From 51f030790060ec22577e3bc52ec2d1a645e3591a Mon Sep 17 00:00:00 2001 From: Andreas Frisch Date: Thu, 29 Mar 2018 13:33:10 +0200 Subject: [PATCH] dtls: Properly display all errors/warnings from ERR queue Print out all errors from the OpenSSL error queue instead of just looking at the topmost error. Using the callback interface also removes the need for formatting using a buffer on the stack. --- ext/dtls/gstdtlsagent.c | 14 ++++++++++---- ext/dtls/gstdtlsconnection.c | 27 ++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/ext/dtls/gstdtlsagent.c b/ext/dtls/gstdtlsagent.c index 212c5a0..06dbdc2 100644 --- a/ext/dtls/gstdtlsagent.c +++ b/ext/dtls/gstdtlsagent.c @@ -164,6 +164,14 @@ gst_dtls_agent_class_init (GstDtlsAgentClass * klass) _gst_dtls_init_openssl (); } +static int +ssl_warn_cb (const char *str, size_t len, void *u) +{ + GstDtlsAgent *self = u; + GST_WARNING_OBJECT (self, "ssl error: %s", str); + return 0; +} + static void gst_dtls_agent_init (GstDtlsAgent * self) { @@ -178,12 +186,10 @@ gst_dtls_agent_init (GstDtlsAgent * self) priv->ssl_context = SSL_CTX_new (DTLSv1_method ()); #endif if (ERR_peek_error () || !priv->ssl_context) { - char buf[512]; - priv->ssl_context = NULL; - GST_WARNING_OBJECT (self, "Error creating SSL Context: %s", - ERR_error_string (ERR_get_error (), buf)); + GST_WARNING_OBJECT (self, "Error creating SSL Context"); + ERR_print_errors_cb (ssl_warn_cb, self); g_return_if_reached (); } diff --git a/ext/dtls/gstdtlsconnection.c b/ext/dtls/gstdtlsconnection.c index a6db163..7e48ddd 100644 --- a/ext/dtls/gstdtlsconnection.c +++ b/ext/dtls/gstdtlsconnection.c @@ -707,11 +707,26 @@ beach: self->priv->keys_exported = TRUE; } +static int +ssl_warn_cb (const char *str, size_t len, void *u) +{ + GstDtlsConnection *self = u; + GST_WARNING_OBJECT (self, "ssl error: %s", str); + return 0; +} + +static int +ssl_err_cb (const char *str, size_t len, void *u) +{ + GstDtlsConnection *self = u; + GST_ERROR_OBJECT (self, "ssl error: %s", str); + return 0; +} + static void openssl_poll (GstDtlsConnection * self) { int ret; - char buf[512]; int error; log_state (self, "poll: before handshake"); @@ -748,9 +763,9 @@ openssl_poll (GstDtlsConnection * self) GST_WARNING_OBJECT (self, "no error, handshake should be done"); break; case SSL_ERROR_SSL: - GST_LOG_OBJECT (self, "SSL error %d: %s", error, - ERR_error_string (ERR_get_error (), buf)); - break; + GST_ERROR_OBJECT (self, "SSL error"); + ERR_print_errors_cb (ssl_err_cb, self); + return; case SSL_ERROR_WANT_READ: GST_LOG_OBJECT (self, "SSL wants read"); break; @@ -758,12 +773,14 @@ openssl_poll (GstDtlsConnection * self) GST_LOG_OBJECT (self, "SSL wants write"); break; case SSL_ERROR_SYSCALL:{ - GST_LOG_OBJECT (self, "SSL syscall (error) : %lu", ERR_get_error ()); + GST_LOG_OBJECT (self, "SSL syscall error"); break; } default: GST_WARNING_OBJECT (self, "Unknown SSL error: %d, ret: %d", error, ret); } + + ERR_print_errors_cb (ssl_warn_cb, self); } static int -- 2.7.4