isaacpittman-hitachi / rpms / openssl

Forked from rpms/openssl 2 years ago
Clone

Blame SOURCES/openssl-1.1.1-system-cipherlist.patch

acdedc
diff -up openssl-1.1.1c/Configurations/unix-Makefile.tmpl.system-cipherlist openssl-1.1.1c/Configurations/unix-Makefile.tmpl
acdedc
--- openssl-1.1.1c/Configurations/unix-Makefile.tmpl.system-cipherlist	2019-05-29 15:42:27.951329271 +0200
acdedc
+++ openssl-1.1.1c/Configurations/unix-Makefile.tmpl	2019-05-29 15:42:27.974328867 +0200
acdedc
@@ -180,6 +180,10 @@ MANDIR=$(INSTALLTOP)/share/man
acdedc
 DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
acdedc
 HTMLDIR=$(DOCDIR)/html
acdedc
 
acdedc
+{- output_off() if $config{system_ciphers_file} eq ""; "" -}
acdedc
+SYSTEM_CIPHERS_FILE_DEFINE=-DSYSTEM_CIPHERS_FILE="\"{- $config{system_ciphers_file} -}\""
acdedc
+{- output_on() if $config{system_ciphers_file} eq ""; "" -}
acdedc
+
acdedc
 # MANSUFFIX is for the benefit of anyone who may want to have a suffix
acdedc
 # appended after the manpage file section number.  "ssl" is popular,
acdedc
 # resulting in files such as config.5ssl rather than config.5.
acdedc
@@ -203,6 +207,7 @@ CC=$(CROSS_COMPILE){- $config{CC} -}
acdedc
 CXX={- $config{CXX} ? "\$(CROSS_COMPILE)$config{CXX}" : '' -}
acdedc
 CPPFLAGS={- our $cppflags1 = join(" ",
acdedc
                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
acdedc
+                                  "\$(SYSTEM_CIPHERS_FILE_DEFINE)",
acdedc
                                   (map { "-I".$_} @{$config{CPPINCLUDES}}),
acdedc
                                   @{$config{CPPFLAGS}}) -}
acdedc
 CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
acdedc
diff -up openssl-1.1.1c/Configure.system-cipherlist openssl-1.1.1c/Configure
acdedc
--- openssl-1.1.1c/Configure.system-cipherlist	2019-05-28 15:12:21.000000000 +0200
acdedc
+++ openssl-1.1.1c/Configure	2019-05-29 15:45:10.465469533 +0200
acdedc
@@ -24,7 +24,7 @@ use OpenSSL::Glob;
acdedc
 my $orig_death_handler = $SIG{__DIE__};
acdedc
 $SIG{__DIE__} = \&death_handler;
acdedc
 
acdedc
-my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";
acdedc
+my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--system-ciphers-file=SYSTEMCIPHERFILE] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";
acdedc
 
acdedc
 # Options:
acdedc
 #
acdedc
@@ -41,6 +41,9 @@ my $usage="Usage: Configure [no-<cipher>
acdedc
 #               This becomes the value of OPENSSLDIR in Makefile and in C.
acdedc
 #               (Default: PREFIX/ssl)
acdedc
 #
acdedc
+# --system-ciphers-file  A file to read cipher string from when the PROFILE=SYSTEM
acdedc
+#		cipher is specified (default).
acdedc
+#
acdedc
 # --cross-compile-prefix Add specified prefix to binutils components.
acdedc
 #
acdedc
 # --api         One of 0.9.8, 1.0.0 or 1.1.0.  Do not compile support for
acdedc
@@ -295,6 +298,7 @@ $config{prefix}="";
acdedc
 $config{openssldir}="";
acdedc
 $config{processor}="";
acdedc
 $config{libdir}="";
acdedc
+$config{system_ciphers_file}="";
acdedc
 my $auto_threads=1;    # enable threads automatically? true by default
acdedc
 my $default_ranlib;
acdedc
 
acdedc
@@ -824,6 +828,10 @@ while (@argvcopy)
acdedc
                             push @seed_sources, $x;
acdedc
                             }
acdedc
                         }
acdedc
+		elsif (/^--system-ciphers-file=(.*)$/)
acdedc
+			{
acdedc
+			$config{system_ciphers_file}=$1;
acdedc
+			}
acdedc
                 elsif (/^--cross-compile-prefix=(.*)$/)
