Blame SOURCES/openssl-1.1.1-seclevel.patch

0bf02d
diff -up openssl-1.1.1g/crypto/x509/x509_vfy.c.seclevel openssl-1.1.1g/crypto/x509/x509_vfy.c
0bf02d
--- openssl-1.1.1g/crypto/x509/x509_vfy.c.seclevel	2020-04-21 14:22:39.000000000 +0200
0bf02d
+++ openssl-1.1.1g/crypto/x509/x509_vfy.c	2020-06-05 17:16:54.835536823 +0200
0bf02d
@@ -3225,6 +3225,7 @@ static int build_chain(X509_STORE_CTX *c
0bf02d
 }
0bf02d
 
0bf02d
 static const int minbits_table[] = { 80, 112, 128, 192, 256 };
0bf02d
+static const int minbits_digest_table[] = { 80, 80, 128, 192, 256 };
0bf02d
 static const int NUM_AUTH_LEVELS = OSSL_NELEM(minbits_table);
0bf02d
 
0bf02d
 /*
0bf02d
@@ -3276,6 +3277,11 @@ static int check_sig_level(X509_STORE_CT
0bf02d
 
0bf02d
     if (!X509_get_signature_info(cert, NULL, NULL, &secbits, NULL))
0bf02d
         return 0;
0bf02d
-
0bf02d
-    return secbits >= minbits_table[level - 1];
0bf02d
+    /*
0bf02d
+     * Allow SHA1 in SECLEVEL 2 in non-FIPS mode or when the magic
0bf02d
+     * disable SHA1 flag is not set.
0bf02d
+     */
0bf02d
+    if ((ctx->param->flags & 0x40000000) || FIPS_mode())
0bf02d
+        return secbits >= minbits_table[level - 1];
0bf02d
+    return secbits >= minbits_digest_table[level - 1];
0bf02d
 }
0bf02d
diff -up openssl-1.1.1g/doc/man3/SSL_CTX_set_security_level.pod.seclevel openssl-1.1.1g/doc/man3/SSL_CTX_set_security_level.pod
0bf02d
--- openssl-1.1.1g/doc/man3/SSL_CTX_set_security_level.pod.seclevel	2020-04-21 14:22:39.000000000 +0200
0bf02d
+++ openssl-1.1.1g/doc/man3/SSL_CTX_set_security_level.pod	2020-06-04 15:48:01.608178833 +0200
0bf02d
@@ -81,8 +81,10 @@ using MD5 for the MAC is also prohibited
0bf02d
 
0bf02d
 =item B<Level 2>
0bf02d
 
0bf02d
-Security level set to 112 bits of security. As a result RSA, DSA and DH keys
0bf02d
-shorter than 2048 bits and ECC keys shorter than 224 bits are prohibited.
0bf02d
+Security level set to 112 bits of security with the exception of SHA1 allowed
0bf02d
+for signatures.
0bf02d
+As a result RSA, DSA and DH keys shorter than 2048 bits and ECC keys
0bf02d
+shorter than 224 bits are prohibited.
0bf02d
 In addition to the level 1 exclusions any cipher suite using RC4 is also
0bf02d
 prohibited. SSL version 3 is also not allowed. Compression is disabled.
0bf02d
 
0bf02d
diff -up openssl-1.1.1g/ssl/ssl_cert.c.seclevel openssl-1.1.1g/ssl/ssl_cert.c
0bf02d
--- openssl-1.1.1g/ssl/ssl_cert.c.seclevel	2020-04-21 14:22:39.000000000 +0200
0bf02d
+++ openssl-1.1.1g/ssl/ssl_cert.c	2020-06-05 17:10:11.842198401 +0200
0bf02d
@@ -27,6 +27,7 @@
0bf02d
 static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx,
0bf02d
                                          int op, int bits, int nid, void *other,
0bf02d
                                          void *ex);
0bf02d
+static unsigned long sha1_disable(const SSL *s, const SSL_CTX *ctx);
0bf02d
 
0bf02d
 static CRYPTO_ONCE ssl_x509_store_ctx_once = CRYPTO_ONCE_STATIC_INIT;
0bf02d
 static volatile int ssl_x509_store_ctx_idx = -1;
0bf02d
@@ -396,7 +397,7 @@ int ssl_verify_cert_chain(SSL *s, STACK_
0bf02d
     X509_VERIFY_PARAM_set_auth_level(param, SSL_get_security_level(s));
0bf02d
 
0bf02d
     /* Set suite B flags if needed */
0bf02d
-    X509_STORE_CTX_set_flags(ctx, tls1_suiteb(s));
0bf02d
+    X509_STORE_CTX_set_flags(ctx, tls1_suiteb(s) | sha1_disable(s, NULL));
0bf02d
     if (!X509_STORE_CTX_set_ex_data
0bf02d
         (ctx, SSL_get_ex_data_X509_STORE_CTX_idx(), s)) {
0bf02d
         goto end;
0bf02d
@@ -953,12 +954,33 @@ static int ssl_security_default_callback
0bf02d
             return 0;
0bf02d
         break;
0bf02d
     default:
0bf02d
+        /* allow SHA1 in SECLEVEL 2 in non FIPS mode */
0bf02d
+        if (nid == NID_sha1 && minbits == 112 && !sha1_disable(s, ctx))
0bf02d
+            break;
0bf02d
         if (bits < minbits)
0bf02d
             return 0;
0bf02d
     }
0bf02d
     return 1;
0bf02d
 }
0bf02d
 
