]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid exporting bogus (empty) data if empty selection is used
authorTomas Mraz <tomas@openssl.org>
Fri, 21 Jul 2023 14:26:12 +0000 (16:26 +0200)
committerTodd Short <todd.short@me.com>
Fri, 4 Aug 2023 14:09:43 +0000 (10:09 -0400)
This is already correct in the rsa_kmgmt.c but other
implementations are wrong.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/21519)

providers/implementations/keymgmt/dh_kmgmt.c
providers/implementations/keymgmt/dsa_kmgmt.c
providers/implementations/keymgmt/ecx_kmgmt.c
providers/implementations/keymgmt/mac_legacy_kmgmt.c

index d0a101ab3716a1b518da7956be6d1217de78008a..eaca876bb9d133f3de2671cbcf4312a87cc4dd6a 100644 (file)
@@ -222,6 +222,9 @@ static int dh_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
     if (!ossl_prov_is_running() || dh == NULL)
         return 0;
 
+    if ((selection & DH_POSSIBLE_SELECTIONS) == 0)
+        return 0;
+
     tmpl = OSSL_PARAM_BLD_new();
     if (tmpl == NULL)
         return 0;
index 9aa699c28904392b67b3f4a9bbb1fa037fb33191..c2400e4602ddd860f984dd3827cfeb15acea6d0d 100644 (file)
@@ -223,6 +223,9 @@ static int dsa_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
     if (!ossl_prov_is_running() || dsa == NULL)
         return 0;
 
+    if ((selection & DSA_POSSIBLE_SELECTIONS) == 0)
+        return 0;
+
     tmpl = OSSL_PARAM_BLD_new();
     if (tmpl == NULL)
         return 0;
index f79fe9fde7260279f0890c7bf068905230126700..0a354ea721d02aae89229d674d25713db0b6182b 100644 (file)
@@ -241,6 +241,9 @@ static int ecx_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
     if (!ossl_prov_is_running() || key == NULL)
         return 0;
 
+    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
+        return 0;
+
     tmpl = OSSL_PARAM_BLD_new();
     if (tmpl == NULL)
         return 0;
index babeba748dacda5113df529004391d05d6c31037..9b37027a966e7b15b6023f41efc0409a4a25a36c 100644 (file)
@@ -275,6 +275,9 @@ static int mac_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
     if (!ossl_prov_is_running() || key == NULL)
         return 0;
 
+    if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) == 0)
+        return 0;
+
     tmpl = OSSL_PARAM_BLD_new();
     if (tmpl == NULL)
         return 0;