From 4fd397821139723fd4e51a03e92df33e9a9fadcc Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Sun, 2 Aug 2020 14:29:33 +0200 Subject: [PATCH] DECODER: Add function to set an OSSL_PASSPHRASE_CALLBACK type callback This makes it possible to use OSSL_DECODER in functions that are passed a OSSL_PASSPHRASE_CALLBACK already. Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/12512) --- crypto/encode_decode/decoder_pkey.c | 7 ++++++ doc/man3/OSSL_DECODER_CTX_new_by_EVP_PKEY.pod | 25 ++++++++++--------- include/openssl/decoder.h | 3 +++ util/libcrypto.num | 1 + 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/crypto/encode_decode/decoder_pkey.c b/crypto/encode_decode/decoder_pkey.c index 92c0d5a6ea8..0bb548abcee 100644 --- a/crypto/encode_decode/decoder_pkey.c +++ b/crypto/encode_decode/decoder_pkey.c @@ -36,6 +36,13 @@ int OSSL_DECODER_CTX_set_pem_password_cb(OSSL_DECODER_CTX *ctx, return ossl_pw_set_pem_password_cb(&ctx->pwdata, cb, cbarg); } +int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx, + OSSL_PASSPHRASE_CALLBACK *cb, + void *cbarg) +{ + return ossl_pw_set_ossl_passphrase_cb(&ctx->pwdata, cb, cbarg); +} + /* * Support for OSSL_DECODER_CTX_new_by_EVP_PKEY: * The construct data, and collecting keymgmt information for it diff --git a/doc/man3/OSSL_DECODER_CTX_new_by_EVP_PKEY.pod b/doc/man3/OSSL_DECODER_CTX_new_by_EVP_PKEY.pod index 4486e6b0016..620688e322f 100644 --- a/doc/man3/OSSL_DECODER_CTX_new_by_EVP_PKEY.pod +++ b/doc/man3/OSSL_DECODER_CTX_new_by_EVP_PKEY.pod @@ -5,7 +5,8 @@ OSSL_DECODER_CTX_new_by_EVP_PKEY, OSSL_DECODER_CTX_set_passphrase, OSSL_DECODER_CTX_set_pem_password_cb, -OSSL_DECODER_CTX_set_passphrase_ui +OSSL_DECODER_CTX_set_passphrase_ui, +OSSL_DECODER_CTX_set_passphrase_cb - Decoder routines to decode EVP_PKEYs =head1 SYNOPSIS @@ -25,6 +26,9 @@ OSSL_DECODER_CTX_set_passphrase_ui int OSSL_DECODER_CTX_set_passphrase_ui(OSSL_DECODER_CTX *ctx, const UI_METHOD *ui_method, void *ui_data); + int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx, + OSSL_PASSPHRASE_CALLBACK *cb, + void *cbarg); =head1 DESCRIPTION @@ -55,29 +59,26 @@ pass phrase to use when decrypting the encoded private key. Alternatively, a pass phrase callback may be specified with the following functions. -OSSL_DECODER_CTX_set_pem_password_cb() and -OSSL_DECODER_CTX_set_passphrase_ui() set up a callback method that +OSSL_DECODER_CTX_set_pem_password_cb(), +OSSL_DECODER_CTX_set_passphrase_ui() and +OSSL_DECODER_CTX_set_passphrase_cb() set up a callback method that the implementation can use to prompt for a pass phrase, giving the caller the choice of prefered pass phrase callback form. These are called indirectly, through an internal B function. -The internal B function caches the pass phrase, to -be re-used in all decodings that are performed in the same -decoding run +The internal B function caches the pass phrase, +to be re-used in all decodings that are performed in the same decoding run (for example, within one L call). -=for comment the name OSSL_DECODER_CTX_set_pem_password_cb() leaves -open the future possibility of having a function where the caller can set a -B method as another option. - =head1 RETURN VALUES OSSL_DECODER_CTX_new_by_EVP_PKEY() returns a pointer to a B, or NULL if it couldn't be created. OSSL_DECODER_CTX_set_passphrase(), -OSSL_DECODER_CTX_set_pem_password_cb() and -OSSL_DECODER_CTX_set_passphrase_ui() +OSSL_DECODER_CTX_set_pem_password_cb(), +OSSL_DECODER_CTX_set_passphrase_ui() and +OSSL_DECODER_CTX_set_passphrase_cb() all return 1 on success, or 0 on failure. =head1 NOTES diff --git a/include/openssl/decoder.h b/include/openssl/decoder.h index cb5a404b893..91dfca4a094 100644 --- a/include/openssl/decoder.h +++ b/include/openssl/decoder.h @@ -58,6 +58,9 @@ int OSSL_DECODER_CTX_set_passphrase(OSSL_DECODER_CTX *ctx, int OSSL_DECODER_CTX_set_pem_password_cb(OSSL_DECODER_CTX *ctx, pem_password_cb *cb, void *cbarg); +int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx, + OSSL_PASSPHRASE_CALLBACK *cb, + void *cbarg); int OSSL_DECODER_CTX_set_passphrase_ui(OSSL_DECODER_CTX *ctx, const UI_METHOD *ui_method, void *ui_data); diff --git a/util/libcrypto.num b/util/libcrypto.num index 5cda5b3d8dc..99790a1b74c 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -5283,3 +5283,4 @@ OSSL_STORE_LOADER_do_all_provided ? 3_0_0 EXIST::FUNCTION: OSSL_STORE_LOADER_names_do_all ? 3_0_0 EXIST::FUNCTION: OSSL_PARAM_get_utf8_string_ptr ? 3_0_0 EXIST::FUNCTION: OSSL_PARAM_get_octet_string_ptr ? 3_0_0 EXIST::FUNCTION: +OSSL_DECODER_CTX_set_passphrase_cb ? 3_0_0 EXIST::FUNCTION: -- 2.47.2