-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a test for CVE-2015-1793. This adds a new test file verify_extra_test.c, which could form the basis for additional verification tests. Reviewed-by: Stephen Henson <steve@openssl.org>
- Loading branch information
1 parent
21376d8
commit f404943
Showing
16 changed files
with
581 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
/* | ||
* 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. | ||
* | ||
* 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). This product includes software written by Tim | ||
* Hudson (tjh@cryptsoft.com). | ||
* | ||
*/ | ||
|
||
#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_INVALID_CA) { | ||
/* 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(); | ||
ERR_remove_thread_state(NULL); | ||
ERR_free_strings(); | ||
CRYPTO_mem_leaks_fp(stderr); | ||
|
||
printf("PASS\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- |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lKiSGVDVnr6jb69WUujCkYUZIwR | ||
Q20QYBUUQu0JiFBU22tRgILIAK+rRah37EP4RPECgYBN3hKH1fDGpw1R+QoVyPHf | ||
pYYQzQJiqiFhSJeYOCCiaIoSFjrbdfH+pjjMMbMQKctmIYI4KRZvijaSFiV3XeLP | ||
kCI6KWQLCf2nRUjISa+cBAVLib88mMzrnROyHiA+psFGOrAuc/DSQ3lUxxKUT+HH | ||
+G6I4XHQKE7Du2X+qGzs4QKBgBZyJNjRxWhF7rR5Dq4/RHsLM0yKqPPCoSkx2+ur | ||
WJjU47sofpVKUE4mzUaOumGnNicqk3nfkgw54HL6kTZpQ7JqUKt9pNGLBM+zI8qi | ||
njPec04MRmo7zjg1YKNmqDodXGl38QD7+5r/VRzO04fwgI8e5G98aiOhIuLezGHR | ||
R3GRAoGAAyhwtKoC87fSGrpyZQ16UAYuqNy0fVAQtrDgRgP5Nu4esr9QxS/hWjcR | ||
8s2P82wsR4gZna6l6vSz4awGVG4PGKnVjteAtZxok3nBHxPmRke5o7IpdObPjpQP | ||
RJNZYbJ9G/PbYDhciEoTjVyig6Ol5BRe9stSbO7+JIxEYr7VSpA= | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDdzCCAl+gAwIBAgIJAJgwOOciuxjSMA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV | ||
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX | ||
aWRnaXRzIFB0eSBMdGQxDTALBgNVBAMTBGxlYWYwHhcNMTUwNzAyMTMyMDQ2WhcN | ||
MzUwNzAyMTMyMDQ2WjBTMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0 | ||
ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQwwCgYDVQQDEwNi | ||
YWQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDBOo2Sjm9CJDkFCiE8 | ||
nezJKuNPol52Owq23U5nyd1HYLVqxSIeClU7xAMcogPzxCSXHpQKJ54oDAhjRXOp | ||
bNPJlZPB2pNT23xqsccm7shwWWZawAt/BOYBFYmalj4rx8adDHUrF+LqdAnxaGrh | ||
twConYdfMbr1aOzcqLvRJw1tD1FTBcmf8V42uymEoC/krbbMGqNYBB1gyDq+0pkB | ||
cIRPyPDo6Q9WdRv9C/KgESKNa3T4cGHvAuRJS8yP/t9zzz7G28apk/IbY/LgN1Zb | ||
Wy2mCJndNOiESTzi3W7kvepBpFCZUTrLlEwibJVjyF6ALjNzpoZkMVG/wxH6CTqm | ||
ty5TAgMBAAGjTTBLMAkGA1UdEwQCMAAwHQYDVR0OBBYEFJoH29IULbskIG8BwYp4 | ||
9yD+q7wbMB8GA1UdIwQYMBaAFBwdxP7xJUYhGU31hO4z2uXPtRl/MA0GCSqGSIb3 | ||
DQEBCwUAA4IBAQBl0tHkWMBHW6r3ywBlWWFdok04xlt2QD8eA4ywwz97t/8JgLht | ||
OpuHO1bQtrZR6bxAgYT1+yHQnYBTfjKxFq+S9EP6nxBe94mEgizLmMv9pf7x5q+H | ||
pfT8ejcY54E/oXlFXSbLDE1BDpfgkWll2/TIsTRJNoM2n8mytEdPqzRburwWnoFR | ||
VchcfO968asdc9/8glSLJSNO+Wh9vQlbtcPzfbd4ZVE5E/P6drQzSwNjWvHQdswJ | ||
ujkY1zkTP2rtVBGN4OyOfkE6enVKpt5lN6AqjEMhJ5i/yFM/jDndTrgd/JkAvyUJ | ||
O2ELtifCd8DeSYNA9Qm8/MEUYq1xXQrGJHCE | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEowIBAAKCAQEAu7NHo76UDp738A/nuEfvVkKL7a7Kjk8PJIYkRKouSZZgBW6Q | ||
xBWptfJ6UZLeoDnBjJ47hc7s+ohLkJnnsodAalgMKTIFjDLXhMyzgGqpBJf/ydvl | ||
oEWwP/KZsB32z1v3fn926euBaA9YUAHpwc15i8VaIREPQQPsRA0ZC/3AN2PpPztQ | ||
vTkYUkKyTbAfWhN8ymxR3fZjph+GjUrBfDp90qpUVTgkIp3uXOgAkndB1BI2MvWj | ||
m6mOO8kjVC281auculTozLNFvthv16q3FZMc3/W1aslQa6wCa529+f8v4itM1oCQ | ||
T/h14cK+ZjE7zbhIqwXlWLs/uoVHq1G7iYa9BQIDAQABAoIBABa8FldNBB3pP1rC | ||
cmytud2W3eACJeKqzMi9vrLachTTs/m0dLBrd0zke9BZm8GIfVsM52TDtYx66bww | ||
CBJls3WuCHsM5gMfPV+Gc8+AG8zEpGTMz7lj938nYVolpvliyE14Hu0ia2AxS58V | ||
PD0PKEO3ubz7lf9n/DwZ4gjDyX5r1Cq+thwPlIf4PbEcGHk5SYxNm2DGR0DNL676 | ||
X7CrRu3JBa2mY+moTV/pMrjvwAInmSxs4RBO7ggdYEief/4cBYyzMdiQ1v0UxvdO | ||
674dBJJFG32akPrnPqza7U41ivoDPlgCpKWHDaZadI0Joozd2pw0Mq0a8cyig0BJ | ||
Wa3d9xkCgYEA9T3j8F52u+QMaMzV1VENUAwo0Sqhk8xU0r/4l5PsvCjOuJ7NZkkW | ||
EQnNOI++zaPCeBRV55X0A5E8Pi3uEdKt6m+wsncJzGEVNRwixfd0Ul7Itntq7u9L | ||
/DHTlwpQ4t4PLNu8/uSBDN9A2slY2WsoXkJsdYPgjkrS2rYkt5bHFN8CgYEAw+8w | ||
Qw/zTCBmerzYLJSsjz9rcD2hTtDw72UF1rvEg4QP/9v0I/OU7Lu0ds0KmKJcJfay | ||
ZDMeBT8tW6LFztqdFi24tKISfodfYdET32lNd4QnMtWhoqXXXNiJY5gQC16YmSJm | ||
R7Dgw9hBrr0323/lhhwDDysq1lgD9QbUVEacJpsCgYAoau/TIK5u3vHQn9mqE3af | ||
N7HObzk785QTO8JLsPx2Mj+Hm9x8PBVf736cEMzAdXnKcoeJ6GPT5q7IDKfM1i0F | ||
kyzK7OV3gpSNMTrl55eLL8XilUqVYGjkgo29udyE11Ym7XwjgiNmrLCynjZ/drKr | ||
fkUDxR1QNjK0CwrYGwhqfwKBgQDAYGn3foK4nRthqWdrJjLjlzZLBwgJldbqhjsc | ||
YlIJezImWnU0k2YGpioDd0DPKqLlV3pCLXptVmGXlpM3jags7YlsObGE8C+zoBAu | ||
DHtWPLgsDltckg6Jh8YltlkSgLe9q2vXOhEF2aBsDDb62nGmonxSeWTe/Z4tB56U | ||
fJu2vwKBgFnGbZIcH8sDR7Vwh0sjSKnFkZ1v0T4qsBKpDz9yCvZVIgIFXPkKnALT | ||
+OEpQTuLVN/MZxVlc8qo8UFflJprDsK1/Rm3iPaw+lwErswgddNUKNLnLPjlxcEe | ||
nTinsfyf4i48+IW55UFVU118nyufNeDdasoU6SSBH/MdeNq4hrTa | ||
-----END RSA PRIVATE KEY----- |
Oops, something went wrong.