[glib-networking] Fail unsafe rehandshake attempts initiated by API request
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking] Fail unsafe rehandshake attempts initiated by API request
- Date: Fri, 27 Jul 2018 15:33:20 +0000 (UTC)
commit 21f765e24c9a9f7da6860ce6b4affc74a46648ee
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Fri Jul 27 10:27:53 2018 -0500
Fail unsafe rehandshake attempts initiated by API request
If the application attempts a rehandshake, that will currently be
allowed even if the server does not support safe renegotiation, and even
if the application has not enabled unsafe rehandshake mode. Since
applications have no way using our API to check if safe renegotiation is
supported, we had best check for them.
tls/gnutls/gtlsconnection-gnutls.c | 58 ++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 25 deletions(-)
---
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index c246f90..806e467 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -1789,7 +1789,6 @@ handshake_thread (GTask *task,
{
GTlsConnectionGnutls *gnutls = object;
GTlsConnectionGnutlsPrivate *priv = g_tls_connection_gnutls_get_instance_private (gnutls);
- gboolean is_client;
GError *error = NULL;
int ret;
gint64 start_time;
@@ -1811,37 +1810,46 @@ handshake_thread (GTask *task,
g_clear_error (&priv->handshake_error);
- is_client = G_IS_TLS_CLIENT_CONNECTION (gnutls);
-
- if (!is_client && priv->ever_handshaked && !priv->implicit_handshake)
+ if (priv->ever_handshaked && !priv->implicit_handshake)
{
- /* Adjust the timeout for the next operation in the sequence. */
- if (timeout > 0)
+ if (priv->rehandshake_mode != G_TLS_REHANDSHAKE_UNSAFELY &&
+ !gnutls_safe_renegotiation_status (priv->session))
{
- unsigned int timeout_ms;
+ g_task_return_new_error (task, G_TLS_ERROR, G_TLS_ERROR_MISC,
+ _("Peer does not support safe renegotiation"));
+ return;
+ }
- timeout -= (g_get_monotonic_time () - start_time);
- if (timeout <= 0)
- timeout = 1;
+ if (!G_IS_TLS_CLIENT_CONNECTION (gnutls))
+ {
+ /* Adjust the timeout for the next operation in the sequence. */
+ if (timeout > 0)
+ {
+ unsigned int timeout_ms;
- /* Convert from microseconds to milliseconds, but ensure the timeout
- * remains positive. */
- timeout_ms = (timeout + 999) / 1000;
+ timeout -= (g_get_monotonic_time () - start_time);
+ if (timeout <= 0)
+ timeout = 1;
- gnutls_handshake_set_timeout (priv->session, timeout_ms);
- gnutls_dtls_set_timeouts (priv->session, 1000 /* default */,
- timeout_ms);
- }
+ /* Convert from microseconds to milliseconds, but ensure the timeout
+ * remains positive. */
+ timeout_ms = (timeout + 999) / 1000;
- BEGIN_GNUTLS_IO (gnutls, G_IO_IN | G_IO_OUT, timeout, cancellable);
- ret = gnutls_rehandshake (priv->session);
- END_GNUTLS_IO (gnutls, G_IO_IN | G_IO_OUT, ret,
- _("Error performing TLS handshake"), &error);
+ gnutls_handshake_set_timeout (priv->session, timeout_ms);
+ gnutls_dtls_set_timeouts (priv->session, 1000 /* default */,
+ timeout_ms);
+ }
- if (error)
- {
- g_task_return_error (task, error);
- return;
+ BEGIN_GNUTLS_IO (gnutls, G_IO_IN | G_IO_OUT, timeout, cancellable);
+ ret = gnutls_rehandshake (priv->session);
+ END_GNUTLS_IO (gnutls, G_IO_IN | G_IO_OUT, ret,
+ _("Error performing TLS handshake"), &error);
+
+ if (error)
+ {
+ g_task_return_error (task, error);
+ return;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]