From d0ddf9b409495e8e2adab8a6b5bc38b34273341a Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 15 Apr 2020 09:54:11 +0200 Subject: EVP: Fix calls to evp_pkey_export_to_provider() The calls weren't quite right, as this function has changed its behaviour. We also change the internal documentation of this function, and document evp_pkey_downgrade(). Fixes #11549 Reviewed-by: Paul Dale Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/11550) --- crypto/evp/keymgmt_meth.c | 9 ++++++++- crypto/evp/pmeth_gn.c | 6 +++++- crypto/evp/signature.c | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'crypto') diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index 7ea414e8dd..7925aeaf43 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -313,8 +313,15 @@ void *evp_keymgmt_gen_init(const EVP_KEYMGMT *keymgmt, int selection) int evp_keymgmt_gen_set_template(const EVP_KEYMGMT *keymgmt, void *genctx, void *template) { + /* + * It's arguable if we actually should return success in this case, as + * it allows the caller to set a template key, which is then ignored. + * However, this is how the legacy methods (EVP_PKEY_METHOD) operate, + * so we do this in the interest of backward compatibility. + * TODO(3.0) Investigate if we should change this behaviour. + */ if (keymgmt->gen_set_template == NULL) - return 0; + return 1; return keymgmt->gen_set_template(genctx, template); } diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index 78ed9ec781..95e3185573 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -170,8 +170,12 @@ int EVP_PKEY_gen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) evp_pkey_export_to_provider(ctx->pkey, ctx->libctx, &tmp_keymgmt, ctx->propquery); - if (keydata == NULL) + if (tmp_keymgmt == NULL) goto not_supported; + /* + * It's ok if keydata is NULL here. The backend is expected to deal + * with that as it sees fit. + */ ret = evp_keymgmt_gen_set_template(ctx->keymgmt, ctx->op.keymgmt.genctx, keydata); } diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index 1f5e570ff8..2334dcfb41 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -369,7 +369,7 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) tmp_keymgmt = ctx->keymgmt; provkey = evp_pkey_export_to_provider(ctx->pkey, ctx->libctx, &tmp_keymgmt, ctx->propquery); - if (provkey == NULL) + if (tmp_keymgmt == NULL) goto legacy; if (!EVP_KEYMGMT_up_ref(tmp_keymgmt)) { ERR_clear_last_mark(); -- cgit v1.2.3