<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13812">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">tcptls.c: Log more informative OpenSSL errors<br><br>Dump OpenSSL's error stack to the error log when things fail.<br><br>ASTERISK-28750 #close<br>Reported by: Martin Zeh<br><br>Change-Id: Ib63cd0df20275586e68ac4c2ddad222ed7bd9c0a<br>---<br>M main/tcptls.c<br>1 file changed, 26 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/tcptls.c b/main/tcptls.c</span><br><span>index c2397e7..8a2422f 100644</span><br><span>--- a/main/tcptls.c</span><br><span>+++ b/main/tcptls.c</span><br><span>@@ -134,6 +134,28 @@</span><br><span> </span><br><span> return "Unknown";</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void write_openssl_error_to_log(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ FILE *fp;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *buffer;</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t length;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ fp = open_memstream(&buffer, &length);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!fp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ERR_print_errors_fp(fp);</span><br><span style="color: hsl(120, 100%, 40%);">+ fclose(fp);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (length) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "%.*s\n", (int) length, buffer);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(buffer);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif</span><br><span> </span><br><span> void ast_tcptls_stream_set_timeout_disable(struct ast_tcptls_stream *stream)</span><br><span>@@ -1010,6 +1032,7 @@</span><br><span> if (!client) {</span><br><span> /* Clients don't need a certificate, but if its setup we can use it */</span><br><span> ast_log(LOG_ERROR, "TLS/SSL error loading cert file. <%s>\n", cfg->certfile);</span><br><span style="color: hsl(120, 100%, 40%);">+ write_openssl_error_to_log();</span><br><span> cfg->enabled = 0;</span><br><span> SSL_CTX_free(cfg->ssl_ctx);</span><br><span> cfg->ssl_ctx = NULL;</span><br><span>@@ -1020,6 +1043,7 @@</span><br><span> if (!client) {</span><br><span> /* Clients don't need a private key, but if its setup we can use it */</span><br><span> ast_log(LOG_ERROR, "TLS/SSL error loading private key file. <%s>\n", tmpprivate);</span><br><span style="color: hsl(120, 100%, 40%);">+ write_openssl_error_to_log();</span><br><span> cfg->enabled = 0;</span><br><span> SSL_CTX_free(cfg->ssl_ctx);</span><br><span> cfg->ssl_ctx = NULL;</span><br><span>@@ -1031,6 +1055,7 @@</span><br><span> if (SSL_CTX_set_cipher_list(cfg->ssl_ctx, cfg->cipher) == 0 ) {</span><br><span> if (!client) {</span><br><span> ast_log(LOG_ERROR, "TLS/SSL cipher error <%s>\n", cfg->cipher);</span><br><span style="color: hsl(120, 100%, 40%);">+ write_openssl_error_to_log();</span><br><span> cfg->enabled = 0;</span><br><span> SSL_CTX_free(cfg->ssl_ctx);</span><br><span> cfg->ssl_ctx = NULL;</span><br><span>@@ -1041,6 +1066,7 @@</span><br><span> if (!ast_strlen_zero(cfg->cafile) || !ast_strlen_zero(cfg->capath)) {</span><br><span> if (SSL_CTX_load_verify_locations(cfg->ssl_ctx, S_OR(cfg->cafile, NULL), S_OR(cfg->capath,NULL)) == 0) {</span><br><span> ast_log(LOG_ERROR, "TLS/SSL CA file(%s)/path(%s) error\n", cfg->cafile, cfg->capath);</span><br><span style="color: hsl(120, 100%, 40%);">+ write_openssl_error_to_log();</span><br><span> }</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13812">change 13812</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13812"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Ib63cd0df20275586e68ac4c2ddad222ed7bd9c0a </div>
<div style="display:none"> Gerrit-Change-Number: 13812 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>