SecureSocket: add code to trace SSL events.
Under a #define TRACE_SSL, should you need it. Also load error strings when initializing the SSL context, so we get human readable errors from SSL (also in the ser reported ones).
This commit is contained in:
@@ -179,11 +179,58 @@ BSecureSocket::Private::VerifyCallback(int ok, X509_STORE_CTX* ctx)
|
||||
}
|
||||
|
||||
|
||||
#if TRACE_SSL
|
||||
static void apps_ssl_info_callback(const SSL *s, int where, int ret)
|
||||
{
|
||||
const char *str;
|
||||
int w;
|
||||
|
||||
w=where& ~SSL_ST_MASK;
|
||||
|
||||
if (w & SSL_ST_CONNECT) str="SSL_connect";
|
||||
else if (w & SSL_ST_ACCEPT) str="SSL_accept";
|
||||
else str="undefined";
|
||||
|
||||
if (where & SSL_CB_LOOP)
|
||||
{
|
||||
fprintf(stderr,"%s:%s\n",str,SSL_state_string_long(s));
|
||||
}
|
||||
else if (where & SSL_CB_ALERT)
|
||||
{
|
||||
str=(where & SSL_CB_READ)?"read":"write";
|
||||
fprintf(stderr,"SSL3 alert %s:%s:%s\n",
|
||||
str,
|
||||
SSL_alert_type_string_long(ret),
|
||||
SSL_alert_desc_string_long(ret));
|
||||
}
|
||||
else if (where & SSL_CB_EXIT)
|
||||
{
|
||||
if (ret == 0)
|
||||
fprintf(stderr,"%s:failed in %s\n",
|
||||
str,SSL_state_string_long(s));
|
||||
else if (ret < 0)
|
||||
{
|
||||
fprintf(stderr,"%s:error in %s\n",
|
||||
str,SSL_state_string_long(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* static */ void
|
||||
BSecureSocket::Private::_CreateContext()
|
||||
{
|
||||
// We want SSL to report errors in human readable format.
|
||||
SSL_load_error_strings();
|
||||
|
||||
sContext = SSL_CTX_new(SSLv23_method());
|
||||
|
||||
#if TRACE_SSL
|
||||
// For debugging purposes: get all SSL messages to the standard error.
|
||||
SSL_CTX_set_info_callback(sContext, apps_ssl_info_callback);
|
||||
#endif
|
||||
|
||||
// Disable legacy protocols. They have known vulnerabilities.
|
||||
SSL_CTX_set_options(sContext, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user