From 1aa8c97a67ae922343d58a24ff10b46744c94e0d Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 6 Feb 2023 08:26:21 +0100 Subject: [PATCH] [crypto,key] use EVP_PKEY_up_ref The function is available since OpenSSL 1.1.0 instead of 3.0 for EVP_PKEY_dup --- libfreerdp/crypto/privatekey.c | 10 ++++++++-- libfreerdp/crypto/privatekey.h | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libfreerdp/crypto/privatekey.c b/libfreerdp/crypto/privatekey.c index 5c4ba19e3..c88b6377b 100644 --- a/libfreerdp/crypto/privatekey.c +++ b/libfreerdp/crypto/privatekey.c @@ -42,6 +42,8 @@ #include +#include + #include "x509_utils.h" #include "crypto.h" #include "opensslcompat.h" @@ -233,9 +235,10 @@ rdpPrivateKey* freerdp_key_clone(const rdpPrivateKey* key) _key->isRSA = key->isRSA; if (key->evp) { - _key->evp = EVP_PKEY_dup(key->evp); + _key->evp = key->evp; if (!_key->evp) goto out_fail; + EVP_PKEY_up_ref(_key->evp); } if (key->PrivateExponent) @@ -303,5 +306,8 @@ RSA* freerdp_key_get_RSA(const rdpPrivateKey* key) EVP_PKEY* freerdp_key_get_evp_pkey(const rdpPrivateKey* key) { WINPR_ASSERT(key); - return key->evp; + + EVP_PKEY* evp = key->evp; + EVP_PKEY_up_ref(evp); + return evp; } diff --git a/libfreerdp/crypto/privatekey.h b/libfreerdp/crypto/privatekey.h index 900445ce4..1d3b7d971 100644 --- a/libfreerdp/crypto/privatekey.h +++ b/libfreerdp/crypto/privatekey.h @@ -35,7 +35,14 @@ extern "C" FREERDP_LOCAL const rdpCertInfo* freerdp_key_get_info(const rdpPrivateKey* key); FREERDP_LOCAL const BYTE* freerdp_key_get_exponent(const rdpPrivateKey* key, size_t* plength); + /** \brief returns a pointer to a RSA structure. + * Call RSA_free when done. + */ FREERDP_LOCAL RSA* freerdp_key_get_RSA(const rdpPrivateKey* key); + + /** \brief returns a pointer to a EVP_PKEY structure. + * Call EVP_PKEY_free when done. + */ FREERDP_LOCAL EVP_PKEY* freerdp_key_get_evp_pkey(const rdpPrivateKey* key); FREERDP_LOCAL extern const rdpPrivateKey* priv_key_tssk;