From: Kevin McCarthy Date: Mon, 11 Apr 2016 18:55:50 +0000 (-0700) Subject: Add an error message and debugging if SSL_CTX_new() fails. (closes #3831) X-Git-Tag: neomutt-20160822~176 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1a3de4392a640ed539332a8dcf5d724dc3e2354;p=neomutt Add an error message and debugging if SSL_CTX_new() fails. (closes #3831) Generate a mutt_error(). Add a debugging function ssl_dprint_err_stack() to dprint the ssl error stack. --- diff --git a/mutt_ssl.c b/mutt_ssl.c index da5efa8ba..30da838e9 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -82,6 +82,7 @@ static int ssl_socket_open (CONNECTION * conn); static int ssl_socket_close (CONNECTION * conn); static int tls_close (CONNECTION* conn); static void ssl_err (sslsockdata *data, int err); +static void ssl_dprint_err_stack (void); static int ssl_cache_trusted_cert (X509 *cert); static int ssl_check_certificate (CONNECTION *conn, sslsockdata * data); static int interactive_check_cert (X509 *cert, int idx, int len); @@ -336,6 +337,12 @@ static int ssl_socket_open (CONNECTION * conn) if (! (data->ctx = SSL_CTX_new (SSLv23_client_method ()))) { + /* L10N: an SSL context is a data structure returned by the OpenSSL + * function SSL_CTX_new(). In this case it returned NULL: an + * error condition. + */ + mutt_error (_("Unable to create SSL context")); + ssl_dprint_err_stack (); mutt_socket_close (conn); return -1; } @@ -537,6 +544,22 @@ static void ssl_err (sslsockdata *data, int err) dprint (1, (debugfile, "SSL error: %s\n", errmsg)); } +static void ssl_dprint_err_stack (void) +{ +#ifdef DEBUG + BIO *bio; + char *buf = NULL; + + if (! (bio = BIO_new (BIO_s_mem ()))) + return; + ERR_print_errors (bio); + if (BIO_get_mem_data (bio, &buf)) + dprint (1, (debugfile, "SSL error stack: %s\n", buf)); + BIO_free (bio); +#endif +} + + static char *x509_get_part (char *line, const char *ndx) { static char ret[SHORT_STRING];