Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/openssl/dist Import 1.0.1p to fix:



details:   https://anonhg.NetBSD.org/src/rev/04893f85fab1
branches:  trunk
changeset: 339276:04893f85fab1
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jul 09 14:15:22 2015 +0000

description:
Import 1.0.1p to fix:

  *) Alternate chains certificate forgery

     During certificate verfification, OpenSSL will attempt to find an
     alternative certificate chain if the first attempt to build such a chain
     fails. An error in the implementation of this logic can mean that an
     attacker could cause certain checks on untrusted certificates to be
     bypassed, such as the CA flag, enabling them to use a valid leaf
     certificate to act as a CA and "issue" an invalid certificate.

     This issue was reported to OpenSSL by Adam Langley/David Benjamin
     (Google/BoringSSL).
     [Matt Caswell]

diffstat:

 crypto/external/bsd/openssl/dist/Makefile.org                              |   11 +-
 crypto/external/bsd/openssl/dist/crypto/bio/bio.h                          |    2 +-
 crypto/external/bsd/openssl/dist/crypto/opensslconf.h.in                   |    2 +-
 crypto/external/bsd/openssl/dist/crypto/pkcs12/p12_kiss.c                  |    2 +
 crypto/external/bsd/openssl/dist/crypto/threads/pthread2.sh                |    3 +-
 crypto/external/bsd/openssl/dist/crypto/x509/Makefile                      |    2 +-
 crypto/external/bsd/openssl/dist/crypto/x509/verify_extra_test.c           |  209 ++++++++++
 crypto/external/bsd/openssl/dist/doc/crypto/X509_NAME_get_index_by_NID.pod |    7 +
 crypto/external/bsd/openssl/dist/doc/crypto/X509_STORE_CTX_new.pod         |   13 +-
 crypto/external/bsd/openssl/dist/doc/crypto/X509_verify_cert.pod           |    3 +-
 crypto/external/bsd/openssl/dist/test/certs/bad.key                        |   27 +
 crypto/external/bsd/openssl/dist/test/certs/bad.pem                        |   21 +
 crypto/external/bsd/openssl/dist/test/certs/interCA.key                    |   27 +
 crypto/external/bsd/openssl/dist/test/certs/interCA.pem                    |   21 +
 crypto/external/bsd/openssl/dist/test/certs/leaf.key                       |   27 +
 crypto/external/bsd/openssl/dist/test/certs/leaf.pem                       |   21 +
 crypto/external/bsd/openssl/dist/test/certs/rootCA.key                     |   27 +
 crypto/external/bsd/openssl/dist/test/certs/rootCA.pem                     |   21 +
 crypto/external/bsd/openssl/dist/test/certs/roots.pem                      |   42 ++
 crypto/external/bsd/openssl/dist/test/certs/subinterCA-ss.pem              |   21 +
 crypto/external/bsd/openssl/dist/test/certs/subinterCA.key                 |   27 +
 crypto/external/bsd/openssl/dist/test/certs/subinterCA.pem                 |   21 +
 crypto/external/bsd/openssl/dist/test/certs/untrusted.pem                  |   42 ++
 23 files changed, 584 insertions(+), 15 deletions(-)

diffs (truncated from 771 to 300 lines):

diff -r 33d64f288749 -r 04893f85fab1 crypto/external/bsd/openssl/dist/Makefile.org
--- a/crypto/external/bsd/openssl/dist/Makefile.org     Thu Jul 09 13:39:51 2015 +0000
+++ b/crypto/external/bsd/openssl/dist/Makefile.org     Thu Jul 09 14:15:22 2015 +0000
@@ -268,6 +268,7 @@
        @[ -n "$(THIS)" ] && $(CLEARENV) && $(MAKE) $(THIS) -e $(BUILDENV)
 
 sub_all: build_all
+
 build_all: build_libs build_apps build_tests build_tools
 
 build_libs: build_libcrypto build_libssl openssl.pc
@@ -277,15 +278,15 @@
 
 build_crypto:
        @dir=crypto; target=all; $(BUILD_ONE_CMD)
-build_ssl:
+build_ssl: build_crypto
        @dir=ssl; target=all; $(BUILD_ONE_CMD)
-build_engines:
+build_engines: build_crypto
        @dir=engines; target=all; $(BUILD_ONE_CMD)
-build_apps:
+build_apps: build_libs
        @dir=apps; target=all; $(BUILD_ONE_CMD)