acdedc
                         {
acdedc
                         $user{CROSS_COMPILE}=$1;
acdedc
@@ -1016,6 +1024,8 @@ if ($target eq "HASH") {
acdedc
     exit 0;
acdedc
 }
acdedc
 
acdedc
+chop $config{system_ciphers_file} if $config{system_ciphers_file} =~ /\/$/;
acdedc
+
acdedc
 print "Configuring OpenSSL version $config{version} ($config{version_num}) ";
acdedc
 print "for $target\n";
acdedc
 
acdedc
diff -up openssl-1.1.1c/doc/man1/ciphers.pod.system-cipherlist openssl-1.1.1c/doc/man1/ciphers.pod
acdedc
--- openssl-1.1.1c/doc/man1/ciphers.pod.system-cipherlist	2019-05-28 15:12:21.000000000 +0200
acdedc
+++ openssl-1.1.1c/doc/man1/ciphers.pod	2019-05-29 15:42:27.975328849 +0200
acdedc
@@ -182,6 +182,15 @@ As of OpenSSL 1.0.0, the B<ALL> cipher s
acdedc
 
acdedc
 The cipher suites not enabled by B<ALL>, currently B<eNULL>.
acdedc
 
acdedc
+=item B<PROFILE=SYSTEM>
acdedc
+
acdedc
+The list of enabled cipher suites will be loaded from the system crypto policy
acdedc
+configuration file B</etc/crypto-policies/back-ends/openssl.config>.
acdedc
+See also L<update-crypto-policies(8)>.
acdedc
+This is the default behavior unless an application explicitly sets a cipher
acdedc
+list. If used in a cipher list configuration value this string must be at the
acdedc
+beginning of the cipher list, otherwise it will not be recognized.
acdedc
+
acdedc
 =item B<HIGH>
acdedc
 
acdedc
 "High" encryption cipher suites. This currently means those with key lengths
acdedc
diff -up openssl-1.1.1c/include/openssl/ssl.h.system-cipherlist openssl-1.1.1c/include/openssl/ssl.h
acdedc
--- openssl-1.1.1c/include/openssl/ssl.h.system-cipherlist	2019-05-28 15:12:21.000000000 +0200
acdedc
+++ openssl-1.1.1c/include/openssl/ssl.h	2019-05-29 15:42:27.975328849 +0200
acdedc
@@ -186,6 +186,11 @@ extern "C" {
acdedc
  * throwing out anonymous and unencrypted ciphersuites! (The latter are not
acdedc
  * actually enabled by ALL, but "ALL:RSA" would enable some of them.)
acdedc
  */
acdedc
+# ifdef SYSTEM_CIPHERS_FILE
acdedc
+#  define SSL_SYSTEM_DEFAULT_CIPHER_LIST "PROFILE=SYSTEM"
acdedc
+# else
acdedc
+#  define SSL_SYSTEM_DEFAULT_CIPHER_LIST SSL_DEFAULT_CIPHER_LIST
acdedc
+# endif
acdedc
 
acdedc
 /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
acdedc
 # define SSL_SENT_SHUTDOWN       1
acdedc
diff -up openssl-1.1.1c/ssl/ssl_ciph.c.system-cipherlist openssl-1.1.1c/ssl/ssl_ciph.c
acdedc
--- openssl-1.1.1c/ssl/ssl_ciph.c.system-cipherlist	2019-05-28 15:12:21.000000000 +0200
acdedc
+++ openssl-1.1.1c/ssl/ssl_ciph.c	2019-05-29 15:42:27.976328831 +0200
acdedc
@@ -9,6 +9,8 @@
acdedc
  * https://www.openssl.org/source/license.html
acdedc
  */
acdedc
 
acdedc
+/* for secure_getenv */
acdedc
+#define _GNU_SOURCE
acdedc
 #include <stdio.h>
acdedc
 #include <ctype.h>
acdedc
 #include <openssl/objects.h>
acdedc
@@ -1399,6 +1401,53 @@ int SSL_set_ciphersuites(SSL *s, const c
acdedc
     return ret;
acdedc
 }
acdedc
 
acdedc
+#ifdef SYSTEM_CIPHERS_FILE
acdedc
+static char *load_system_str(const char *suffix)
acdedc
+{
acdedc
+    FILE *fp;
acdedc
+    char buf[1024];
acdedc
+    char *new_rules;
acdedc
+    const char *ciphers_path;
acdedc
+    unsigned len, slen;
acdedc
+
acdedc
+    if ((ciphers_path = secure_getenv("OPENSSL_SYSTEM_CIPHERS_OVERRIDE")) == NULL)
acdedc
+        ciphers_path = SYSTEM_CIPHERS_FILE;
acdedc
+    fp = fopen(ciphers_path, "r");
acdedc
+    if (fp == NULL || fgets(buf, sizeof(buf), fp) == NULL) {
acdedc
+        /* cannot open or file is empty */
acdedc
+        snprintf(buf, sizeof(buf), "%s", SSL_DEFAULT_CIPHER_LIST);
acdedc
+    }
acdedc
+
acdedc
+    if (fp)
acdedc
+        fclose(fp);
acdedc
+
acdedc
+    slen = strlen(suffix);
acdedc
+    len = strlen(buf);
acdedc
+
acdedc
+    if (buf[len - 1] == '\n') {
acdedc
+        len--;
acdedc
+        buf[len] = 0;
acdedc
+    }
acdedc
+    if (buf[len - 1] == '\r') {
acdedc
+        len--;
acdedc
+        buf[len] = 0;
acdedc
+    }
acdedc
+
acdedc
+    new_rules = OPENSSL_malloc(len + slen + 1);
acdedc
+    if (new_rules == 0)
acdedc
+        return NULL;
acdedc
+
acdedc
+    memcpy(new_rules, buf, len);
acdedc
+    if (slen > 0) {
acdedc
+        memcpy(&new_rules[len], suffix, slen);
acdedc
+        len += slen;
acdedc
+    }
acdedc
+    new_rules[len] = 0;
acdedc
+
acdedc
+    return new_rules;
acdedc
+}
acdedc
+#endif
acdedc
+
acdedc
 STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
acdedc
                                              STACK_OF(SSL_CIPHER) *tls13_ciphersuites,
acdedc
                                              STACK_OF(SSL_CIPHER) **cipher_list,
acdedc
@@ -1412,15 +1461,25 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_
acdedc
     const char *rule_p;
acdedc
     CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
acdedc
     const SSL_CIPHER **ca_list = NULL;
acdedc
+#ifdef SYSTEM_CIPHERS_FILE
acdedc
+    char *new_rules = NULL;
acdedc
+
acdedc
+    if (rule_str != NULL && strncmp(rule_str, "PROFILE=SYSTEM", 14) == 0) {
acdedc
+        char *p = rule_str + 14;
acdedc
+    
acdedc
+        new_rules = load_system_str(p);
acdedc
+        rule_str = new_rules;
acdedc
+    }
acdedc
+#endif
acdedc
 
acdedc
     /*
acdedc
      * Return with error if nothing to do.
acdedc
      */
acdedc
     if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL)
acdedc
-        return NULL;
acdedc
+        goto err;
acdedc
 #ifndef OPENSSL_NO_EC
acdedc
     if (!check_suiteb_cipher_list(ssl_method, c, &rule_str))
acdedc
-        return NULL;
acdedc
+        goto err;
acdedc
 #endif
acdedc
 
acdedc
     /*
acdedc
@@ -1443,7 +1502,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_
acdedc
     co_list = OPENSSL_malloc(sizeof(*co_list) * num_of_ciphers);
acdedc
     if (co_list == NULL) {
acdedc
         SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
acdedc
-        return NULL;          /* Failure */
acdedc
+        goto err;
acdedc
     }
