churchyard / rpms / openssl

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