aboutsummaryrefslogtreecommitdiff
path: root/crypto/dsa
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-02-27 10:51:45 +0100
committerRichard Levitte <levitte@openssl.org>2020-03-09 10:54:01 +0100
commitdf13defd4fd4c5a7afff69bc9733e7526e07959a (patch)
tree869933ff708dffee404be50d512fff4f59394581 /crypto/dsa
parentb4dc705a73ba2e8257ea3438ee39e661973e2a13 (diff)
downloadopenssl-df13defd4fd4c5a7afff69bc9733e7526e07959a.zip
openssl-df13defd4fd4c5a7afff69bc9733e7526e07959a.tar.gz
openssl-df13defd4fd4c5a7afff69bc9733e7526e07959a.tar.bz2
EVP: Check that key methods aren't foreign when exporting
The EVP_PKEY_ASN1_METHOD function export_to() must check that the key we're trying to export has a known libcrypto method, i.e. is a built in RSA_METHOD, DSA_METHOD, etc. Otherwise, the method may be defined by the calling application, by an engine, by another library, and we simply cannot know all the quirks hidden behind that method, if we have access to the key data, or much anything. Such keys are simply deemed impossible to export to provider keys, i.e. have export_to() return 0. This cascades back to functions like evp_pkey_export_to_provider() and evp_pkey_upgrade_to_provider() and their callers. In most cases, this is fine, but if these get mixed in with provider side keys in any function, that function will fail. Fixes #11179 Fixes #9915 Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/11193)
Diffstat (limited to 'crypto/dsa')
-rw-r--r--crypto/dsa/dsa_ameth.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c
index 9715a75..94f3f43 100644
--- a/crypto/dsa/dsa_ameth.c
+++ b/crypto/dsa/dsa_ameth.c
@@ -528,6 +528,13 @@ static int dsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
OSSL_PARAM *params;
int rv;
+ /*
+ * If the DSA method is foreign, then we can't be sure of anything, and
+ * can therefore not export or pretend to export.
+ */
+ if (DSA_get_method(dsa) != DSA_OpenSSL())
+ return 0;
+
if (p == NULL || q == NULL || g == NULL)
return 0;