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:13:40 +0000 (10:13 -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)

(cherry picked from commit 1ae4678cebaa13604c0f31bdf2c64cd28bdaf287)

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 9a7dde7c66273bf8a62cbe8ff42d89989d55d95f..4ca9c1a3fad8b9a60fdbec5820ee393fde7108d6 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 cd8b4410b0db63d9507e1cd24b7382b9a7f50e5a..2f5742cfcc07ce6733c8e3c81d0c3b0c439e45d1 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 2a7f867aa56b3bdf6399b98d3795f7b7f99348b3..831681412aec7730dd2ba21834bbd1e4a4f65a79 100644 (file)
@@ -238,6 +238,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 fd192893009f68f36c52a8195013c1321522fca1..a55dcb0320319f98c4d630f260db7c283d77e967 100644 (file)
@@ -281,6 +281,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;