[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [tor/master] Log OpenSSL errors coming from bufferevent_openssl



Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon, 11 Oct 2010 13:25:41 -0400
Subject: Log OpenSSL errors coming from bufferevent_openssl
Commit: 4cfa6fbaca443ddb037147f71386d9d3a407c15b

---
 src/common/tortls.c    |   54 ++++++++++++++++++++++++++++-------------------
 src/or/connection_or.c |    8 +++++++
 2 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/src/common/tortls.c b/src/common/tortls.c
index 7568a6b..fc671c7 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -224,36 +224,46 @@ ssl_state_to_string(int ssl_state)
   return buf;
 }
 
+void
+tor_tls_log_one_error(tor_tls_t *tls, unsigned long err,
+                  int severity, int domain, const char *doing)
+{
+  const char *state = NULL, *addr;
+  const char *msg, *lib, *func;
+  int st;
+
+  st = (tls && tls->ssl) ? tls->ssl->state : -1;
+  state = (st>=0)?ssl_state_to_string(st):"---";
+
+  addr = tls ? tls->address : NULL;
+
+  msg = (const char*)ERR_reason_error_string(err);
+  lib = (const char*)ERR_lib_error_string(err);
+  func = (const char*)ERR_func_error_string(err);
+  if (!msg) msg = "(null)";
+  if (!lib) lib = "(null)";
+  if (!func) func = "(null)";
+  if (doing) {
+    log(severity, domain, "TLS error while %s%s%s: %s (in %s:%s:%s)",
+        doing, addr?" with ":"", addr?addr:"",
+        msg, lib, func, state);
+  } else {
+    log(severity, domain, "TLS error%s%s: %s (in %s:%s:%s)",
+        addr?" with ":"", addr?addr:"",
+        msg, lib, func, state);
+  }
+}
+
 /** Log all pending tls errors at level <b>severity</b>.  Use
  * <b>doing</b> to describe our current activities.
  */
 static void
 tls_log_errors(tor_tls_t *tls, int severity, int domain, const char *doing)
 {
-  const char *state = NULL;
-  int st;
   unsigned long err;
-  const char *msg, *lib, *func, *addr;
-  addr = tls ? tls->address : NULL;
-  st = (tls && tls->ssl) ? tls->ssl->state : -1;
+
   while ((err = ERR_get_error()) != 0) {
-    msg = (const char*)ERR_reason_error_string(err);
-    lib = (const char*)ERR_lib_error_string(err);
-    func = (const char*)ERR_func_error_string(err);
-    if (!state)
-      state = (st>=0)?ssl_state_to_string(st):"---";
-    if (!msg) msg = "(null)";
-    if (!lib) lib = "(null)";
-    if (!func) func = "(null)";
-    if (doing) {
-      log(severity, domain, "TLS error while %s%s%s: %s (in %s:%s:%s)",
-          doing, addr?" with ":"", addr?addr:"",
-          msg, lib, func, state);
-    } else {
-      log(severity, domain, "TLS error%s%s: %s (in %s:%s:%s)",
-          addr?" with ":"", addr?addr:"",
-          msg, lib, func, state);
-    }
+    tor_tls_log_one_error(tls, err, severity, domain, doing);
   }
 }
 
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 069c3e1..9bd5b9b 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -1050,6 +1050,14 @@ connection_or_handle_event_cb(struct bufferevent *bufev, short event,
     return;
   }
 
+  if (event & BEV_EVENT_ERROR) {
+    unsigned long err;
+    while ((err = bufferevent_get_openssl_error(bufev))) {
+      tor_tls_log_one_error(conn->tls, err, LOG_WARN, LD_OR,
+                            "handshaking (with bufferevent)");
+    }
+  }
+
   connection_handle_event_cb(bufev, event, arg);
 }
 #endif
-- 
1.7.1