0bf02d
+static unsigned long sha1_disable(const SSL *s, const SSL_CTX *ctx)
0bf02d
+{
0bf02d
+    unsigned long ret = 0x40000000; /* a magical internal value used by X509_VERIFY_PARAM */
0bf02d
+    const CERT *c;
0bf02d
+
0bf02d
+    if (FIPS_mode())
0bf02d
+        return ret;
0bf02d
+
0bf02d
+    if (ctx != NULL) {
0bf02d
+       c = ctx->cert;
0bf02d
+    } else {
0bf02d
+       c = s->cert;
0bf02d
+    }
0bf02d
+    if (tls1_cert_sigalgs_have_sha1(c))
0bf02d
+        return 0;
0bf02d
+    return ret;
0bf02d
+}
0bf02d
+
0bf02d
 int ssl_security(const SSL *s, int op, int bits, int nid, void *other)
0bf02d
 {
0bf02d
     return s->cert->sec_cb(s, NULL, op, bits, nid, other, s->cert->sec_ex);
0bf02d
diff -up openssl-1.1.1g/ssl/ssl_local.h.seclevel openssl-1.1.1g/ssl/ssl_local.h
0bf02d
--- openssl-1.1.1g/ssl/ssl_local.h.seclevel	2020-06-04 15:48:01.602178783 +0200
0bf02d
+++ openssl-1.1.1g/ssl/ssl_local.h	2020-06-05 17:02:22.666313410 +0200
0bf02d
@@ -2576,6 +2576,7 @@ __owur int tls1_save_sigalgs(SSL *s, PAC
0bf02d
 __owur int tls1_process_sigalgs(SSL *s);
0bf02d
 __owur int tls1_set_peer_legacy_sigalg(SSL *s, const EVP_PKEY *pkey);
0bf02d
 __owur int tls1_lookup_md(const SIGALG_LOOKUP *lu, const EVP_MD **pmd);
0bf02d
+int tls1_cert_sigalgs_have_sha1(const CERT *c);
0bf02d
 __owur size_t tls12_get_psigalgs(SSL *s, int sent, const uint16_t **psigs);
0bf02d
 #  ifndef OPENSSL_NO_EC
0bf02d
 __owur int tls_check_sigalg_curve(const SSL *s, int curve);
0bf02d
diff -up openssl-1.1.1g/ssl/t1_lib.c.seclevel openssl-1.1.1g/ssl/t1_lib.c
0bf02d
--- openssl-1.1.1g/ssl/t1_lib.c.seclevel	2020-06-04 15:48:01.654179221 +0200
0bf02d
+++ openssl-1.1.1g/ssl/t1_lib.c	2020-06-05 17:02:40.268459157 +0200
0bf02d
@@ -2145,6 +2145,36 @@ int tls1_set_sigalgs(CERT *c, const int
0bf02d
     return 0;
0bf02d
 }
0bf02d
 
0bf02d
+static int tls1_sigalgs_have_sha1(const uint16_t *sigalgs, size_t sigalgslen)
0bf02d
+{
0bf02d
+    size_t i;
0bf02d
+
0bf02d
+    for (i = 0; i < sigalgslen; i++, sigalgs++) {
0bf02d
+        const SIGALG_LOOKUP *lu = tls1_lookup_sigalg(*sigalgs);
0bf02d
+
0bf02d
+        if (lu == NULL)
0bf02d
+            continue;
0bf02d
+        if (lu->hash == NID_sha1)
0bf02d
+            return 1;
0bf02d
+    }
0bf02d
+    return 0;
0bf02d
+}
0bf02d
+
0bf02d
+
0bf02d
+int tls1_cert_sigalgs_have_sha1(const CERT *c)
0bf02d
+{
0bf02d
+    if (c->client_sigalgs != NULL) {
0bf02d
+        if (tls1_sigalgs_have_sha1(c->client_sigalgs, c->client_sigalgslen))
0bf02d
+            return 1;
0bf02d
+    }
0bf02d
+    if (c->conf_sigalgs != NULL) {
0bf02d
+        if (tls1_sigalgs_have_sha1(c->conf_sigalgs, c->conf_sigalgslen))
0bf02d
+            return 1;
0bf02d
+        return 0;
0bf02d
+    }
0bf02d
+    return 1;
0bf02d
+}
0bf02d
+
0bf02d
 static int tls1_check_sig_alg(SSL *s, X509 *x, int default_nid)
0bf02d
 {
0bf02d
     int sig_nid, use_pc_sigalgs = 0;
0bf02d
diff -up openssl-1.1.1g/test/recipes/25-test_verify.t.seclevel openssl-1.1.1g/test/recipes/25-test_verify.t
0bf02d
--- openssl-1.1.1g/test/recipes/25-test_verify.t.seclevel	2020-04-21 14:22:39.000000000 +0200
0bf02d
+++ openssl-1.1.1g/test/recipes/25-test_verify.t	2020-06-04 15:48:01.608178833 +0200
0bf02d
@@ -346,8 +346,8 @@ ok(verify("ee-pss-sha1-cert", "sslserver
0bf02d
 ok(verify("ee-pss-sha256-cert", "sslserver", ["root-cert"], ["ca-cert"], ),
0bf02d
     "CA with PSS signature using SHA256");
0bf02d
 
0bf02d
-ok(!verify("ee-pss-sha1-cert", "sslserver", ["root-cert"], ["ca-cert"], "-auth_level", "2"),
0bf02d
-    "Reject PSS signature using SHA1 and auth level 2");
0bf02d
+ok(!verify("ee-pss-sha1-cert", "sslserver", ["root-cert"], ["ca-cert"], "-auth_level", "3"),
0bf02d
+    "Reject PSS signature using SHA1 and auth level 3");
0bf02d
 
0bf02d
 ok(verify("ee-pss-sha256-cert", "sslserver", ["root-cert"], ["ca-cert"], "-auth_level", "2"),
0bf02d
     "PSS signature using SHA256 and auth level 2");