acdedc
 
acdedc
     ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers,
acdedc
@@ -1509,8 +1568,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_
acdedc
      * in force within each class
acdedc
      */
acdedc
     if (!ssl_cipher_strength_sort(&head, &tail)) {
acdedc
-        OPENSSL_free(co_list);
acdedc
-        return NULL;
acdedc
+        goto err;
acdedc
     }
acdedc
 
acdedc
     /*
acdedc
@@ -1555,9 +1613,8 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_
acdedc
     num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
acdedc
     ca_list = OPENSSL_malloc(sizeof(*ca_list) * num_of_alias_max);
acdedc
     if (ca_list == NULL) {
acdedc
-        OPENSSL_free(co_list);
acdedc
         SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
acdedc
-        return NULL;          /* Failure */
acdedc
+        goto err;
acdedc
     }
acdedc
     ssl_cipher_collect_aliases(ca_list, num_of_group_aliases,
acdedc
                                disabled_mkey, disabled_auth, disabled_enc,
acdedc
@@ -1583,8 +1640,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_
acdedc
     OPENSSL_free(ca_list);      /* Not needed anymore */
acdedc
 
acdedc
     if (!ok) {                  /* Rule processing failure */
acdedc
-        OPENSSL_free(co_list);
acdedc
-        return NULL;
acdedc
+        goto err;
acdedc
     }
acdedc
 
acdedc
     /*
acdedc
@@ -1592,14 +1648,18 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_
acdedc
      * if we cannot get one.
acdedc
      */
acdedc
     if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) {
acdedc
-        OPENSSL_free(co_list);
acdedc
-        return NULL;
acdedc
+        goto err;
acdedc
     }
