Log OpenSSL errors coming from bufferevent_openssl

This commit is contained in:
Nick Mathewson 2010-10-11 13:25:41 -04:00
parent 50d77ad4b6
commit 4cfa6fbaca
2 changed files with 40 additions and 22 deletions

View File

@ -224,24 +224,22 @@ ssl_state_to_string(int ssl_state)
return buf; return buf;
} }
/** Log all pending tls errors at level <b>severity</b>. Use void
* <b>doing</b> to describe our current activities. tor_tls_log_one_error(tor_tls_t *tls, unsigned long err,
*/ int severity, int domain, const char *doing)
static void
tls_log_errors(tor_tls_t *tls, int severity, int domain, const char *doing)
{ {
const char *state = NULL; const char *state = NULL, *addr;
const char *msg, *lib, *func;
int st; int st;
unsigned long err;
const char *msg, *lib, *func, *addr;
addr = tls ? tls->address : NULL;
st = (tls && tls->ssl) ? tls->ssl->state : -1; st = (tls && tls->ssl) ? tls->ssl->state : -1;
while ((err = ERR_get_error()) != 0) { state = (st>=0)?ssl_state_to_string(st):"---";
addr = tls ? tls->address : NULL;
msg = (const char*)ERR_reason_error_string(err); msg = (const char*)ERR_reason_error_string(err);
lib = (const char*)ERR_lib_error_string(err); lib = (const char*)ERR_lib_error_string(err);
func = (const char*)ERR_func_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 (!msg) msg = "(null)";
if (!lib) lib = "(null)"; if (!lib) lib = "(null)";
if (!func) func = "(null)"; if (!func) func = "(null)";
@ -254,6 +252,18 @@ tls_log_errors(tor_tls_t *tls, int severity, int domain, const char *doing)
addr?" with ":"", addr?addr:"", addr?" with ":"", addr?addr:"",
msg, lib, func, state); 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)
{
unsigned long err;
while ((err = ERR_get_error()) != 0) {
tor_tls_log_one_error(tls, err, severity, domain, doing);
} }
} }

View File

@ -1050,6 +1050,14 @@ connection_or_handle_event_cb(struct bufferevent *bufev, short event,
return; 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); connection_handle_event_cb(bufev, event, arg);
} }
#endif #endif