mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 11:23:26 +01:00
Merge pull request #5258
bb8eab24
epee: certificate generation fix, pkey deleted (Dusan Klinec)
This commit is contained in:
commit
1d1a02e9f9
@ -74,22 +74,23 @@ bool create_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
|
|||||||
{
|
{
|
||||||
MGINFO("Generating SSL certificate");
|
MGINFO("Generating SSL certificate");
|
||||||
pkey = EVP_PKEY_new();
|
pkey = EVP_PKEY_new();
|
||||||
openssl_pkey pkey_deleter{pkey};
|
|
||||||
if (!pkey)
|
if (!pkey)
|
||||||
{
|
{
|
||||||
MERROR("Failed to create new private key");
|
MERROR("Failed to create new private key");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openssl_pkey pkey_deleter{pkey};
|
||||||
RSA *rsa = RSA_generate_key(4096, RSA_F4, NULL, NULL);
|
RSA *rsa = RSA_generate_key(4096, RSA_F4, NULL, NULL);
|
||||||
if (!rsa)
|
if (!rsa)
|
||||||
{
|
{
|
||||||
MERROR("Error generating RSA private key");
|
MERROR("Error generating RSA private key");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (EVP_PKEY_assign_RSA(pkey, rsa) <= 0)
|
if (EVP_PKEY_assign_RSA(pkey, rsa) <= 0) // The RSA will be automatically freed when the EVP_PKEY structure is freed.
|
||||||
{
|
{
|
||||||
RSA_free(rsa);
|
|
||||||
MERROR("Error assigning RSA private key");
|
MERROR("Error assigning RSA private key");
|
||||||
|
RSA_free(rsa);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +118,7 @@ bool create_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
|
|||||||
X509_free(cert);
|
X509_free(cert);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
(void)pkey_deleter.release();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user