diff options
author | Sean Bright <sean.bright@gmail.com> | 2017-03-23 10:45:35 -0400 |
---|---|---|
committer | Sean Bright <sean.bright@gmail.com> | 2017-03-25 12:01:28 -0400 |
commit | 196626556250ae395026f9b235b3e7c0b98a508c (patch) | |
tree | 6cfd1fdefe51d6161ddfb121cd232301127fa35b /res/res_xmpp.c | |
parent | 03b99ae3d29aa9b49e6e1bd538feddb9813d6daf (diff) |
res_xmpp: Try to provide useful errors messages from OpenSSL
If any errors occur during the TLS connection setup, we currently dump a
fairly generic error message. So instead we try to pull in something
useful from OpenSSL to report instead.
ASTERISK-24712
Reported by: Matthias Urlichs
Change-Id: I288500991a9681f447d92913b11fedaf426087f4
Diffstat (limited to 'res/res_xmpp.c')
-rw-r--r-- | res/res_xmpp.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/res/res_xmpp.c b/res/res_xmpp.c index aee2cf5cf..ebf29741a 100644 --- a/res/res_xmpp.c +++ b/res/res_xmpp.c @@ -2623,12 +2623,31 @@ static int xmpp_client_request_tls(struct ast_xmpp_client *client, struct ast_xm #endif } +#ifdef HAVE_OPENSSL +static char *openssl_error_string(void) +{ + char *buf = NULL, *ret; + size_t len; + BIO *bio = BIO_new(BIO_s_mem()); + + ERR_print_errors(bio); + len = BIO_get_mem_data(bio, &buf); + ret = ast_calloc(1, len + 1); + if (ret) { + memcpy(ret, buf, len); + } + BIO_free(bio); + return ret; +} +#endif + /*! \brief Internal function called when we receive a response to our TLS initiation request */ static int xmpp_client_requested_tls(struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) { #ifdef HAVE_OPENSSL int sock; long ssl_opts; + char *err; #endif if (!strcmp(iks_name(node), "success")) { @@ -2684,7 +2703,10 @@ static int xmpp_client_requested_tls(struct ast_xmpp_client *client, struct ast_ return 0; failure: - ast_log(LOG_ERROR, "TLS connection for client '%s' cannot be established. OpenSSL initialization failed.\n", client->name); + err = openssl_error_string(); + ast_log(LOG_ERROR, "TLS connection for client '%s' cannot be established. " + "OpenSSL initialization failed: %s\n", client->name, err); + ast_free(err); return -1; #endif } |