diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2020-12-02 08:52:24 +0100 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2021-02-19 10:19:28 +0100 |
commit | 576892d78f80cf9a169e7f766319c843e430f378 (patch) | |
tree | 324a1adedd7008b364b4e70776eb0239bc894e09 /test/evp_extra_test2.c | |
parent | doc: remove notes section in OSSL_ENCODER.pod (diff) | |
download | openssl-576892d78f80cf9a169e7f766319c843e430f378.tar.xz openssl-576892d78f80cf9a169e7f766319c843e430f378.zip |
Fix d2i_AutoPrivateKey_ex so that is uses the new decoder (and produces
non legacy keys).
Fixes #13522
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13591)
Diffstat (limited to 'test/evp_extra_test2.c')
-rw-r--r-- | test/evp_extra_test2.c | 84 |
1 files changed, 81 insertions, 3 deletions
diff --git a/test/evp_extra_test2.c b/test/evp_extra_test2.c index 9181061247..bb8e897536 100644 --- a/test/evp_extra_test2.c +++ b/test/evp_extra_test2.c @@ -17,6 +17,7 @@ #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/provider.h> +#include <openssl/core_names.h> #include "testutil.h" #include "internal/nelem.h" @@ -141,6 +142,58 @@ static const unsigned char kExampleRSAKeyPKCS8[] = { 0x08, 0xf1, 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf, }; +#ifndef OPENSSL_NO_DH +static const unsigned char kExampleDHPrivateKeyDER[] = { + 0x30, 0x82, 0x02, 0x26, 0x02, 0x01, 0x00, 0x30, 0x82, 0x01, 0x17, 0x06, + 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x03, 0x01, 0x30, 0x82, + 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xD8, 0x4B, 0x0F, 0x0E, 0x6B, + 0x79, 0xE9, 0x23, 0x4E, 0xE4, 0xBE, 0x9A, 0x8F, 0x7A, 0x5C, 0xA3, 0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, 0x69, 0xDB, + 0xF2, 0x4F, 0x94, 0xB7, 0x71, 0xAF, 0xBA, 0x5C, 0x1F, 0xF8, 0x6B, 0xE5, + 0xD1, 0xB1, 0x00, 0x81, 0xE2, 0x6D, 0xEC, 0x65, 0xF7, 0x7E, 0xCE, 0x03, + 0x84, 0x68, 0x42, 0x6A, 0x8B, 0x47, 0x8E, 0x4A, 0x88, 0xDE, 0x82, 0xDD, + 0xAF, 0xA9, 0x6F, 0x18, 0xF7, 0xC6, 0xE2, 0xB9, 0x97, 0xCE, 0x47, 0x8F, + 0x85, 0x19, 0x61, 0x42, 0x67, 0x21, 0x7D, 0x13, 0x6E, 0xB5, 0x5A, 0x62, + 0xF3, 0x08, 0xE2, 0x70, 0x3B, 0x0E, 0x85, 0x3C, 0xA1, 0xD3, 0xED, 0x7A, + 0x43, 0xD6, 0xDE, 0x30, 0x5C, 0x48, 0xB2, 0x99, 0xAB, 0x3E, 0x65, 0xA6, + 0x66, 0x80, 0x22, 0xFF, 0x92, 0xC1, 0x42, 0x1C, 0x30, 0x87, 0x74, 0x1E, + 0x53, 0x57, 0x7C, 0xF8, 0x77, 0x51, 0xF1, 0x74, 0x16, 0xF4, 0x45, 0x26, + 0x77, 0x0A, 0x05, 0x96, 0x13, 0x12, 0x06, 0x86, 0x2B, 0xB8, 0x49, 0x82, + 0x69, 0x43, 0x0A, 0x57, 0xA7, 0x30, 0x19, 0x4C, 0xB8, 0x47, 0x82, 0x6E, + 0x64, 0x7A, 0x06, 0x13, 0x5A, 0x82, 0x98, 0xD6, 0x7A, 0x09, 0xEC, 0x03, + 0x8D, 0x03 +}; +#endif /* OPENSSL_NO_DH */ + #ifndef OPENSSL_NO_EC /* * kExampleECKeyDER is a sample EC private key encoded as an ECPrivateKey @@ -183,7 +236,10 @@ static APK_DATA keydata[] = { {kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8), EVP_PKEY_RSA}, #ifndef OPENSSL_NO_EC {kExampleECKeyDER, sizeof(kExampleECKeyDER), EVP_PKEY_EC}, - {kExampleECKey2DER, sizeof(kExampleECKey2DER), EVP_PKEY_EC} + {kExampleECKey2DER, sizeof(kExampleECKey2DER), EVP_PKEY_EC}, +#endif +#ifndef OPENSSL_NO_DH + {kExampleDHPrivateKeyDER, sizeof(kExampleDHPrivateKeyDER), EVP_PKEY_DH}, #endif }; @@ -197,6 +253,9 @@ static int test_d2i_AutoPrivateKey_ex(int i) const unsigned char *input = ak->kder; size_t input_len = ak->size; int expected_id = ak->evptype; + BIGNUM *p_bn = NULL; + BIGNUM *g_bn = NULL; + BIGNUM *priv_bn = NULL; p = input; if (!TEST_ptr(pkey = d2i_AutoPrivateKey_ex(NULL, &p, input_len, mainctx, @@ -205,9 +264,28 @@ static int test_d2i_AutoPrivateKey_ex(int i) || !TEST_int_eq(EVP_PKEY_id(pkey), expected_id)) goto done; - ret = 1; + if (ak->evptype == EVP_PKEY_RSA) { + if (!TEST_true(EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_D, + &priv_bn))) + goto done; + } else { + if (!TEST_true(EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_PRIV_KEY, + &priv_bn))) + goto done; + } + + if (ak->evptype == EVP_PKEY_DH) { + if (!TEST_true(EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_FFC_P, &p_bn)) + || !TEST_true(EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_FFC_G, + &g_bn))) + goto done; + } - done: + ret = 1; +done: + BN_free(p_bn); + BN_free(g_bn); + BN_free(priv_bn); EVP_PKEY_free(pkey); return ret; } |