Blame SOURCES/openssl-1.0.2j-deprecate-algos.patch

450916
diff -up openssl-1.0.2j/crypto/asn1/a_verify.c.deprecate-algos openssl-1.0.2j/crypto/asn1/a_verify.c
450916
--- openssl-1.0.2j/crypto/asn1/a_verify.c.deprecate-algos	2016-09-26 11:49:07.000000000 +0200
450916
+++ openssl-1.0.2j/crypto/asn1/a_verify.c	2017-01-09 16:47:11.666994197 +0100
450916
@@ -56,6 +56,9 @@
450916
  * [including the GNU Public Licence.]
450916
  */
450916
 
450916
+/* for secure_getenv */
450916
+#define _GNU_SOURCE
450916
+
450916
 #include <stdio.h>
450916
 #include <time.h>
450916
 
450916
@@ -133,6 +136,30 @@ int ASN1_verify(i2d_of_void *i2d, X509_A
450916
 
450916
 #endif
450916
 
450916
+static int legacy_mds[] = { NID_md5, NID_sha, NID_md4, NID_md2, 0 };
450916
+extern int private_ossl_allowed_legacy_mds[];
450916
+
450916
+static int is_md_legacy_disallowed(int mdnid)
450916
+{
450916
+    int i;
450916
+
450916
+    if (mdnid == NID_md5 && secure_getenv("OPENSSL_ENABLE_MD5_VERIFY") != NULL)
450916
+        return 0;
450916
+
450916
+    for (i = 0; legacy_mds[i] != 0; ++i) {
450916
+         if (mdnid == legacy_mds[i]) {
450916
+            int j;
450916
+
450916
+            for (j = 0; private_ossl_allowed_legacy_mds[j] != 0; ++j) {
450916
+                 if (mdnid == private_ossl_allowed_legacy_mds[j])
450916
+                     return 0;
450916
+            }
450916
+            return 1;
450916
+        }
450916
+     }
450916
+     return 0;
450916
+}
450916
+
450916
 int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
450916
                      ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey)
