[glib-networking/mcatanzaro/#135] Return bad identity error if identity is unset



commit f40407eb8d20a940687a014f127c4bb3446d946d
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Mon May 4 17:47:28 2020 -0500

    Return bad identity error if identity is unset
    
    When the server-identity property of GTlsClientConnection is unset, the
    documentation sasy we need to fail the certificate verification with
    G_TLS_CERTIFICATE_BAD_IDENTITY. This is important because otherwise,
    it's easy for applications to fail to specify server identity.
    
    Unfortunately, we did not correctly implement the intended, documented
    behavior. When server identity is missing, we check the validity of the
    TLS certificate, but do not check if it corresponds to the expected
    server (since we have no expected server). Then we assume the identity
    is good, instead of returning bad identity, as documented. This means,
    for example, that evil.com can present a valid certificate issued to
    evil.com, and we would happily accept it for paypal.com.
    
    Fixes #135

 tls/base/gtlsconnection-base.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index f7ad660..7f0e6fe 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -1233,21 +1233,23 @@ static GTlsCertificateFlags
 verify_peer_certificate (GTlsConnectionBase *tls,
                          GTlsCertificate    *peer_certificate)
 {
-  GSocketConnectable *peer_identity;
+  GSocketConnectable *peer_identity = NULL;
   GTlsDatabase *database;
-  GTlsCertificateFlags errors;
+  GTlsCertificateFlags errors = 0;
   gboolean is_client;
 
   is_client = G_IS_TLS_CLIENT_CONNECTION (tls);
 
-  if (!is_client)
-    peer_identity = NULL;
-  else if (!g_tls_connection_base_is_dtls (tls))
-    peer_identity = g_tls_client_connection_get_server_identity (G_TLS_CLIENT_CONNECTION (tls));
-  else
-    peer_identity = g_dtls_client_connection_get_server_identity (G_DTLS_CLIENT_CONNECTION (tls));
+  if (is_client)
+    {
+      if (!g_tls_connection_base_is_dtls (tls))
+        peer_identity = g_tls_client_connection_get_server_identity (G_TLS_CLIENT_CONNECTION (tls));
+      else
+        peer_identity = g_dtls_client_connection_get_server_identity (G_DTLS_CLIENT_CONNECTION (tls));
 
-  errors = 0;
+      if (!peer_identity)
+        errors |= G_TLS_CERTIFICATE_BAD_IDENTITY;
+    }
 
   database = g_tls_connection_get_database (G_TLS_CONNECTION (tls));
   if (!database)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]