Blame SOURCES/cyrus-imapd-2.3.16-tlsconfig.patch

a9ab2d
New settings:
a9ab2d
a9ab2d
    tls_prefer_server_ciphers: 0
a9ab2d
a9ab2d
        Prefer the cipher order configured on the server-side.
a9ab2d
a9ab2d
    tls_versions: ssl2 ssl3 tls1_0 tls1_1 tls1_2
a9ab2d
a9ab2d
        Disable SSL/TLS protocols not in this list.
a9ab2d
a9ab2d
diff --git a/imap/tls.c b/imap/tls.c
a9ab2d
index b2cf666..5a626e2 100644
a9ab2d
--- a/imap/tls.c
a9ab2d
+++ b/imap/tls.c
a9ab2d
@@ -632,6 +632,7 @@ int     tls_init_serverengine(const char *ident,
a9ab2d
     const char   *s_cert_file;
a9ab2d
     const char   *s_key_file;
a9ab2d
     int    requirecert;
a9ab2d
+    int    server_cipher_order;
a9ab2d
     int    timeout;
a9ab2d
 
a9ab2d
     if (tls_serverengine)
a9ab2d
@@ -663,10 +657,40 @@ int     tls_init_serverengine(const char *ident,
a9ab2d
     };
a9ab2d
 
a9ab2d
     off |= SSL_OP_ALL;		/* Work around all known bugs */
a9ab2d
-    if (tlsonly) {
a9ab2d
-	off |= SSL_OP_NO_SSLv2;
a9ab2d
-	off |= SSL_OP_NO_SSLv3;
a9ab2d
+
a9ab2d
+    const char *tls_versions = config_getstring(IMAPOPT_TLS_VERSIONS);
a9ab2d
+
a9ab2d
+    if (strstr(tls_versions, "ssl2") == NULL || tlsonly) {
a9ab2d
+    off |= SSL_OP_NO_SSLv2;
a9ab2d
+    }
a9ab2d
+
a9ab2d
+    if (strstr(tls_versions, "ssl3") == NULL || tlsonly) {
a9ab2d
+    off |= SSL_OP_NO_SSLv3;
a9ab2d
+    }
a9ab2d
+
a9ab2d
+    if (strstr(tls_versions, "tls1_2") == NULL) {
a9ab2d
+#if (OPENSSL_VERSION_NUMBER >= 0x1000105fL)
a9ab2d
+    off |= SSL_OP_NO_TLSv1_2;
a9ab2d
+#else
a9ab2d
+    syslog(LOG_ERR, "ERROR: TLSv1.2 configured, OpenSSL < 1.0.1e insufficient");
a9ab2d
+#endif
a9ab2d
     }
a9ab2d
+
a9ab2d
+    if (strstr(tls_versions, "tls1_1") == NULL) {
a9ab2d
+#if (OPENSSL_VERSION_NUMBER >= 0x1000000fL)
a9ab2d
+    off |= SSL_OP_NO_TLSv1_1;
a9ab2d
+#else
a9ab2d
+    syslog(LOG_ERR, "ERROR: TLSv1.1 configured, OpenSSL < 1.0.0 insufficient");
a9ab2d
+#endif
a9ab2d
+    }
a9ab2d
+    if (strstr(tls_versions, "tls1_0") == NULL) {
a9ab2d
+    off |= SSL_OP_NO_TLSv1;
a9ab2d
+    }
a9ab2d
+
a9ab2d
+    server_cipher_order = config_getswitch(IMAPOPT_TLS_PREFER_SERVER_CIPHERS);
a9ab2d
+    if (server_cipher_order)
a9ab2d
+        off |= SSL_OP_CIPHER_SERVER_PREFERENCE;
a9ab2d
+
a9ab2d
     SSL_CTX_set_options(s_ctx, off);
a9ab2d
     SSL_CTX_set_info_callback(s_ctx, (void (*)()) apps_ssl_info_callback);
a9ab2d
 
a9ab2d
@@ -1196,7 +1220,7 @@ int tls_init_clientengine(int verifydepth,
a9ab2d
 	return -1;
a9ab2d
     }
a9ab2d
     
a9ab2d
-    c_ctx = SSL_CTX_new(TLSv1_client_method());
a9ab2d
+    c_ctx = SSL_CTX_new(SSLv23_client_method());
a9ab2d
     if (c_ctx == NULL) {
a9ab2d
 	return (-1);
a9ab2d
     };
a9ab2d
diff --git a/imtest/imtest.c b/imtest/imtest.c
a9ab2d
index 01ac72c..50d115d 100644
a9ab2d
--- a/imtest/imtest.c
a9ab2d
+++ b/imtest/imtest.c
a9ab2d
@@ -510,7 +510,7 @@ static int tls_init_clientengine(int verifydepth, char *var_tls_cert_file, char
a9ab2d
 	return IMTEST_FAIL;
a9ab2d
     }
a9ab2d
     
a9ab2d
-    tls_ctx = SSL_CTX_new(TLSv1_client_method());
a9ab2d
+    tls_ctx = SSL_CTX_new(SSLv23_client_method());
a9ab2d
     if (tls_ctx == NULL) {
a9ab2d
 	return IMTEST_FAIL;
a9ab2d
     };
a9ab2d
Index: cyrus-imapd-2.3.16/lib/imapoptions
a9ab2d
===================================================================
a9ab2d
--- cyrus-imapd-2.3.16.orig/lib/imapoptions
a9ab2d
+++ cyrus-imapd-2.3.16/lib/imapoptions
a9ab2d
@@ -1288,6 +1288,15 @@ product version in the capabilities */
a9ab2d
    the special use flag "\Drafts" added.  Later versions of Cyrus
a9ab2d
    have a much more flexible RFC 6154 compatible system.  */
a9ab2d
 
a9ab2d
+{ "tls_prefer_server_ciphers", 0, SWITCH }
a9ab2d
+/* Prefer the ciphers on the server side instead of client side */
a9ab2d
+
a9ab2d
+{ "tls_versions", "ssl2 ssl3 tls1_0 tls1_1 tls1_2", STRING }
a9ab2d
+/* A list of SSL/TLS versions to not disable. Cyrus IMAP SSL/TLS starts
a9ab2d
+   with all protocols, and substracts protocols not in this list. Newer
a9ab2d
+   versions of SSL/TLS will need to be added here to allow them to get
a9ab2d
+   disabled. */
a9ab2d
+
a9ab2d
 /*
a9ab2d
 .SH SEE ALSO
a9ab2d
 .PP