Blame SOURCES/tigervnc-utilize-system-crypto-policies.patch

809922
diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx
809922
index 9900837..59d2086 100644
809922
--- a/common/rfb/CSecurityTLS.cxx
809922
+++ b/common/rfb/CSecurityTLS.cxx
809922
@@ -210,26 +210,66 @@ void CSecurityTLS::setParam()
809922
   static const char kx_anon_priority[] = ":+ANON-ECDH:+ANON-DH";
809922
 
809922
   int ret;
809922
-  char *prio;
809922
-  const char *err;
809922
 
809922
-  prio = (char*)malloc(strlen(Security::GnuTLSPriority) +
809922
-                       strlen(kx_anon_priority) + 1);
809922
-  if (prio == NULL)
809922
-    throw AuthFailureException("Not enough memory for GnuTLS priority string");
809922
+  // Custom priority string specified?
809922
+  if (strcmp(Security::GnuTLSPriority, "") != 0) {
809922
+    char *prio;
809922
+    const char *err;
809922
 
809922
-  strcpy(prio, Security::GnuTLSPriority);
809922
-  if (anon)
809922
+    prio = (char*)malloc(strlen(Security::GnuTLSPriority) +
809922
+                         strlen(kx_anon_priority) + 1);
809922
+    if (prio == NULL)
809922
+      throw AuthFailureException("Not enough memory for GnuTLS priority string");
809922
+
809922
+    strcpy(prio, Security::GnuTLSPriority);
809922
+    if (anon)
809922
+      strcat(prio, kx_anon_priority);
809922
+
809922
+    ret = gnutls_priority_set_direct(session, prio, &err;;
809922
+
809922
+    free(prio);
809922
+
809922
+    if (ret != GNUTLS_E_SUCCESS) {
809922
+      if (ret == GNUTLS_E_INVALID_REQUEST)
809922
+        vlog.error("GnuTLS priority syntax error at: %s", err);
809922
+      throw AuthFailureException("gnutls_set_priority_direct failed");
809922
+    }
809922
+  } else if (anon) {
809922
+    const char *err;
809922
+
809922
+#if GNUTLS_VERSION_NUMBER >= 0x030603
809922
+    // gnutls_set_default_priority_appends() expects a normal priority string that
809922
+    // doesn't start with ":".
809922
+    ret = gnutls_set_default_priority_append(session, kx_anon_priority + 1, &err, 0);
809922
+    if (ret != GNUTLS_E_SUCCESS) {
809922
+      if (ret == GNUTLS_E_INVALID_REQUEST)
809922
+        vlog.error("GnuTLS priority syntax error at: %s", err);
809922
+      throw AuthFailureException("gnutls_set_default_priority_append failed");
809922
+    }
809922
+#else
809922
+    // We don't know what the system default priority is, so we guess
809922
+    // it's what upstream GnuTLS has
809922
+    static const char gnutls_default_priority[] = "NORMAL";
809922
+    char *prio;
809922
+
809922
+    prio = (char*)malloc(strlen(gnutls_default_priority) +
809922
+                         strlen(kx_anon_priority) + 1);
809922
+    if (prio == NULL)
809922
+      throw AuthFailureException("Not enough memory for GnuTLS priority string");
809922
+
809922
+    strcpy(prio, gnutls_default_priority);
809922
     strcat(prio, kx_anon_priority);
809922
 
809922
-  ret = gnutls_priority_set_direct(session, prio, &err;;
809922
+    ret = gnutls_priority_set_direct(session, prio, &err;;
809922
 
809922
-  free(prio);
809922
+    free(prio);
809922
 
809922
-  if (ret != GNUTLS_E_SUCCESS) {
809922
-    if (ret == GNUTLS_E_INVALID_REQUEST)
809922
-      vlog.error("GnuTLS priority syntax error at: %s", err);
809922
-    throw AuthFailureException("gnutls_set_priority_direct failed");
809922
+    if (ret != GNUTLS_E_SUCCESS) {
809922
+      if (ret == GNUTLS_E_INVALID_REQUEST)
809922
+        vlog.error("GnuTLS priority syntax error at: %s", err);
809922
+      throw AuthFailureException("gnutls_set_priority_direct failed");
809922
+    }
809922
+#endif
809922
   }
809922
 
809922
   if (anon) {
809922
diff --git a/common/rfb/SSecurityTLS.cxx b/common/rfb/SSecurityTLS.cxx
809922
index ef5d8c9..f32f87f 100644
809922
--- a/common/rfb/SSecurityTLS.cxx
809922
+++ b/common/rfb/SSecurityTLS.cxx
809922
@@ -198,26 +198,66 @@ void SSecurityTLS::setParams(gnutls_session_t session)
809922
   static const char kx_anon_priority[] = ":+ANON-ECDH:+ANON-DH";
809922
 
809922
   int ret;
809922
-  char *prio;
809922
-  const char *err;
809922
 
809922
-  prio = (char*)malloc(strlen(Security::GnuTLSPriority) +
809922
-                       strlen(kx_anon_priority) + 1);
809922
-  if (prio == NULL)
809922
-    throw AuthFailureException("Not enough memory for GnuTLS priority string");
809922
+  // Custom priority string specified?
809922
+  if (strcmp(Security::GnuTLSPriority, "") != 0) {
809922
+    char *prio;
809922
+    const char *err;
809922
 
809922
-  strcpy(prio, Security::GnuTLSPriority);
809922
-  if (anon)
809922
+    prio = (char*)malloc(strlen(Security::GnuTLSPriority) +
809922
+                         strlen(kx_anon_priority) + 1);
809922
+    if (prio == NULL)
809922
+      throw AuthFailureException("Not enough memory for GnuTLS priority string");
809922
+
809922
+    strcpy(prio, Security::GnuTLSPriority);
809922
+    if (anon)
809922
+      strcat(prio, kx_anon_priority);
809922
+
809922
+    ret = gnutls_priority_set_direct(session, prio, &err;;
809922
+
809922
+    free(prio);
809922
+
809922
+    if (ret != GNUTLS_E_SUCCESS) {
809922
+      if (ret == GNUTLS_E_INVALID_REQUEST)
809922
+        vlog.error("GnuTLS priority syntax error at: %s", err);
809922
+      throw AuthFailureException("gnutls_set_priority_direct failed");
809922
+    }
809922
+  } else if (anon) {
809922
+    const char *err;
809922
+
809922
+#if GNUTLS_VERSION_NUMBER >= 0x030603
809922
+    // gnutls_set_default_priority_appends() expects a normal priority string that
809922
+    // doesn't start with ":".
809922
+    ret = gnutls_set_default_priority_append(session, kx_anon_priority + 1, &err, 0);
809922
+    if (ret != GNUTLS_E_SUCCESS) {
809922
+      if (ret == GNUTLS_E_INVALID_REQUEST)
809922
+        vlog.error("GnuTLS priority syntax error at: %s", err);
809922
+      throw AuthFailureException("gnutls_set_default_priority_append failed");
809922
+    }
809922
+#else
809922
+    // We don't know what the system default priority is, so we guess
809922
+    // it's what upstream GnuTLS has
809922
+    static const char gnutls_default_priority[] = "NORMAL";
809922
+    char *prio;
809922
+
809922
+    prio = (char*)malloc(strlen(gnutls_default_priority) +
809922
+                         strlen(kx_anon_priority) + 1);
809922
+    if (prio == NULL)
809922
+      throw AuthFailureException("Not enough memory for GnuTLS priority string");
809922
+
809922
+    strcpy(prio, gnutls_default_priority);
809922
     strcat(prio, kx_anon_priority);
809922
 
809922
-  ret = gnutls_priority_set_direct(session, prio, &err;;
809922
+    ret = gnutls_priority_set_direct(session, prio, &err;;
809922
 
809922
-  free(prio);
809922
+    free(prio);
809922
 
809922
-  if (ret != GNUTLS_E_SUCCESS) {
809922
-    if (ret == GNUTLS_E_INVALID_REQUEST)
809922
-      vlog.error("GnuTLS priority syntax error at: %s", err);
809922
-    throw AuthFailureException("gnutls_set_priority_direct failed");
809922
+    if (ret != GNUTLS_E_SUCCESS) {
809922
+      if (ret == GNUTLS_E_INVALID_REQUEST)
809922
+        vlog.error("GnuTLS priority syntax error at: %s", err);
809922
+      throw AuthFailureException("gnutls_set_priority_direct failed");
809922
+    }
809922
+#endif
809922
   }
809922
 
809922
 #if defined (SSECURITYTLS__USE_DEPRECATED_DH)
acbd46
diff --git a/common/rfb/Security.cxx b/common/rfb/Security.cxx
809922
index 0666041..59deb78 100644
acbd46
--- a/common/rfb/Security.cxx
acbd46
+++ b/common/rfb/Security.cxx
acbd46
@@ -52,7 +52,7 @@ static LogWriter vlog("Security");
acbd46
 #ifdef HAVE_GNUTLS
acbd46
 StringParameter Security::GnuTLSPriority("GnuTLSPriority",
acbd46
   "GnuTLS priority string that controls the TLS session’s handshake algorithms",
acbd46
-  "NORMAL");
809922
+  "");
acbd46
 #endif
809922
 
acbd46
 Security::Security()
809922
diff --git a/unix/xserver/hw/vnc/Xvnc.man b/unix/xserver/hw/vnc/Xvnc.man
809922
index 83621c0..4a0d20c 100644
809922
--- a/unix/xserver/hw/vnc/Xvnc.man
809922
+++ b/unix/xserver/hw/vnc/Xvnc.man
809922
@@ -226,7 +226,9 @@ also be in PEM format.
809922
 .TP
809922
 .B \-GnuTLSPriority \fIpriority\fP
809922
 GnuTLS priority string that controls the TLS session’s handshake algorithms.
809922
-See the GnuTLS manual for possible values. Default is \fBNORMAL\fP.
809922
+See the GnuTLS manual for possible values. For GnuTLS < 3.6.3 the default
809922
+value will be \fBNORMAL\fP to use upstream default. For newer versions
809922
+of GnuTLS system-wide crypto policy will be used.
809922
 .
809922
 .TP
809922
 .B \-UseBlacklist