]> source.dussan.org Git - tigervnc.git/commitdiff
Fix reporting of some TLS errors
authorPierre Ossman <ossman@cendio.se>
Tue, 3 Sep 2024 06:07:11 +0000 (08:07 +0200)
committerPierre Ossman <ossman@cendio.se>
Wed, 4 Sep 2024 09:29:18 +0000 (11:29 +0200)
These functions return a GnuTLS status, so we should use the correct
exception for that so we get the proper error messages.

common/rfb/CSecurityTLS.cxx
common/rfb/SSecurityTLS.cxx

index eff215ab003c11e8748e7a0752ed7bf431b85d1c..6eeb6a84d3c65af9dad861cf25a3c4d5b35679ec 100644 (file)
@@ -333,11 +333,12 @@ void CSecurityTLS::checkSession()
     if (fatal_status != 0) {
       std::string error;
 
-      if (gnutls_certificate_verification_status_print(fatal_status,
-                                                       GNUTLS_CRT_X509,
-                                                       &status_str,
-                                                       0) < 0)
-        throw Exception("Failed to get certificate error description");
+      err = gnutls_certificate_verification_status_print(fatal_status,
+                                                         GNUTLS_CRT_X509,
+                                                         &status_str,
+                                                         0);
+      if (err != GNUTLS_E_SUCCESS)
+        throw rdr::TLSException("Failed to get certificate error description", err);
 
       error = (const char*)status_str.data;
 
@@ -346,11 +347,12 @@ void CSecurityTLS::checkSession()
       throw Exception("Invalid server certificate: %s", error.c_str());
     }
 
-    if (gnutls_certificate_verification_status_print(status,
-                                                     GNUTLS_CRT_X509,
-                                                     &status_str,
-                                                     0) < 0)
-      throw Exception("Failed to get certificate error description");
+    err = gnutls_certificate_verification_status_print(status,
+                                                       GNUTLS_CRT_X509,
+                                                       &status_str,
+                                                       0);
+    if (err != GNUTLS_E_SUCCESS)
+      throw rdr::TLSException("Failed to get certificate error description", err);
 
     vlog.info("Server certificate errors: %s", status_str.data);
 
@@ -367,8 +369,9 @@ void CSecurityTLS::checkSession()
   gnutls_x509_crt_t crt;
   gnutls_x509_crt_init(&crt);
 
-  if (gnutls_x509_crt_import(crt, &cert_list[0], GNUTLS_X509_FMT_DER) < 0)
-    throw Exception("decoding of certificate failed");
+  err = gnutls_x509_crt_import(crt, &cert_list[0], GNUTLS_X509_FMT_DER);
+  if (err != GNUTLS_E_SUCCESS)
+    throw rdr::TLSException("Failed to decode server certificate", err);
 
   if (gnutls_x509_crt_check_hostname(crt, client->getServerName()) == 0) {
     vlog.info("Server certificate doesn't match given server name");
index 67dced6c0d6f91b57936d5a1576473653d59c892..465126eb7e694bca825700373a2634068b6dadf8 100644 (file)
@@ -299,16 +299,11 @@ void SSecurityTLS::setParams()
     gnutls_certificate_set_dh_params(cert_cred, dh_params);
 #endif
 
-    switch (gnutls_certificate_set_x509_key_file(cert_cred, X509_CertFile, X509_KeyFile, GNUTLS_X509_FMT_PEM)) {
-    case GNUTLS_E_SUCCESS:
-      break;
-    case GNUTLS_E_CERTIFICATE_KEY_MISMATCH:
-      throw Exception("Private key does not match certificate");
-    case GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE:
-      throw Exception("Unsupported certificate type");
-    default:
-      throw Exception("Error loading X509 certificate or key");
-    }
+    ret = gnutls_certificate_set_x509_key_file(cert_cred, X509_CertFile,
+                                               X509_KeyFile,
+                                               GNUTLS_X509_FMT_PEM);
+    if (ret != GNUTLS_E_SUCCESS)
+      throw rdr::TLSException("Failed to load certificate and key", ret);
 
     ret = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, cert_cred);
     if (ret != GNUTLS_E_SUCCESS)