450916
 {
450916
@@ -174,6 +201,10 @@ int ASN1_item_verify(const ASN1_ITEM *it
450916
         if (ret != 2)
450916
             goto err;
450916
         ret = -1;
450916
+    } else if (is_md_legacy_disallowed(mdnid)) {
450916
+        ASN1err(ASN1_F_ASN1_ITEM_VERIFY,
450916
+                ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
450916
+        goto err;
450916
     } else {
450916
         const EVP_MD *type;
450916
         type = EVP_get_digestbynid(mdnid);
450916
diff -up openssl-1.0.2j/crypto/o_init.c.deprecate-algos openssl-1.0.2j/crypto/o_init.c
450916
--- openssl-1.0.2j/crypto/o_init.c.deprecate-algos	2017-01-05 17:49:00.000000000 +0100
450916
+++ openssl-1.0.2j/crypto/o_init.c	2017-01-09 16:52:29.018298611 +0100
450916
@@ -64,11 +64,21 @@
450916
 # include <unistd.h>
450916
 # include <errno.h>
450916
 # include <stdlib.h>
450916
+# include <stdio.h>
450916
+# include <string.h>
450916
+# include <strings.h>
450916
+# include <ctype.h>
450916
 # include <openssl/fips.h>
450916
 # include <openssl/rand.h>
450916
+# include <openssl/dh.h>
450916
+# include <openssl/objects.h>
450916
 
450916
 # define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"
450916
 
450916
+# define LEGACY_SETTINGS_FILE "/etc/pki/tls/legacy-settings"
450916
+
450916
+# define NUM_MAX_LEGACY_MDS 8
450916
+
450916
 static void init_fips_mode(void)
450916
 {
450916
     char buf[2] = "0";
450916
@@ -98,6 +108,115 @@ static void init_fips_mode(void)
450916
 }
450916
 #endif
450916
 
450916
+int private_ossl_allowed_legacy_mds[NUM_MAX_LEGACY_MDS + 1]; /* zero terminated */
450916
+
450916
+int private_ossl_minimum_dh_bits;
450916
+
450916
+static void parse_legacy_mds(char *p)
450916
+{
450916
+    int idx = 0;
450916
+    char *e = p;
450916
+
450916
+    while (p[0] != '\0') {
450916
+        while (e[0] != '\0' && !isspace(e[0]) && e[0] != ',') {
450916
+            ++e;
450916
+        }
450916
+        if (e[0] != '\0') {
450916
+            e[0] = '\0';
450916
+            ++e;
450916
+        }
450916
+
450916
+        if (strcasecmp(p, "md5") == 0) {
450916
+            private_ossl_allowed_legacy_mds[idx++] = NID_md5;
450916
+        } else if (strcasecmp(p, "md4") == 0) {
450916
+            private_ossl_allowed_legacy_mds[idx++] = NID_md4;
450916
+        } else if (strcasecmp(p, "sha") == 0) {
450916
+            private_ossl_allowed_legacy_mds[idx++] = NID_sha;
450916
+        } else if (strcasecmp(p, "md2") == 0) {
450916
+            private_ossl_allowed_legacy_mds[idx++] = NID_md2;
450916
+        }
450916
+
450916
+        if (idx >=
450916
+            sizeof(private_ossl_allowed_legacy_mds) /
450916
+            sizeof(private_ossl_allowed_legacy_mds[0])) {
450916
+            break;
450916
+        }
450916
+
450916
+        while (e[0] == ',' || isspace(e[0])) {
450916
+            ++e;
450916
+        }
450916
+
450916
+        p = e;
450916
+    }
450916
+}
450916
+
450916
+static void parse_minimum_dh_bits(char *p)
450916
+{
450916
+    private_ossl_minimum_dh_bits = strtol(p, NULL, 10);
450916
+    if (private_ossl_minimum_dh_bits < 512
450916
+        || private_ossl_minimum_dh_bits > OPENSSL_DH_MAX_MODULUS_BITS) {
450916
+        /* use default */
450916
+        private_ossl_minimum_dh_bits = 0;
450916
+    }
450916
+}
450916
+
450916
+static void load_legacy_settings(void)
450916
+{
450916
+    FILE *f;
450916
+    char *line = NULL;
450916
+    size_t len = 0;
450916
+
450916
+    if ((f = fopen(LEGACY_SETTINGS_FILE, "r")) == NULL) {
450916
+        return;
450916
+    }
450916
+
450916
+    while (getline(&line, &len, f) > 0) {
450916
+        char *p = line, *e, *val;
450916
+
450916
+        /* skip initial whitespace */
450916
+        while (isspace(p[0])) {
450916
+            ++p;
450916
+        }
450916
+
450916
+        e = p;
450916
+
450916
+        while (e[0] != '\0' && !isspace(e[0])) {
450916
+            ++e;
450916
+        }
450916
+
450916
+        /* terminate name, skip whitespace between name and value */
450916
+        if (e[0] != '\0') {
450916
+            e[0] = '\0';
450916
+            ++e;
450916
+            while (isspace(e[0])) {
450916
+                ++e;
450916
+            }
450916
+        }
450916
+
450916
+        val = e;
450916
+
450916
+        e = e + strlen(val);
450916
+
450916
+        /* trim terminating whitespace */
450916
+        while (e > val) {
450916
+            --e;
450916
+            if (isspace(e[0])) {
450916
+                e[0] = '\0';
450916
+            } else {
450916
+                break;
450916
+            }
450916
+        }
450916
+
450916
+        if (strcasecmp(p, "LegacySigningMDs") == 0) {
450916
+            parse_legacy_mds(val);
450916
+        } else if (strcasecmp(line, "MinimumDHBits") == 0) {
450916
+            parse_minimum_dh_bits(val);
450916
+        }
450916
+        /* simply skip other unrecognized lines */
450916
+    }
450916
+    (void)fclose(f);
450916
+}
450916
+
450916
 /*
450916
  * Perform any essential OpenSSL initialization operations. Currently only
450916
  * sets FIPS callbacks
450916
@@ -109,6 +228,7 @@ void __attribute__ ((constructor)) OPENS
450916
     if (done)
450916
         return;
450916
     done = 1;
450916
+    load_legacy_settings();
450916
 #ifdef OPENSSL_FIPS
450916
     if (!FIPS_module_installed()) {
450916
         return;
450916
diff -up openssl-1.0.2j/ssl/s3_clnt.c.deprecate-algos openssl-1.0.2j/ssl/s3_clnt.c
450916
--- openssl-1.0.2j/ssl/s3_clnt.c.deprecate-algos	2016-09-26 11:49:07.000000000 +0200
450916
+++ openssl-1.0.2j/ssl/s3_clnt.c	2017-01-09 17:01:19.428506961 +0100
450916
@@ -3478,6 +3478,8 @@ int ssl3_send_client_certificate(SSL *s)
450916
 
450916
 #define has_bits(i,m)   (((i)&(m)) == (m))
450916
 
450916
+extern int private_ossl_minimum_dh_bits;
450916
+
450916
 int ssl3_check_cert_and_algorithm(SSL *s)
450916
 {
450916
     int i, idx;
450916
@@ -3608,8 +3610,7 @@ int ssl3_check_cert_and_algorithm(SSL *s
450916
             DH_free(dh_srvr);
450916
         }
450916
 
450916
-        if ((!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 1024)
450916
-            || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 512)) {
450916
+        if (dh_size < (private_ossl_minimum_dh_bits ? private_ossl_minimum_dh_bits : 1024)) {
450916
             SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_DH_KEY_TOO_SMALL);
450916
             goto f_err;
450916
         }