acdedc
 
acdedc
+#ifdef SYSTEM_CIPHERS_FILE
acdedc
+    OPENSSL_free(new_rules);    /* Not needed anymore */
acdedc
+#endif
acdedc
+
acdedc
     /* Add TLSv1.3 ciphers first - we always prefer those if possible */
acdedc
     for (i = 0; i < sk_SSL_CIPHER_num(tls13_ciphersuites); i++) {
acdedc
         if (!sk_SSL_CIPHER_push(cipherstack,
acdedc
                                 sk_SSL_CIPHER_value(tls13_ciphersuites, i))) {
acdedc
+            OPENSSL_free(co_list);
acdedc
             sk_SSL_CIPHER_free(cipherstack);
acdedc
             return NULL;
acdedc
         }
acdedc
@@ -1631,6 +1691,14 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_
acdedc
     *cipher_list = cipherstack;
acdedc
 
acdedc
     return cipherstack;
acdedc
+
acdedc
+err:
acdedc
+    OPENSSL_free(co_list);
acdedc
+#ifdef SYSTEM_CIPHERS_FILE
acdedc
+    OPENSSL_free(new_rules);
acdedc
+#endif
acdedc
+    return NULL;
acdedc
+  
acdedc
 }
acdedc
 
acdedc
 char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
acdedc
diff -up openssl-1.1.1c/ssl/ssl_lib.c.system-cipherlist openssl-1.1.1c/ssl/ssl_lib.c
acdedc
--- openssl-1.1.1c/ssl/ssl_lib.c.system-cipherlist	2019-05-29 15:42:27.970328937 +0200
acdedc
+++ openssl-1.1.1c/ssl/ssl_lib.c	2019-05-29 15:42:27.977328814 +0200
acdedc
@@ -662,7 +662,7 @@ int SSL_CTX_set_ssl_version(SSL_CTX *ctx
acdedc
                                 ctx->tls13_ciphersuites,
acdedc
                                 &(ctx->cipher_list),
acdedc
                                 &(ctx->cipher_list_by_id),
acdedc
-                                SSL_DEFAULT_CIPHER_LIST, ctx->cert);
acdedc
+                                SSL_SYSTEM_DEFAULT_CIPHER_LIST, ctx->cert);
acdedc
     if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) {
acdedc
         SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION, SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
acdedc
         return 0;
acdedc
@@ -2954,7 +2954,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *m
acdedc
     if (!ssl_create_cipher_list(ret->method,
acdedc
                                 ret->tls13_ciphersuites,
acdedc
                                 &ret->cipher_list, &ret->cipher_list_by_id,
acdedc
-                                SSL_DEFAULT_CIPHER_LIST, ret->cert)
acdedc
+                                SSL_SYSTEM_DEFAULT_CIPHER_LIST, ret->cert)
acdedc
         || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {
acdedc
         SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS);
acdedc
         goto err2;
acdedc
diff -up openssl-1.1.1c/test/cipherlist_test.c.system-cipherlist openssl-1.1.1c/test/cipherlist_test.c
acdedc
--- openssl-1.1.1c/test/cipherlist_test.c.system-cipherlist	2019-05-28 15:12:21.000000000 +0200
acdedc
+++ openssl-1.1.1c/test/cipherlist_test.c	2019-05-29 15:42:27.977328814 +0200
acdedc
@@ -251,7 +251,9 @@ end:
acdedc
 
acdedc
 int setup_tests(void)
acdedc
 {
acdedc
+#ifndef SYSTEM_CIPHERS_FILE
acdedc
     ADD_TEST(test_default_cipherlist_implicit);
acdedc
+#endif
acdedc
     ADD_TEST(test_default_cipherlist_explicit);
acdedc
     ADD_TEST(test_default_cipherlist_clear);
acdedc
     return 1;