Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: crypto/openssl_util.cc

Issue 6865011: Fix openssl build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/socket/ssl_server_socket_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "crypto/openssl_util.h" 5 #include "crypto/openssl_util.h"
6 6
7 #include <openssl/err.h> 7 #include <openssl/err.h>
8 #include <openssl/ssl.h> 8 #include <openssl/ssl.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 16 matching lines...) Expand all
27 static OpenSSLInitSingleton* GetInstance() { 27 static OpenSSLInitSingleton* GetInstance() {
28 // We allow the SSL environment to leak for multiple reasons: 28 // We allow the SSL environment to leak for multiple reasons:
29 // - it is used from a non-joinable worker thread that is not stopped on 29 // - it is used from a non-joinable worker thread that is not stopped on
30 // shutdown, hence may still be using OpenSSL library after the AtExit 30 // shutdown, hence may still be using OpenSSL library after the AtExit
31 // runner has completed. 31 // runner has completed.
32 // - There are other OpenSSL related singletons (e.g. the client socket 32 // - There are other OpenSSL related singletons (e.g. the client socket
33 // context) who's cleanup depends on the global environment here, but 33 // context) who's cleanup depends on the global environment here, but
34 // we can't control the order the AtExit handlers will run in so 34 // we can't control the order the AtExit handlers will run in so
35 // allowing the global environment to leak at least ensures it is 35 // allowing the global environment to leak at least ensures it is
36 // available for those other singletons to reliably cleanup. 36 // available for those other singletons to reliably cleanup.
37 return base::Singleton<OpenSSLInitSingleton, 37 return Singleton<OpenSSLInitSingleton,
38 base::LeakySingletonTraits<OpenSSLInitSingleton> >::get(); 38 LeakySingletonTraits<OpenSSLInitSingleton> >::get();
39 } 39 }
40 private: 40 private:
41 friend struct DefaultSingletonTraits<OpenSSLInitSingleton>; 41 friend struct DefaultSingletonTraits<OpenSSLInitSingleton>;
42 OpenSSLInitSingleton() { 42 OpenSSLInitSingleton() {
43 SSL_load_error_strings(); 43 SSL_load_error_strings();
44 SSL_library_init(); 44 SSL_library_init();
45 OpenSSL_add_all_algorithms(); 45 OpenSSL_add_all_algorithms();
46 int num_locks = CRYPTO_num_locks(); 46 int num_locks = CRYPTO_num_locks();
47 locks_.reserve(num_locks); 47 locks_.reserve(num_locks);
48 for (int i = 0; i < num_locks; ++i) 48 for (int i = 0; i < num_locks; ++i)
(...skipping 29 matching lines...) Expand all
78 // Callback routine for OpenSSL to print error messages. |str| is a 78 // Callback routine for OpenSSL to print error messages. |str| is a
79 // NULL-terminated string of length |len| containing diagnostic information 79 // NULL-terminated string of length |len| containing diagnostic information
80 // such as the library, function and reason for the error, the file and line 80 // such as the library, function and reason for the error, the file and line
81 // where the error originated, plus potentially any context-specific 81 // where the error originated, plus potentially any context-specific
82 // information about the error. |context| contains a pointer to user-supplied 82 // information about the error. |context| contains a pointer to user-supplied
83 // data, which is currently unused. 83 // data, which is currently unused.
84 // If this callback returns a value <= 0, OpenSSL will stop processing the 84 // If this callback returns a value <= 0, OpenSSL will stop processing the
85 // error queue and return, otherwise it will continue calling this function 85 // error queue and return, otherwise it will continue calling this function
86 // until all errors have been removed from the queue. 86 // until all errors have been removed from the queue.
87 int OpenSSLErrorCallback(const char* str, size_t len, void* context) { 87 int OpenSSLErrorCallback(const char* str, size_t len, void* context) {
88 DVLOG(1) << "\t" << StringPiece(str, len); 88 DVLOG(1) << "\t" << base::StringPiece(str, len);
89 return 1; 89 return 1;
90 } 90 }
91 91
92 } // namespace 92 } // namespace
93 93
94 void EnsureOpenSSLInit() { 94 void EnsureOpenSSLInit() {
95 (void)OpenSSLInitSingleton::GetInstance(); 95 (void)OpenSSLInitSingleton::GetInstance();
96 } 96 }
97 97
98 void ClearOpenSSLERRStack(const tracked_objects::Location& location) { 98 void ClearOpenSSLERRStack(const tracked_objects::Location& location) {
99 if (logging::DEBUG_MODE && VLOG_IS_ON(1)) { 99 if (logging::DEBUG_MODE && VLOG_IS_ON(1)) {
100 int error_num = ERR_peek_error(); 100 int error_num = ERR_peek_error();
101 if (error_num == 0) 101 if (error_num == 0)
102 return; 102 return;
103 103
104 std::string message; 104 std::string message;
105 location.Write(true, true, &message); 105 location.Write(true, true, &message);
106 DVLOG(1) << "OpenSSL ERR_get_error stack from " << message; 106 DVLOG(1) << "OpenSSL ERR_get_error stack from " << message;
107 ERR_print_errors_cb(&OpenSSLErrorCallback, NULL); 107 ERR_print_errors_cb(&OpenSSLErrorCallback, NULL);
108 } else { 108 } else {
109 ERR_clear_error(); 109 ERR_clear_error();
110 } 110 }
111 } 111 }
112 112
113 } // namespace crypto 113 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | net/socket/ssl_server_socket_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698