summaryrefslogtreecommitdiffstats
path: root/base/openssl_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/openssl_util.cc')
-rw-r--r--base/openssl_util.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/base/openssl_util.cc b/base/openssl_util.cc
index 5cfc34a..8d47609 100644
--- a/base/openssl_util.cc
+++ b/base/openssl_util.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/scoped_vector.h"
#include "base/singleton.h"
+#include "base/string_piece.h"
namespace base {
@@ -74,6 +75,20 @@ class OpenSSLInitSingleton {
DISALLOW_COPY_AND_ASSIGN(OpenSSLInitSingleton);
};
+// Callback routine for OpenSSL to print error messages. |str| is a
+// NULL-terminated string of length |len| containing diagnostic information
+// such as the library, function and reason for the error, the file and line
+// where the error originated, plus potentially any context-specific
+// information about the error. |context| contains a pointer to user-supplied
+// data, which is currently unused.
+// If this callback returns a value <= 0, OpenSSL will stop processing the
+// error queue and return, otherwise it will continue calling this function
+// until all errors have been removed from the queue.
+int OpenSSLErrorCallback(const char* str, size_t len, void* context) {
+ DVLOG(1) << "\t" << StringPiece(str, len);
+ return 1;
+}
+
} // namespace
void EnsureOpenSSLInit() {
@@ -82,19 +97,14 @@ void EnsureOpenSSLInit() {
void ClearOpenSSLERRStack(const tracked_objects::Location& location) {
if (logging::DEBUG_MODE && VLOG_IS_ON(1)) {
- int error_num = ERR_get_error();
+ int error_num = ERR_peek_error();
if (error_num == 0)
return;
std::string message;
location.Write(true, true, &message);
DVLOG(1) << "OpenSSL ERR_get_error stack from " << message;
- char buf[140];
- do {
- ERR_error_string_n(error_num, buf, arraysize(buf));
- DVLOG(1) << "\t" << error_num << ": " << buf;
- error_num = ERR_get_error();
- } while (error_num != 0);
+ ERR_print_errors_cb(&OpenSSLErrorCallback, NULL);
} else {
ERR_clear_error();
}