]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Do not allow creating empty RSA keys by duplication
authorTomas Mraz <tomas@openssl.org>
Thu, 8 Apr 2021 17:27:06 +0000 (19:27 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 15 Apr 2021 07:23:18 +0000 (09:23 +0200)
Also avoid crashing in rsa_get_params on empty keys.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14793)

crypto/dh/dh_lib.c
crypto/dsa/dsa_lib.c
crypto/ec/ecx_key.c
providers/implementations/keymgmt/rsa_kmgmt.c

index 92767a94c222a3575c65c1fca00d2507f0cc919b..f5e0f893c18b33c48ebf7323049103edf2c8337b 100644 (file)
@@ -325,5 +325,3 @@ int ossl_dh_get0_nid(const DH *dh)
 {
     return dh->params.nid;
 }
-
-
index f39c2aa21a893a3b57321e475569c3c7ca949fb6..5512b99ef100799defc97238670dfa7227ec1154 100644 (file)
@@ -358,4 +358,3 @@ int ossl_dsa_ffc_params_fromdata(DSA *dsa, const OSSL_PARAM params[])
         dsa->dirty_cnt++;
     return ret;
 }
-
index 90253372cecfa714c287d5b16c3417a02f08b482..dcec26c2e9b38f4df2438dfc11b073fad147539b 100644 (file)
@@ -96,4 +96,3 @@ unsigned char *ossl_ecx_key_allocate_privkey(ECX_KEY *key)
 
     return key->privkey;
 }
-
index f0d1896ec0efbeb5eb01cf131e35d4a3080e5118..a075c54487ce2bd70ea5e6da8edb09862dfba6f2 100644 (file)
@@ -306,15 +306,16 @@ static int rsa_get_params(void *key, OSSL_PARAM params[])
     const RSA_PSS_PARAMS_30 *pss_params = ossl_rsa_get0_pss_params_30(rsa);
     int rsa_type = RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK);
     OSSL_PARAM *p;
+    int empty = RSA_get0_n(rsa) == NULL;
 
     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL
-        && !OSSL_PARAM_set_int(p, RSA_bits(rsa)))
+        && (empty || !OSSL_PARAM_set_int(p, RSA_bits(rsa))))
         return 0;
     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_SECURITY_BITS)) != NULL
-        && !OSSL_PARAM_set_int(p, RSA_security_bits(rsa)))
+        && (empty || !OSSL_PARAM_set_int(p, RSA_security_bits(rsa))))
         return 0;
     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL
-        && !OSSL_PARAM_set_int(p, RSA_size(rsa)))
+        && (empty || !OSSL_PARAM_set_int(p, RSA_size(rsa))))
         return 0;
 
     /*
@@ -648,7 +649,9 @@ static void *rsapss_load(const void *reference, size_t reference_sz)
 
 static void *rsa_dup(const void *keydata_from, int selection)
 {
-    if (ossl_prov_is_running())
+    if (ossl_prov_is_running()
+        /* do not allow creating empty keys by duplication */
+        && (selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
         return ossl_rsa_dup(keydata_from, selection);
     return NULL;
 }