From ef35ebc6dd68b8921b2079bcef978731c653700a Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Wed, 22 Feb 2023 01:36:29 +0800 Subject: [PATCH] Remove OpenSSL 3 deprecated RSA functions. --- src/protocol/MySQLMessage.cc | 38 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/protocol/MySQLMessage.cc b/src/protocol/MySQLMessage.cc index e5078b93..d163a2de 100644 --- a/src/protocol/MySQLMessage.cc +++ b/src/protocol/MySQLMessage.cc @@ -574,40 +574,32 @@ int MySQLRSAAuthRequest::rsa_encrypt(void *ctx) int MySQLRSAAuthRequest::encode(struct iovec vectors[], int max) { - RSA *rsa; BIO *bio; - - bio = BIO_new_mem_buf(public_key_.c_str(), public_key_.size()); - if (!bio) - return -1; - - rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL); - BIO_free(bio); - if (!rsa) - return -1; - - EVP_PKEY_CTX *pkey_ctx; EVP_PKEY *pkey; + EVP_PKEY_CTX *pkey_ctx; int ret = -1; - pkey = EVP_PKEY_new(); - if (pkey) + bio = BIO_new_mem_buf(public_key_.c_str(), public_key_.size()); + if (bio) { - EVP_PKEY_assign_RSA(pkey, rsa); - pkey_ctx = EVP_PKEY_CTX_new(pkey, NULL); - if (pkey_ctx) + pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL); + if (pkey) { - ret = rsa_encrypt(pkey_ctx); - EVP_PKEY_CTX_free(pkey_ctx); + pkey_ctx = EVP_PKEY_CTX_new(pkey, NULL); + if (pkey_ctx) + { + ret = rsa_encrypt(pkey_ctx); + EVP_PKEY_CTX_free(pkey_ctx); + } + + EVP_PKEY_free(pkey); } - EVP_PKEY_free(pkey); + BIO_free(bio); } - else - RSA_free(rsa); if (ret < 0) - return -1; + return ret; return MySQLMessage::encode(vectors, max); }