parent
481e98f2c9
commit
bc0edf9e0f
@ -0,0 +1,30 @@
|
||||
diff --git a/providers/implementations/ciphers/cipher_aes_siv.c b/providers/implementations/ciphers/cipher_aes_siv.c
|
||||
index 45010b90db..b396c8651a 100644
|
||||
--- a/providers/implementations/ciphers/cipher_aes_siv.c
|
||||
+++ b/providers/implementations/ciphers/cipher_aes_siv.c
|
||||
@@ -120,14 +120,18 @@ static int siv_cipher(void *vctx, unsigned char *out, size_t *outl,
|
||||
if (!ossl_prov_is_running())
|
||||
return 0;
|
||||
|
||||
- if (inl == 0) {
|
||||
- *outl = 0;
|
||||
- return 1;
|
||||
- }
|
||||
+ /* Ignore just empty encryption/decryption call and not AAD. */
|
||||
+ if (out != NULL) {
|
||||
+ if (inl == 0) {
|
||||
+ if (outl != NULL)
|
||||
+ *outl = 0;
|
||||
+ return 1;
|
||||
+ }
|
||||
|
||||
- if (outsize < inl) {
|
||||
- ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
|
||||
- return 0;
|
||||
+ if (outsize < inl) {
|
||||
+ ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
|
||||
+ return 0;
|
||||
+ }
|
||||
}
|
||||
|
||||
if (ctx->hw->cipher(ctx, out, in, inl) <= 0)
|
@ -0,0 +1,74 @@
|
||||
diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c
|
||||
index 0b391910d6..84a926998e 100644
|
||||
--- a/crypto/dh/dh_check.c
|
||||
+++ b/crypto/dh/dh_check.c
|
||||
@@ -152,6 +152,12 @@ int DH_check(const DH *dh, int *ret)
|
||||
if (nid != NID_undef)
|
||||
return 1;
|
||||
|
||||
+ /* Don't do any checks at all with an excessively large modulus */
|
||||
+ if (BN_num_bits(dh->params.p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) {
|
||||
+ ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
if (!DH_check_params(dh, ret))
|
||||
return 0;
|
||||
|
||||
diff --git a/include/openssl/dh.h b/include/openssl/dh.h
|
||||
index b97871eca7..36420f51d8 100644
|
||||
--- a/include/openssl/dh.h
|
||||
+++ b/include/openssl/dh.h
|
||||
@@ -89,7 +89,11 @@ int EVP_PKEY_CTX_get0_dh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);
|
||||
# include <openssl/dherr.h>
|
||||
|
||||
# ifndef OPENSSL_DH_MAX_MODULUS_BITS
|
||||
-# define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
+# define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
+# endif
|
||||
+
|
||||
+# ifndef OPENSSL_DH_CHECK_MAX_MODULUS_BITS
|
||||
+# define OPENSSL_DH_CHECK_MAX_MODULUS_BITS 32768
|
||||
# endif
|
||||
|
||||
# define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024
|
||||
diff --git a/test/dhtest.c b/test/dhtest.c
|
||||
index 7b587f3cfa..f8dd8f3aa7 100644
|
||||
--- a/test/dhtest.c
|
||||
+++ b/test/dhtest.c
|
||||
@@ -73,7 +73,7 @@ static int dh_test(void)
|
||||
goto err1;
|
||||
|
||||
/* check fails, because p is way too small */
|
||||
- if (!DH_check(dh, &i))
|
||||
+ if (!TEST_true(DH_check(dh, &i)))
|
||||
goto err2;
|
||||
i ^= DH_MODULUS_TOO_SMALL;
|
||||
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
|
||||
@@ -124,6 +124,17 @@ static int dh_test(void)
|
||||
/* We'll have a stale error on the queue from the above test so clear it */
|
||||
ERR_clear_error();
|
||||
|
||||
+ /* Modulus of size: dh check max modulus bits + 1 */
|
||||
+ if (!TEST_true(BN_set_word(p, 1))
|
||||
+ || !TEST_true(BN_lshift(p, p, OPENSSL_DH_CHECK_MAX_MODULUS_BITS)))
|
||||
+ goto err3;
|
||||
+
|
||||
+ /*
|
||||
+ * We expect no checks at all for an excessively large modulus
|
||||
+ */
|
||||
+ if (!TEST_false(DH_check(dh, &i)))
|
||||
+ goto err3;
|
||||
+
|
||||
/*
|
||||
* II) key generation
|
||||
*/
|
||||
@@ -138,7 +149,7 @@ static int dh_test(void)
|
||||
goto err3;
|
||||
|
||||
/* ... and check whether it is valid */
|
||||
- if (!DH_check(a, &i))
|
||||
+ if (!TEST_true(DH_check(a, &i)))
|
||||
goto err3;
|
||||
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
|
||||
|| !TEST_false(i & DH_CHECK_P_NOT_SAFE_PRIME)
|
@ -0,0 +1,57 @@
|
||||
diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c
|
||||
index aef6f9b1b7..fbe2797569 100644
|
||||
--- a/crypto/dh/dh_check.c
|
||||
+++ b/crypto/dh/dh_check.c
|
||||
@@ -143,7 +143,7 @@ int DH_check(const DH *dh, int *ret)
|
||||
#ifdef FIPS_MODULE
|
||||
return DH_check_params(dh, ret);
|
||||
#else
|
||||
- int ok = 0, r;
|
||||
+ int ok = 0, r, q_good = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *t1 = NULL, *t2 = NULL;
|
||||
int nid = DH_get_nid((DH *)dh);
|
||||
@@ -172,6 +172,13 @@ int DH_check(const DH *dh, int *ret)
|
||||
goto err;
|
||||
|
||||
if (dh->params.q != NULL) {
|
||||
+ if (BN_ucmp(dh->params.p, dh->params.q) > 0)
|
||||
+ q_good = 1;
|
||||
+ else
|
||||
+ *ret |= DH_CHECK_INVALID_Q_VALUE;
|
||||
+ }
|
||||
+
|
||||
+ if (q_good) {
|
||||
if (BN_cmp(dh->params.g, BN_value_one()) <= 0)
|
||||
*ret |= DH_NOT_SUITABLE_GENERATOR;
|
||||
else if (BN_cmp(dh->params.g, dh->params.p) >= 0)
|
||||
diff --git a/test/dhtest.c b/test/dhtest.c
|
||||
index f8dd8f3aa7..d02b3b7c58 100644
|
||||
--- a/test/dhtest.c
|
||||
+++ b/test/dhtest.c
|
||||
@@ -124,6 +124,15 @@ static int dh_test(void)
|
||||
/* We'll have a stale error on the queue from the above test so clear it */
|
||||
ERR_clear_error();
|
||||
|
||||
+ if (!TEST_ptr(BN_copy(q, p)) || !TEST_true(BN_add(q, q, BN_value_one())))
|
||||
+ goto err3;
|
||||
+
|
||||
+ if (!TEST_true(DH_check(dh, &i)))
|
||||
+ goto err3;
|
||||
+ if (!TEST_true(i & DH_CHECK_INVALID_Q_VALUE)
|
||||
+ || !TEST_false(i & DH_CHECK_Q_NOT_PRIME))
|
||||
+ goto err3;
|
||||
+
|
||||
/* Modulus of size: dh check max modulus bits + 1 */
|
||||
if (!TEST_true(BN_set_word(p, 1))
|
||||
|| !TEST_true(BN_lshift(p, p, OPENSSL_DH_CHECK_MAX_MODULUS_BITS)))
|
||||
@@ -135,6 +144,9 @@ static int dh_test(void)
|
||||
if (!TEST_false(DH_check(dh, &i)))
|
||||
goto err3;
|
||||
|
||||
+ /* We'll have a stale error on the queue from the above test so clear it */
|
||||
+ ERR_clear_error();
|
||||
+
|
||||
/*
|
||||
* II) key generation
|
||||
*/
|
@ -0,0 +1,143 @@
|
||||
diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c
|
||||
index 7ba2beae7f..e20eb62081 100644
|
||||
--- a/crypto/dh/dh_check.c
|
||||
+++ b/crypto/dh/dh_check.c
|
||||
@@ -249,6 +249,18 @@ int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key)
|
||||
*/
|
||||
int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
|
||||
{
|
||||
+ /* Don't do any checks at all with an excessively large modulus */
|
||||
+ if (BN_num_bits(dh->params.p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) {
|
||||
+ ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE);
|
||||
+ *ret = DH_MODULUS_TOO_LARGE | DH_CHECK_PUBKEY_INVALID;
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (dh->params.q != NULL && BN_ucmp(dh->params.p, dh->params.q) < 0) {
|
||||
+ *ret |= DH_CHECK_INVALID_Q_VALUE | DH_CHECK_PUBKEY_INVALID;
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
return ossl_ffc_validate_public_key(&dh->params, pub_key, ret);
|
||||
}
|
||||
|
||||
diff --git a/crypto/dh/dh_err.c b/crypto/dh/dh_err.c
|
||||
index 4152397426..f76ac0dd14 100644
|
||||
--- a/crypto/dh/dh_err.c
|
||||
+++ b/crypto/dh/dh_err.c
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
- * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -54,6 +54,7 @@ static const ERR_STRING_DATA DH_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_DH, 0, DH_R_PARAMETER_ENCODING_ERROR),
|
||||
"parameter encoding error"},
|
||||
{ERR_PACK(ERR_LIB_DH, 0, DH_R_PEER_KEY_ERROR), "peer key error"},
|
||||
+ {ERR_PACK(ERR_LIB_DH, 0, DH_R_Q_TOO_LARGE), "q too large"},
|
||||
{ERR_PACK(ERR_LIB_DH, 0, DH_R_SHARED_INFO_ERROR), "shared info error"},
|
||||
{ERR_PACK(ERR_LIB_DH, 0, DH_R_UNABLE_TO_CHECK_GENERATOR),
|
||||
"unable to check generator"},
|
||||
diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c
|
||||
index d84ea99241..afc49f5cdc 100644
|
||||
--- a/crypto/dh/dh_key.c
|
||||
+++ b/crypto/dh/dh_key.c
|
||||
@@ -49,6 +49,12 @@ int ossl_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
|
||||
goto err;
|
||||
}
|
||||
|
||||
+ if (dh->params.q != NULL
|
||||
+ && BN_num_bits(dh->params.q) > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
+ ERR_raise(ERR_LIB_DH, DH_R_Q_TOO_LARGE);
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) {
|
||||
ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL);
|
||||
return 0;
|
||||
@@ -267,6 +273,12 @@ static int generate_key(DH *dh)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+ if (dh->params.q != NULL
|
||||
+ && BN_num_bits(dh->params.q) > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
+ ERR_raise(ERR_LIB_DH, DH_R_Q_TOO_LARGE);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) {
|
||||
ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL);
|
||||
return 0;
|
||||
diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt
|
||||
index e51504b7ab..36de321b74 100644
|
||||
--- a/crypto/err/openssl.txt
|
||||
+++ b/crypto/err/openssl.txt
|
||||
@@ -500,6 +500,7 @@ DH_R_NO_PARAMETERS_SET:107:no parameters set
|
||||
DH_R_NO_PRIVATE_VALUE:100:no private value
|
||||
DH_R_PARAMETER_ENCODING_ERROR:105:parameter encoding error
|
||||
DH_R_PEER_KEY_ERROR:111:peer key error
|
||||
+DH_R_Q_TOO_LARGE:130:q too large
|
||||
DH_R_SHARED_INFO_ERROR:113:shared info error
|
||||
DH_R_UNABLE_TO_CHECK_GENERATOR:121:unable to check generator
|
||||
DSA_R_BAD_FFC_PARAMETERS:114:bad ffc parameters
|
||||
diff --git a/include/crypto/dherr.h b/include/crypto/dherr.h
|
||||
index bb24d131eb..519327f795 100644
|
||||
--- a/include/crypto/dherr.h
|
||||
+++ b/include/crypto/dherr.h
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
- * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
diff --git a/include/openssl/dh.h b/include/openssl/dh.h
|
||||
index 6533260f20..50e0cf54be 100644
|
||||
--- a/include/openssl/dh.h
|
||||
+++ b/include/openssl/dh.h
|
||||
@@ -141,7 +141,7 @@ DECLARE_ASN1_ITEM(DHparams)
|
||||
# define DH_GENERATOR_3 3
|
||||
# define DH_GENERATOR_5 5
|
||||
|
||||
-/* DH_check error codes */
|
||||
+/* DH_check error codes, some of them shared with DH_check_pub_key */
|
||||
/*
|
||||
* NB: These values must align with the equivalently named macros in
|
||||
* internal/ffc.h.
|
||||
@@ -151,10 +151,10 @@ DECLARE_ASN1_ITEM(DHparams)
|
||||
# define DH_UNABLE_TO_CHECK_GENERATOR 0x04
|
||||
# define DH_NOT_SUITABLE_GENERATOR 0x08
|
||||
# define DH_CHECK_Q_NOT_PRIME 0x10
|
||||
-# define DH_CHECK_INVALID_Q_VALUE 0x20
|
||||
+# define DH_CHECK_INVALID_Q_VALUE 0x20 /* +DH_check_pub_key */
|
||||
# define DH_CHECK_INVALID_J_VALUE 0x40
|
||||
# define DH_MODULUS_TOO_SMALL 0x80
|
||||
-# define DH_MODULUS_TOO_LARGE 0x100
|
||||
+# define DH_MODULUS_TOO_LARGE 0x100 /* +DH_check_pub_key */
|
||||
|
||||
/* DH_check_pub_key error codes */
|
||||
# define DH_CHECK_PUBKEY_TOO_SMALL 0x01
|
||||
diff --git a/include/openssl/dherr.h b/include/openssl/dherr.h
|
||||
index 5d2a762a96..074a70145f 100644
|
||||
--- a/include/openssl/dherr.h
|
||||
+++ b/include/openssl/dherr.h
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
- * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -50,6 +50,7 @@
|
||||
# define DH_R_NO_PRIVATE_VALUE 100
|
||||
# define DH_R_PARAMETER_ENCODING_ERROR 105
|
||||
# define DH_R_PEER_KEY_ERROR 111
|
||||
+# define DH_R_Q_TOO_LARGE 130
|
||||
# define DH_R_SHARED_INFO_ERROR 113
|
||||
# define DH_R_UNABLE_TO_CHECK_GENERATOR 121
|
||||
|
@ -0,0 +1,12 @@
|
||||
diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c
|
||||
index 51c2283db915d..0928a30c2d37b 100644
|
||||
--- a/ssl/t1_lib.c
|
||||
+++ b/ssl/t1_lib.c
|
||||
@@ -765,6 +765,7 @@ int tls1_set_groups_list(SSL_CTX *ctx, uint16_t **pext, size_t *pextlen,
|
||||
tmparr = OPENSSL_memdup(gcb.gid_arr, gcb.gidcnt * sizeof(*tmparr));
|
||||
if (tmparr == NULL)
|
||||
goto end;
|
||||
+ OPENSSL_free(*pext);
|
||||
*pext = tmparr;
|
||||
*pextlen = gcb.gidcnt;
|
||||
ret = 1;
|
@ -0,0 +1,86 @@
|
||||
diff --git a/crypto/poly1305/asm/poly1305-ppc.pl b/crypto/poly1305/asm/poly1305-ppc.pl
|
||||
index 9f86134d923fb..2e601bb9c24be 100755
|
||||
--- a/crypto/poly1305/asm/poly1305-ppc.pl
|
||||
+++ b/crypto/poly1305/asm/poly1305-ppc.pl
|
||||
@@ -744,7 +744,7 @@
|
||||
my $LOCALS= 6*$SIZE_T;
|
||||
my $VSXFRAME = $LOCALS + 6*$SIZE_T;
|
||||
$VSXFRAME += 128; # local variables
|
||||
- $VSXFRAME += 13*16; # v20-v31 offload
|
||||
+ $VSXFRAME += 12*16; # v20-v31 offload
|
||||
|
||||
my $BIG_ENDIAN = ($flavour !~ /le/) ? 4 : 0;
|
||||
|
||||
@@ -919,12 +919,12 @@
|
||||
addi r11,r11,32
|
||||
stvx v22,r10,$sp
|
||||
addi r10,r10,32
|
||||
- stvx v23,r10,$sp
|
||||
- addi r10,r10,32
|
||||
- stvx v24,r11,$sp
|
||||
+ stvx v23,r11,$sp
|
||||
addi r11,r11,32
|
||||
- stvx v25,r10,$sp
|
||||
+ stvx v24,r10,$sp
|
||||
addi r10,r10,32
|
||||
+ stvx v25,r11,$sp
|
||||
+ addi r11,r11,32
|
||||
stvx v26,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v27,r11,$sp
|
||||
@@ -1153,12 +1153,12 @@
|
||||
addi r11,r11,32
|
||||
stvx v22,r10,$sp
|
||||
addi r10,r10,32
|
||||
- stvx v23,r10,$sp
|
||||
- addi r10,r10,32
|
||||
- stvx v24,r11,$sp
|
||||
+ stvx v23,r11,$sp
|
||||
addi r11,r11,32
|
||||
- stvx v25,r10,$sp
|
||||
+ stvx v24,r10,$sp
|
||||
addi r10,r10,32
|
||||
+ stvx v25,r11,$sp
|
||||
+ addi r11,r11,32
|
||||
stvx v26,r10,$sp
|
||||
addi r10,r10,32
|
||||
stvx v27,r11,$sp
|
||||
@@ -1899,26 +1899,26 @@
|
||||
mtspr 256,r12 # restore vrsave
|
||||
lvx v20,r10,$sp
|
||||
addi r10,r10,32
|
||||
- lvx v21,r10,$sp
|
||||
- addi r10,r10,32
|
||||
- lvx v22,r11,$sp
|
||||
+ lvx v21,r11,$sp
|
||||
addi r11,r11,32
|
||||
- lvx v23,r10,$sp
|
||||
+ lvx v22,r10,$sp
|
||||
addi r10,r10,32
|
||||
- lvx v24,r11,$sp
|
||||
+ lvx v23,r11,$sp
|
||||
addi r11,r11,32
|
||||
- lvx v25,r10,$sp
|
||||
+ lvx v24,r10,$sp
|
||||
addi r10,r10,32
|
||||
- lvx v26,r11,$sp
|
||||
+ lvx v25,r11,$sp
|
||||
addi r11,r11,32
|
||||
- lvx v27,r10,$sp
|
||||
+ lvx v26,r10,$sp
|
||||
addi r10,r10,32
|
||||
- lvx v28,r11,$sp
|
||||
+ lvx v27,r11,$sp
|
||||
addi r11,r11,32
|
||||
- lvx v29,r10,$sp
|
||||
+ lvx v28,r10,$sp
|
||||
addi r10,r10,32
|
||||
- lvx v30,r11,$sp
|
||||
- lvx v31,r10,$sp
|
||||
+ lvx v29,r11,$sp
|
||||
+ addi r11,r11,32
|
||||
+ lvx v30,r10,$sp
|
||||
+ lvx v31,r11,$sp
|
||||
$POP r27,`$VSXFRAME-$SIZE_T*5`($sp)
|
||||
$POP r28,`$VSXFRAME-$SIZE_T*4`($sp)
|
||||
$POP r29,`$VSXFRAME-$SIZE_T*3`($sp)
|
@ -0,0 +1,93 @@
|
||||
diff --git a/crypto/rsa/rsa_sp800_56b_check.c b/crypto/rsa/rsa_sp800_56b_check.c
|
||||
index fc8f19b48770b..bcbdd24fb8199 100644
|
||||
--- a/crypto/rsa/rsa_sp800_56b_check.c
|
||||
+++ b/crypto/rsa/rsa_sp800_56b_check.c
|
||||
@@ -289,6 +289,11 @@ int ossl_rsa_sp800_56b_check_public(const RSA *rsa)
|
||||
return 0;
|
||||
|
||||
nbits = BN_num_bits(rsa->n);
|
||||
+ if (nbits > OPENSSL_RSA_MAX_MODULUS_BITS) {
|
||||
+ ERR_raise(ERR_LIB_RSA, RSA_R_MODULUS_TOO_LARGE);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
#ifdef FIPS_MODULE
|
||||
/*
|
||||
* (Step a): modulus must be 2048 or 3072 (caveat from SP800-56Br1)
|
||||
@@ -324,7 +329,8 @@ int ossl_rsa_sp800_56b_check_public(const RSA *rsa)
|
||||
goto err;
|
||||
}
|
||||
|
||||
- ret = ossl_bn_miller_rabin_is_prime(rsa->n, 0, ctx, NULL, 1, &status);
|
||||
+ /* Highest number of MR rounds from FIPS 186-5 Section B.3 Table B.1 */
|
||||
+ ret = ossl_bn_miller_rabin_is_prime(rsa->n, 5, ctx, NULL, 1, &status);
|
||||
#ifdef FIPS_MODULE
|
||||
if (ret != 1 || status != BN_PRIMETEST_COMPOSITE_NOT_POWER_OF_PRIME) {
|
||||
#else
|
||||
diff --git a/test/recipes/91-test_pkey_check.t b/test/recipes/91-test_pkey_check.t
|
||||
index dc7cc64533af2..f8088df14d36c 100644
|
||||
--- a/test/recipes/91-test_pkey_check.t
|
||||
+++ b/test/recipes/91-test_pkey_check.t
|
||||
@@ -70,7 +70,7 @@ push(@positive_tests, (
|
||||
"dhpkey.pem"
|
||||
)) unless disabled("dh");
|
||||
|
||||
-my @negative_pubtests = ();
|
||||
+my @negative_pubtests = ("rsapub_17k.pem"); # Too big RSA public key
|
||||
|
||||
push(@negative_pubtests, (
|
||||
"dsapub_noparam.der"
|
||||
diff --git a/test/recipes/91-test_pkey_check_data/rsapub_17k.pem b/test/recipes/91-test_pkey_check_data/rsapub_17k.pem
|
||||
new file mode 100644
|
||||
index 0000000000000..9a2eaedaf1b22
|
||||
--- /dev/null
|
||||
+++ b/test/recipes/91-test_pkey_check_data/rsapub_17k.pem
|
||||
@@ -0,0 +1,48 @@
|
||||
+-----BEGIN PUBLIC KEY-----
|
||||
+MIIIbzANBgkqhkiG9w0BAQEFAAOCCFwAMIIIVwKCCE4Ang+cE5H+hg3RbapDAHqR
|
||||
+B9lUnp2MlAwsZxQ/FhYepaR60bFQeumbu7817Eo5YLMObVI99hF1C4u/qcpD4Jph
|
||||
+gZt87/JAYDbP+DIh/5gUXCL9m5Fp4u7mvZaZdnlcftBvR1uKUTCAwc9pZ/Cfr8W2
|
||||
+GzrRODzsNYnk2DcZMfe2vRDuDZRopE+Y+I72rom2SZLxoN547N1daM/M/CL9KVQ/
|
||||
+XMI/YOpJrBI0jI3brMRhLkvLckwies9joufydlGbJkeil9H7/grj3fQZtFkZ2Pk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+gV36gxTsbOSfhpO1OXR90ODy0kx06XzWmJCUugK8u9bx4F/CjV+LIHExuNJiethC
|
||||
+A8sIup/MT0fWp4RO/SsVblGqfoqJTaPnhptQzeH2N07pbWkxeMuL6ppPuwFmfVjK
|
||||
+FJndqCVrAukcPEOQ16iVURuloJMudqYRc9QKkJFsnv0W/iMNbqQGmXe8Q/5qFiys
|
||||
+26NIQBiE2ad9hNLnoccEnmYSRgnW3ZPSKuq5TDdYyDqTZH2r8cam65pr3beKw2XC
|
||||
+xw4cc7VaxiwGC2Mg2wRmwwPaTjrcEt6sMa3RjwFEVBxBFyM26wnTEZsTBquCxV0J
|
||||
+pgERaeplkixP2Q0m7XAdlDaob973SM2vOoUgypzDchWmpx7u775bnOfU5CihwXl+
|
||||
+k0i09WZuT8bPmhEAiGCw5sNzMkz1BC2cCZFfJIkE2vc/wXYOrGxBTJo0EKaUFswa
|
||||
+2dnP/u0bn+VksBUM7ywW9LJSXh4mN+tpzdeJtxEObKwX1I0dQxSPWmjd2++wMr9q
|
||||
+Unre5fCrDToy2H7C2VKSpuOCT2/Kv4JDQRWwI4KxQOpn0UknAGNmfBoTtpIZ3LEb
|
||||
+77oBUJdMQD7tQBBLL0a6f1TdK0dHVprWWawJ+gGFMiMQXqAqblHcxFKWuHv9bQID
|
||||
+AQAB
|
||||
+-----END PUBLIC KEY-----
|
@ -0,0 +1,47 @@
|
||||
diff --git a/crypto/evp/ctrl_params_translate.c b/crypto/evp/ctrl_params_translate.c
|
||||
index 448a3c3043c1c..9010fa6c4638c 100644
|
||||
--- a/crypto/evp/ctrl_params_translate.c
|
||||
+++ b/crypto/evp/ctrl_params_translate.c
|
||||
@@ -1134,6 +1134,7 @@ static int fix_ec_paramgen_curve_nid(enum state state,
|
||||
const struct translation_st *translation,
|
||||
struct translation_ctx_st *ctx)
|
||||
{
|
||||
+ char *p2 = NULL;
|
||||
int ret;
|
||||
|
||||
if ((ret = default_check(state, translation, ctx)) <= 0)
|
||||
@@ -1146,13 +1147,25 @@ static int fix_ec_paramgen_curve_nid(enum state state,
|
||||
if (state == PRE_CTRL_TO_PARAMS) {
|
||||
ctx->p2 = (char *)OBJ_nid2sn(ctx->p1);
|
||||
ctx->p1 = 0;
|
||||
+ } else if (state == PRE_PARAMS_TO_CTRL) {
|
||||
+ /*
|
||||
+ * We're translating from params to ctrl and setting the curve name.
|
||||
+ * The ctrl function needs it to be a NID, but meanwhile, we need
|
||||
+ * space to get the curve name from the param. |ctx->name_buf| is
|
||||
+ * sufficient for that.
|
||||
+ * The double indirection is necessary for default_fixup_args()'s
|
||||
+ * call of OSSL_PARAM_get_utf8_string() to be done correctly.
|
||||
+ */
|
||||
+ p2 = ctx->name_buf;
|
||||
+ ctx->p2 = &p2;
|
||||
+ ctx->sz = sizeof(ctx->name_buf);
|
||||
}
|
||||
|
||||
if ((ret = default_fixup_args(state, translation, ctx)) <= 0)
|
||||
return ret;
|
||||
|
||||
if (state == PRE_PARAMS_TO_CTRL) {
|
||||
- ctx->p1 = OBJ_sn2nid(ctx->p2);
|
||||
+ ctx->p1 = OBJ_sn2nid(p2);
|
||||
ctx->p2 = NULL;
|
||||
}
|
||||
|
||||
@@ -2789,6 +2802,7 @@ static int evp_pkey_ctx_setget_params_to_ctrl(EVP_PKEY_CTX *pctx,
|
||||
if (translation->fixup_args != NULL)
|
||||
fixup = translation->fixup_args;
|
||||
ctx.action_type = translation->action_type;
|
||||
+ ctx.ctrl_cmd = translation->ctrl_num;
|
||||
}
|
||||
ctx.pctx = pctx;
|
||||
ctx.params = params;
|
@ -0,0 +1,178 @@
|
||||
diff --git a/crypto/pkcs12/p12_add.c b/crypto/pkcs12/p12_add.c
|
||||
index 6fd4184af5a52..80ce31b3bca66 100644
|
||||
--- a/crypto/pkcs12/p12_add.c
|
||||
+++ b/crypto/pkcs12/p12_add.c
|
||||
@@ -78,6 +78,12 @@ STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7)
|
||||
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_CONTENT_TYPE_NOT_DATA);
|
||||
return NULL;
|
||||
}
|
||||
+
|
||||
+ if (p7->d.data == NULL) {
|
||||
+ ERR_raise(ERR_LIB_PKCS12, PKCS12_R_DECODE_ERROR);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
return ASN1_item_unpack(p7->d.data, ASN1_ITEM_rptr(PKCS12_SAFEBAGS));
|
||||
}
|
||||
|
||||
@@ -150,6 +156,12 @@ STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass,
|
||||
{
|
||||
if (!PKCS7_type_is_encrypted(p7))
|
||||
return NULL;
|
||||
+
|
||||
+ if (p7->d.encrypted == NULL) {
|
||||
+ ERR_raise(ERR_LIB_PKCS12, PKCS12_R_DECODE_ERROR);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
return PKCS12_item_decrypt_d2i_ex(p7->d.encrypted->enc_data->algorithm,
|
||||
ASN1_ITEM_rptr(PKCS12_SAFEBAGS),
|
||||
pass, passlen,
|
||||
@@ -188,6 +200,12 @@ STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12)
|
||||
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_CONTENT_TYPE_NOT_DATA);
|
||||
return NULL;
|
||||
}
|
||||
+
|
||||
+ if (p12->authsafes->d.data == NULL) {
|
||||
+ ERR_raise(ERR_LIB_PKCS12, PKCS12_R_DECODE_ERROR);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
p7s = ASN1_item_unpack(p12->authsafes->d.data,
|
||||
ASN1_ITEM_rptr(PKCS12_AUTHSAFES));
|
||||
if (p7s != NULL) {
|
||||
diff --git a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c
|
||||
index 67a885a45f89e..68ff54d0e90ee 100644
|
||||
--- a/crypto/pkcs12/p12_mutl.c
|
||||
+++ b/crypto/pkcs12/p12_mutl.c
|
||||
@@ -98,6 +98,11 @@ static int pkcs12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
+ if (p12->authsafes->d.data == NULL) {
|
||||
+ ERR_raise(ERR_LIB_PKCS12, PKCS12_R_DECODE_ERROR);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
salt = p12->mac->salt->data;
|
||||
saltlen = p12->mac->salt->length;
|
||||
if (p12->mac->iter == NULL)
|
||||
diff --git a/crypto/pkcs12/p12_npas.c b/crypto/pkcs12/p12_npas.c
|
||||
index 62230bc6187ff..1e5b5495991a4 100644
|
||||
--- a/crypto/pkcs12/p12_npas.c
|
||||
+++ b/crypto/pkcs12/p12_npas.c
|
||||
@@ -77,8 +77,9 @@ static int newpass_p12(PKCS12 *p12, const char *oldpass, const char *newpass)
|
||||
bags = PKCS12_unpack_p7data(p7);
|
||||
} else if (bagnid == NID_pkcs7_encrypted) {
|
||||
bags = PKCS12_unpack_p7encdata(p7, oldpass, -1);
|
||||
- if (!alg_get(p7->d.encrypted->enc_data->algorithm,
|
||||
- &pbe_nid, &pbe_iter, &pbe_saltlen))
|
||||
+ if (p7->d.encrypted == NULL
|
||||
+ || !alg_get(p7->d.encrypted->enc_data->algorithm,
|
||||
+ &pbe_nid, &pbe_iter, &pbe_saltlen))
|
||||
goto err;
|
||||
} else {
|
||||
continue;
|
||||
diff --git a/crypto/pkcs7/pk7_mime.c b/crypto/pkcs7/pk7_mime.c
|
||||
index 49a0da5f819c4..8228315eeaa3a 100644
|
||||
--- a/crypto/pkcs7/pk7_mime.c
|
||||
+++ b/crypto/pkcs7/pk7_mime.c
|
||||
@@ -33,10 +33,13 @@ int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
|
||||
int ctype_nid = OBJ_obj2nid(p7->type);
|
||||
const PKCS7_CTX *ctx = ossl_pkcs7_get0_ctx(p7);
|
||||
|
||||
- if (ctype_nid == NID_pkcs7_signed)
|
||||
+ if (ctype_nid == NID_pkcs7_signed) {
|
||||
+ if (p7->d.sign == NULL)
|
||||
+ return 0;
|
||||
mdalgs = p7->d.sign->md_algs;
|
||||
- else
|
||||
+ } else {
|
||||
mdalgs = NULL;
|
||||
+ }
|
||||
|
||||
flags ^= SMIME_OLDMIME;
|
||||
|
||||
diff --git a/test/recipes/80-test_pkcs12.t b/test/recipes/80-test_pkcs12.t
|
||||
index 1f0cb4d501488..b2c376249646d 100644
|
||||
--- a/test/recipes/80-test_pkcs12.t
|
||||
+++ b/test/recipes/80-test_pkcs12.t
|
||||
@@ -9,7 +9,7 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
-use OpenSSL::Test qw/:DEFAULT srctop_file/;
|
||||
+use OpenSSL::Test qw/:DEFAULT srctop_file with/;
|
||||
use OpenSSL::Test::Utils;
|
||||
|
||||
use Encode;
|
||||
@@ -54,7 +54,7 @@ if (eval { require Win32::API; 1; }) {
|
||||
}
|
||||
$ENV{OPENSSL_WIN32_UTF8}=1;
|
||||
|
||||
-plan tests => 13;
|
||||
+plan tests => 17;
|
||||
|
||||
# Test different PKCS#12 formats
|
||||
ok(run(test(["pkcs12_format_test"])), "test pkcs12 formats");
|
||||
@@ -148,4 +148,25 @@ ok(grep(/subject=CN = server.example/, @pkcs12info) == 1,
|
||||
# Test that the expected friendly name is present in the output
|
||||
ok(grep(/testname/, @pkcs12info) == 1, "test friendly name in output");
|
||||
|
||||
+# Test some bad pkcs12 files
|
||||
+my $bad1 = srctop_file("test", "recipes", "80-test_pkcs12_data", "bad1.p12");
|
||||
+my $bad2 = srctop_file("test", "recipes", "80-test_pkcs12_data", "bad2.p12");
|
||||
+my $bad3 = srctop_file("test", "recipes", "80-test_pkcs12_data", "bad3.p12");
|
||||
+
|
||||
+with({ exit_checker => sub { return shift == 1; } },
|
||||
+ sub {
|
||||
+ ok(run(app(["openssl", "pkcs12", "-in", $bad1, "-password", "pass:"])),
|
||||
+ "test bad pkcs12 file 1");
|
||||
+
|
||||
+ ok(run(app(["openssl", "pkcs12", "-in", $bad1, "-password", "pass:",
|
||||
+ "-nomacver"])),
|
||||
+ "test bad pkcs12 file 1 (nomacver)");
|
||||
+
|
||||
+ ok(run(app(["openssl", "pkcs12", "-in", $bad2, "-password", "pass:"])),
|
||||
+ "test bad pkcs12 file 2");
|
||||
+
|
||||
+ ok(run(app(["openssl", "pkcs12", "-in", $bad3, "-password", "pass:"])),
|
||||
+ "test bad pkcs12 file 3");
|
||||
+ });
|
||||
+
|
||||
SetConsoleOutputCP($savedcp) if (defined($savedcp));
|
||||
diff --git a/test/recipes/80-test_pkcs12_data/bad1.p12 b/test/recipes/80-test_pkcs12_data/bad1.p12
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..8f3387c7e356e4aa374729f3f3939343557b9c09
|
||||
GIT binary patch
|
||||
literal 85
|
||||
zcmV-b0IL5mQvv}4Fbf6=Duzgg_YDCD0Wd)@F)$4V31Egu0c8UO0s#d81R(r{)waiY
|
||||
rfR=Py6XX<mRyon58xHv)BAVy}k(l(hJwF5pk-=q7<yb@T0s;sC$etR(
|
||||
|
||||
literal 0
|
||||
HcmV?d00001
|
||||
|
||||
diff --git a/test/recipes/80-test_pkcs12_data/bad2.p12 b/test/recipes/80-test_pkcs12_data/bad2.p12
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..113cb6f1cd523e880db869f518e60142dc875115
|
||||
GIT binary patch
|
||||
literal 104
|
||||
zcmXp=V`5}BkYnT2YV&CO&dbQoxImDF-+<SE8zIDI;AmiIz{|#&(B{FI%FM#V$jZQ?
|
||||
z@Tpc|>#<$m7-wj)xrauuD`}hF=<J_T`^8$QMBK7d>Ng9=0`~S~)@=J%OiUaM0Oze6
|
||||
AD*ylh
|
||||
|
||||
literal 0
|
||||
HcmV?d00001
|
||||
|
||||
diff --git a/test/recipes/80-test_pkcs12_data/bad3.p12 b/test/recipes/80-test_pkcs12_data/bad3.p12
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..ef86a1d86fb0bc09471ca2596d82e7d521d973a4
|
||||
GIT binary patch
|
||||
literal 104
|
||||
zcmXp=V`5}BkYnT2YV&CO&dbQoxImDF-+<SE8%fB((ZJAvmyI)_&4V$OnT3gwm4QWp
|
||||
zJ2GXlSm>oA$5$MVJL*60=F*5iN*C_e&wD%dwCM*q{=+OBX|Z+F7XSHN#>B+I003La
|
||||
BAqM~e
|
||||
|
||||
literal 0
|
||||
HcmV?d00001
|
||||
|
@ -0,0 +1,233 @@
|
||||
diff --git a/crypto/x509/v3_utl.c b/crypto/x509/v3_utl.c
|
||||
index 1a18174995..a09414c972 100644
|
||||
--- a/crypto/x509/v3_utl.c
|
||||
+++ b/crypto/x509/v3_utl.c
|
||||
@@ -916,36 +916,64 @@ static int do_x509_check(X509 *x, const char *chk, size_t chklen,
|
||||
ASN1_STRING *cstr;
|
||||
|
||||
gen = sk_GENERAL_NAME_value(gens, i);
|
||||
- if ((gen->type == GEN_OTHERNAME) && (check_type == GEN_EMAIL)) {
|
||||
- if (OBJ_obj2nid(gen->d.otherName->type_id) ==
|
||||
- NID_id_on_SmtpUTF8Mailbox) {
|
||||
- san_present = 1;
|
||||
-
|
||||
- /*
|
||||
- * If it is not a UTF8String then that is unexpected and we
|
||||
- * treat it as no match
|
||||
- */
|
||||
- if (gen->d.otherName->value->type == V_ASN1_UTF8STRING) {
|
||||
- cstr = gen->d.otherName->value->value.utf8string;
|
||||
-
|
||||
- /* Positive on success, negative on error! */
|
||||
- if ((rv = do_check_string(cstr, 0, equal, flags,
|
||||
- chk, chklen, peername)) != 0)
|
||||
- break;
|
||||
- }
|
||||
- } else
|
||||
+ switch (gen->type) {
|
||||
+ default:
|
||||
+ continue;
|
||||
+ case GEN_OTHERNAME:
|
||||
+ switch (OBJ_obj2nid(gen->d.otherName->type_id)) {
|
||||
+ default:
|
||||
continue;
|
||||
- } else {
|
||||
- if ((gen->type != check_type) && (gen->type != GEN_OTHERNAME))
|
||||
+ case NID_id_on_SmtpUTF8Mailbox:
|
||||
+ /*-
|
||||
+ * https://datatracker.ietf.org/doc/html/rfc8398#section-3
|
||||
+ *
|
||||
+ * Due to name constraint compatibility reasons described
|
||||
+ * in Section 6, SmtpUTF8Mailbox subjectAltName MUST NOT
|
||||
+ * be used unless the local-part of the email address
|
||||
+ * contains non-ASCII characters. When the local-part is
|
||||
+ * ASCII, rfc822Name subjectAltName MUST be used instead
|
||||
+ * of SmtpUTF8Mailbox. This is compatible with legacy
|
||||
+ * software that supports only rfc822Name (and not
|
||||
+ * SmtpUTF8Mailbox). [...]
|
||||
+ *
|
||||
+ * SmtpUTF8Mailbox is encoded as UTF8String.
|
||||
+ *
|
||||
+ * If it is not a UTF8String then that is unexpected, and
|
||||
+ * we ignore the invalid SAN (neither set san_present nor
|
||||
+ * consider it a candidate for equality). This does mean
|
||||
+ * that the subject CN may be considered, as would be the
|
||||
+ * case when the malformed SmtpUtf8Mailbox SAN is instead
|
||||
+ * simply absent.
|
||||
+ *
|
||||
+ * When CN-ID matching is not desirable, applications can
|
||||
+ * choose to turn it off, doing so is at this time a best
|
||||
+ * practice.
|
||||
+ */
|
||||
+ if (check_type != GEN_EMAIL
|
||||
+ || gen->d.otherName->value->type != V_ASN1_UTF8STRING)
|
||||
+ continue;
|
||||
+ alt_type = 0;
|
||||
+ cstr = gen->d.otherName->value->value.utf8string;
|
||||
+ break;
|
||||
+ }
|
||||
+ break;
|
||||
+ case GEN_EMAIL:
|
||||
+ if (check_type != GEN_EMAIL)
|
||||
continue;
|
||||
- }
|
||||
- san_present = 1;
|
||||
- if (check_type == GEN_EMAIL)
|
||||
cstr = gen->d.rfc822Name;
|
||||
- else if (check_type == GEN_DNS)
|
||||
+ break;
|
||||
+ case GEN_DNS:
|
||||
+ if (check_type != GEN_DNS)
|
||||
+ continue;
|
||||
cstr = gen->d.dNSName;
|
||||
- else
|
||||
+ break;
|
||||
+ case GEN_IPADD:
|
||||
+ if (check_type != GEN_IPADD)
|
||||
+ continue;
|
||||
cstr = gen->d.iPAddress;
|
||||
+ break;
|
||||
+ }
|
||||
+ san_present = 1;
|
||||
/* Positive on success, negative on error! */
|
||||
if ((rv = do_check_string(cstr, alt_type, equal, flags,
|
||||
chk, chklen, peername)) != 0)
|
||||
diff --git a/test/recipes/25-test_eai_data.t b/test/recipes/25-test_eai_data.t
|
||||
index 522982ddfb..e18735d89a 100644
|
||||
--- a/test/recipes/25-test_eai_data.t
|
||||
+++ b/test/recipes/25-test_eai_data.t
|
||||
@@ -21,16 +21,18 @@ setup("test_eai_data");
|
||||
#./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/utf8_chain.pem test/recipes/25-test_eai_data/ascii_leaf.pem
|
||||
#./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/ascii_chain.pem test/recipes/25-test_eai_data/utf8_leaf.pem
|
||||
|
||||
-plan tests => 12;
|
||||
+plan tests => 16;
|
||||
|
||||
require_ok(srctop_file('test','recipes','tconversion.pl'));
|
||||
my $folder = "test/recipes/25-test_eai_data";
|
||||
|
||||
my $ascii_pem = srctop_file($folder, "ascii_leaf.pem");
|
||||
my $utf8_pem = srctop_file($folder, "utf8_leaf.pem");
|
||||
+my $kdc_pem = srctop_file($folder, "kdc-cert.pem");
|
||||
|
||||
my $ascii_chain_pem = srctop_file($folder, "ascii_chain.pem");
|
||||
my $utf8_chain_pem = srctop_file($folder, "utf8_chain.pem");
|
||||
+my $kdc_chain_pem = srctop_file($folder, "kdc-root-cert.pem");
|
||||
|
||||
my $out;
|
||||
my $outcnt = 0;
|
||||
@@ -56,10 +58,18 @@ SKIP: {
|
||||
|
||||
ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $ascii_chain_pem, $ascii_pem])));
|
||||
ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $utf8_chain_pem, $utf8_pem])));
|
||||
+ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $kdc_chain_pem, $kdc_pem])));
|
||||
|
||||
ok(!run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $ascii_chain_pem, $utf8_pem])));
|
||||
ok(!run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $utf8_chain_pem, $ascii_pem])));
|
||||
|
||||
+# Check an otherName does not get misparsed as an DNS name, (should trigger ASAN errors if violated).
|
||||
+ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-verify_hostname", 'mx1.example.com', "-CAfile", $kdc_chain_pem, $kdc_pem])));
|
||||
+# Check an otherName does not get misparsed as an email address, (should trigger ASAN errors if violated).
|
||||
+ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-verify_email", 'joe@example.com', "-CAfile", $kdc_chain_pem, $kdc_pem])));
|
||||
+# We expect SmtpUTF8Mailbox to be a UTF8 String, not an IA5String.
|
||||
+ok(!run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-verify_email", 'moe@example.com', "-CAfile", $kdc_chain_pem, $kdc_pem])));
|
||||
+
|
||||
#Check that we get the expected failure return code
|
||||
with({ exit_checker => sub { return shift == 2; } },
|
||||
sub {
|
||||
diff --git a/test/recipes/25-test_eai_data/kdc-cert.pem b/test/recipes/25-test_eai_data/kdc-cert.pem
|
||||
new file mode 100644
|
||||
index 0000000000..e8a2c6f55d
|
||||
--- /dev/null
|
||||
+++ b/test/recipes/25-test_eai_data/kdc-cert.pem
|
||||
@@ -0,0 +1,21 @@
|
||||
+-----BEGIN CERTIFICATE-----
|
||||
+MIIDbDCCAlSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDDARSb290
|
||||
+MCAXDTI0MDYyMDA2MTQxNVoYDzIxMjQwNjIwMDYxNDE1WjAXMRUwEwYDVQQDDAxU
|
||||
+RVNULkVYQU1QTEUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6wf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iPAJFB76RpwI
|
||||
+oDQ9fKfUOAmUFth2/R/eGA==
|
||||
+-----END CERTIFICATE-----
|
||||
diff --git a/test/recipes/25-test_eai_data/kdc-root-cert.pem b/test/recipes/25-test_eai_data/kdc-root-cert.pem
|
||||
new file mode 100644
|
||||
index 0000000000..a74c96bf31
|
||||
--- /dev/null
|
||||
+++ b/test/recipes/25-test_eai_data/kdc-root-cert.pem
|
||||
@@ -0,0 +1,16 @@
|
||||
+-----BEGIN CERTIFICATE-----
|
||||
+MIICnDCCAYQCCQCBswYcrlZSHjANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDDARS
|
||||
+b290MCAXDTI0MDYyMDA2MTQxNVoYDzIxMjQwNjIwMDYxNDE1WjAPMQ0wCwYDVQQD
|
||||
+DARSb290MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqRj8S4kBbIUj
|
||||
+61kZfi6nE35Q38U140+qt4uAiwAhKumfVHlBM0zQ98WFt5zMHIBQwIb3yjc2zj+0
|
||||
+qzUnQfwm1r/RfcMmBPEti9Ge+aEMSsds2gMXziOFM8wd2aAFPy7UVE0XpEWofsRK
|
||||
+MGi61MKVdPSbGIxBwY9VW38/7D/wf1HtJe7y0xpuecR7GB2XAs+qST59NjuF+7wS
|
||||
+dLM8Hb3TATgeYbXXWsRJgwz+SPzExg5WmLnU+7y4brZ32dHtdSmkRVSgSlaIf7Xj
|
||||
+3Tc6Zi7I+W/JYk7hy1zUexVdWCak4PHcoWrXe0gNNN/t8VfLfMExt5z/HIylXnU7
|
||||
+pGUyqZlTGQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQAHpLF1UCRy7b6Hk0rLokxI
|
||||
+lgwiH9BU9mktigAGASvkbllpt+YbUbWnuYAvpHBGiP1qZtfX2r96UrSJaGO9BEzT
|
||||
+Gp9ThnSjoj4Srul0+s/NArU22irFLmDzbalgevAmm9gMGkdqkiIm/mXbwrPj0ncl
|
||||
+KGicevXryVpvaP62eZ8cc3C4p97frMmXxRX8sTdQpD/gRI7prdEILRSKveqT+AEW
|
||||
+7rFGM5AOevb4U8ddop8A3D/kX0wcCAIBF6jCNk3uEJ57jVcagL04kPnVfdRiedTS
|
||||
+vfq1DRNcD29d1H/9u0fHdSn1/+8Ep3X+afQ3C6//5NvOEaXcIGO4QSwkprQydfv8
|
||||
+-----END CERTIFICATE-----
|
||||
diff --git a/test/recipes/25-test_eai_data/kdc.sh b/test/recipes/25-test_eai_data/kdc.sh
|
||||
new file mode 100755
|
||||
index 0000000000..7a8dbc719f
|
||||
--- /dev/null
|
||||
+++ b/test/recipes/25-test_eai_data/kdc.sh
|
||||
@@ -0,0 +1,41 @@
|
||||
+#! /usr/bin/env bash
|
||||
+
|
||||
+# Create a root CA, signing a leaf cert with a KDC principal otherName SAN, and
|
||||
+# also a non-UTF8 smtpUtf8Mailbox SAN followed by an rfc822Name SAN and a DNS
|
||||
+# name SAN. In the vulnerable EAI code, the KDC principal `otherName` should
|
||||
+# trigger ASAN errors in DNS name checks, while the non-UTF8 `smtpUtf8Mailbox`
|
||||
+# should likewise lead to ASAN issues with email name checks.
|
||||
+
|
||||
+rm -f root-key.pem root-cert.pem
|
||||
+openssl req -nodes -new -newkey rsa:2048 -keyout kdc-root-key.pem \
|
||||
+ -x509 -subj /CN=Root -days 36524 -out kdc-root-cert.pem
|
||||
+
|
||||
+exts=$(
|
||||
+ printf "%s\n%s\n%s\n%s = " \
|
||||
+ "subjectKeyIdentifier = hash" \
|
||||
+ "authorityKeyIdentifier = keyid" \
|
||||
+ "basicConstraints = CA:false" \
|
||||
+ "subjectAltName"
|
||||
+ printf "%s, " "otherName:1.3.6.1.5.2.2;SEQUENCE:kdc_princ_name"
|
||||
+ printf "%s, " "otherName:1.3.6.1.5.5.7.8.9;IA5:moe@example.com"
|
||||
+ printf "%s, " "email:joe@example.com"
|
||||
+ printf "%s\n" "DNS:mx1.example.com"
|
||||
+ printf "[kdc_princ_name]\n"
|
||||
+ printf "realm = EXP:0, GeneralString:TEST.EXAMPLE\n"
|
||||
+ printf "principal_name = EXP:1, SEQUENCE:kdc_principal_seq\n"
|
||||
+ printf "[kdc_principal_seq]\n"
|
||||
+ printf "name_type = EXP:0, INTEGER:1\n"
|
||||
+ printf "name_string = EXP:1, SEQUENCE:kdc_principal_components\n"
|
||||
+ printf "[kdc_principal_components]\n"
|
||||
+ printf "princ1 = GeneralString:krbtgt\n"
|
||||
+ printf "princ2 = GeneralString:TEST.EXAMPLE\n"
|
||||
+ )
|
||||
+
|
||||
+printf "%s\n" "$exts"
|
||||
+
|
||||
+openssl req -nodes -new -newkey rsa:2048 -keyout kdc-key.pem \
|
||||
+ -subj "/CN=TEST.EXAMPLE" |
|
||||
+ openssl x509 -req -out kdc-cert.pem \
|
||||
+ -CA "kdc-root-cert.pem" -CAkey "kdc-root-key.pem" \
|
||||
+ -set_serial 2 -days 36524 \
|
||||
+ -extfile <(printf "%s\n" "$exts")
|
Loading…
Reference in new issue