From 8865d7c4e8f9afac969fc927f2b24ee6d03868bd Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Fri, 21 Jul 2023 16:26:12 +0200 Subject: [PATCH] Avoid exporting bogus (empty) data if empty selection is used This is already correct in the rsa_kmgmt.c but other implementations are wrong. Reviewed-by: Matt Caswell Reviewed-by: Paul Dale Reviewed-by: Todd Short (Merged from https://github.com/openssl/openssl/pull/21519) (cherry picked from commit 1ae4678cebaa13604c0f31bdf2c64cd28bdaf287) --- providers/implementations/keymgmt/dh_kmgmt.c | 3 +++ providers/implementations/keymgmt/dsa_kmgmt.c | 3 +++ providers/implementations/keymgmt/ecx_kmgmt.c | 3 +++ providers/implementations/keymgmt/mac_legacy_kmgmt.c | 3 +++ 4 files changed, 12 insertions(+) diff --git a/providers/implementations/keymgmt/dh_kmgmt.c b/providers/implementations/keymgmt/dh_kmgmt.c index 9a7dde7c662..4ca9c1a3fad 100644 --- a/providers/implementations/keymgmt/dh_kmgmt.c +++ b/providers/implementations/keymgmt/dh_kmgmt.c @@ -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; diff --git a/providers/implementations/keymgmt/dsa_kmgmt.c b/providers/implementations/keymgmt/dsa_kmgmt.c index cd8b4410b0d..2f5742cfcc0 100644 --- a/providers/implementations/keymgmt/dsa_kmgmt.c +++ b/providers/implementations/keymgmt/dsa_kmgmt.c @@ -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; diff --git a/providers/implementations/keymgmt/ecx_kmgmt.c b/providers/implementations/keymgmt/ecx_kmgmt.c index 2a7f867aa56..831681412ae 100644 --- a/providers/implementations/keymgmt/ecx_kmgmt.c +++ b/providers/implementations/keymgmt/ecx_kmgmt.c @@ -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; diff --git a/providers/implementations/keymgmt/mac_legacy_kmgmt.c b/providers/implementations/keymgmt/mac_legacy_kmgmt.c index fd192893009..a55dcb03203 100644 --- a/providers/implementations/keymgmt/mac_legacy_kmgmt.c +++ b/providers/implementations/keymgmt/mac_legacy_kmgmt.c @@ -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; -- 2.47.2