-build_tests:
+build_tests: build_libs
        @dir=test; target=all; $(BUILD_ONE_CMD)
-build_tools:
+build_tools: build_libs
        @dir=tools; target=all; $(BUILD_ONE_CMD)
 
 all_testapps: build_libs build_testapps
diff -r 33d64f288749 -r 04893f85fab1 crypto/external/bsd/openssl/dist/crypto/bio/bio.h
--- a/crypto/external/bsd/openssl/dist/crypto/bio/bio.h Thu Jul 09 13:39:51 2015 +0000
+++ b/crypto/external/bsd/openssl/dist/crypto/bio/bio.h Thu Jul 09 14:15:22 2015 +0000
@@ -290,7 +290,7 @@
  * BIO_CB_RETURN flag indicates if it is after the call
  */
 # define BIO_CB_RETURN   0x80
-# define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
+# define BIO_CB_return(a) ((a)|BIO_CB_RETURN)
 # define BIO_cb_pre(a)   (!((a)&BIO_CB_RETURN))
 # define BIO_cb_post(a)  ((a)&BIO_CB_RETURN)
 
diff -r 33d64f288749 -r 04893f85fab1 crypto/external/bsd/openssl/dist/crypto/opensslconf.h.in
--- a/crypto/external/bsd/openssl/dist/crypto/opensslconf.h.in  Thu Jul 09 13:39:51 2015 +0000
+++ b/crypto/external/bsd/openssl/dist/crypto/opensslconf.h.in  Thu Jul 09 14:15:22 2015 +0000
@@ -101,7 +101,7 @@
 #endif
 
 #if defined(DES_RISC1) && defined(DES_RISC2)
-YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
+#error YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
 #endif
 
 /* Unroll the inner loop, this sometimes helps, sometimes hinders.
diff -r 33d64f288749 -r 04893f85fab1 crypto/external/bsd/openssl/dist/crypto/pkcs12/p12_kiss.c
--- a/crypto/external/bsd/openssl/dist/crypto/pkcs12/p12_kiss.c Thu Jul 09 13:39:51 2015 +0000
+++ b/crypto/external/bsd/openssl/dist/crypto/pkcs12/p12_kiss.c Thu Jul 09 14:15:22 2015 +0000
@@ -135,10 +135,12 @@
 
     while ((x = sk_X509_pop(ocerts))) {
         if (pkey && *pkey && cert && !*cert) {
+            ERR_set_mark();
             if (X509_check_private_key(x, *pkey)) {
                 *cert = x;
                 x = NULL;
             }
+            ERR_pop_to_mark();
         }
 
         if (ca && x) {
diff -r 33d64f288749 -r 04893f85fab1 crypto/external/bsd/openssl/dist/crypto/threads/pthread2.sh
--- a/crypto/external/bsd/openssl/dist/crypto/threads/pthread2.sh       Thu Jul 09 13:39:51 2015 +0000
+++ b/crypto/external/bsd/openssl/dist/crypto/threads/pthread2.sh       Thu Jul 09 14:15:22 2015 +0000
@@ -3,5 +3,4 @@
 # build using pthreads where it's already built into the system
 #
 /bin/rm -f mttest
-gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread
-
+gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread -ldl
diff -r 33d64f288749 -r 04893f85fab1 crypto/external/bsd/openssl/dist/crypto/x509/Makefile
--- a/crypto/external/bsd/openssl/dist/crypto/x509/Makefile     Thu Jul 09 13:39:51 2015 +0000
+++ b/crypto/external/bsd/openssl/dist/crypto/x509/Makefile     Thu Jul 09 14:15:22 2015 +0000
@@ -13,7 +13,7 @@
 CFLAGS= $(INCLUDES) $(CFLAG)
 
 GENERAL=Makefile README
-TEST=
+TEST=verify_extra_test.c
 APPS=
 
 LIB=$(TOP)/libcrypto.a
diff -r 33d64f288749 -r 04893f85fab1 crypto/external/bsd/openssl/dist/crypto/x509/verify_extra_test.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/openssl/dist/crypto/x509/verify_extra_test.c  Thu Jul 09 14:15:22 2015 +0000
@@ -0,0 +1,209 @@
+/*
+ * Written by Matt Caswell for the OpenSSL project.
+ */
+/* ====================================================================
+ * Copyright (c) 1998-2015 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core%openssl.org@localhost.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay%cryptsoft.com@localhost).  This product includes software written by Tim
+ * Hudson (tjh%cryptsoft.com@localhost).
+ *
+ */
+
+#include <stdio.h>
+#include <openssl/crypto.h>
+#include <openssl/bio.h>
+#include <openssl/x509.h>
+#include <openssl/pem.h>
+#include <openssl/err.h>
+
+static STACK_OF(X509) *load_certs_from_file(const char *filename)
+{
+    STACK_OF(X509) *certs;
+    BIO *bio;
+    X509 *x;
+
+    bio = BIO_new_file(filename, "r");
+
+    if (bio == NULL) {
+        return NULL;
+    }
+
+    certs = sk_X509_new_null();
+    if (certs == NULL) {
+        BIO_free(bio);
+        return NULL;
+    }
+
+    ERR_set_mark();
+    do {
+        x = PEM_read_bio_X509(bio, NULL, 0, NULL);
+        if (x != NULL && !sk_X509_push(certs, x)) {
+            sk_X509_pop_free(certs, X509_free);
+            BIO_free(bio);
+            return NULL;
+        } else if (x == NULL) {
+            /*
+             * We probably just ran out of certs, so ignore any errors
+             * generated
+             */
+            ERR_pop_to_mark();
+        }
+    } while (x != NULL);
+
+    BIO_free(bio);
+
+    return certs;
+}
+
+/*
+ * Test for CVE-2015-1793 (Alternate Chains Certificate Forgery)
+ *
+ * Chain is as follows:
+ *
+ * rootCA (self-signed)
+ *   |
+ * interCA
+ *   |
+ * subinterCA       subinterCA (self-signed)
+ *   |                   |
+ * leaf ------------------
+ *   |
+ * bad
+ *
+ * rootCA, interCA, subinterCA, subinterCA (ss) all have CA=TRUE
+ * leaf and bad have CA=FALSE
+ *
+ * subinterCA and subinterCA (ss) have the same subject name and keys
+ *
+ * interCA (but not rootCA) and subinterCA (ss) are in the trusted store
+ * (roots.pem)
+ * leaf and subinterCA are in the untrusted list (untrusted.pem)
+ * bad is the certificate being verified (bad.pem)
+ *
+ * Versions vulnerable to CVE-2015-1793 will fail to detect that leaf has
+ * CA=FALSE, and will therefore incorrectly verify bad
+ *
+ */
+static int test_alt_chains_cert_forgery(void)
+{
+    int ret = 0;
+    int i;
+    X509 *x = NULL;
+    STACK_OF(X509) *untrusted = NULL;
+    BIO *bio = NULL;
+    X509_STORE_CTX *sctx = NULL;
+    X509_STORE *store = NULL;
+    X509_LOOKUP *lookup = NULL;
+
+    store = X509_STORE_new();
+    if (store == NULL)
+        goto err;
+
+    lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
+    if (lookup == NULL)
+        goto err;
+    if(!X509_LOOKUP_load_file(lookup, "certs/roots.pem", X509_FILETYPE_PEM))
+        goto err;
+
+    untrusted = load_certs_from_file("certs/untrusted.pem");
+
+    if ((bio = BIO_new_file("certs/bad.pem", "r")) == NULL)
+        goto err;
+
+    if((x = PEM_read_bio_X509(bio, NULL, 0, NULL)) == NULL)
+        goto err;
+
+    sctx = X509_STORE_CTX_new();
+    if (sctx == NULL)
+        goto err;
+
+    if (!X509_STORE_CTX_init(sctx, store, x, untrusted))
+        goto err;
+
+    i = X509_verify_cert(sctx);
+
+    if(i == 0 && X509_STORE_CTX_get_error(sctx)
+                 == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT) {
+        /* This is the result we were expecting: Test passed */
+        ret = 1;
+    }
+ err:
+    X509_STORE_CTX_free(sctx);
+    X509_free(x);
+    BIO_free(bio);
+    sk_X509_pop_free(untrusted, X509_free);
+    X509_STORE_free(store);
+    if (ret != 1)
+        ERR_print_errors_fp(stderr);
+    return ret;
+}
+
+int main(void)
+{
+    CRYPTO_malloc_debug_init();
+    CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+
+    ERR_load_crypto_strings();
+    OpenSSL_add_all_digests();
+
+    if (!test_alt_chains_cert_forgery()) {
+        fprintf(stderr, "Test alt chains cert forgery failed\n");
+        return 1;
+    }
+
+    EVP_cleanup();
+    CRYPTO_cleanup_all_ex_data();



Home | Main Index | Thread Index | Old Index