aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-03-10 21:11:58 +0200
committerRiccardo Spagni <ric@spagni.net>2019-03-10 21:11:58 +0200
commit1d1a02e9f91c2a93eacb0bc89cbb5e5fddceca39 (patch)
tree5b5b6db4cd5f5fd41aed9a6c8c1b38992ae84787
parentMerge pull request #5257 (diff)
parentepee: certificate generation fix, pkey deleted (diff)
downloadmonero-1d1a02e9f91c2a93eacb0bc89cbb5e5fddceca39.tar.xz
Merge pull request #5258
bb8eab24 epee: certificate generation fix, pkey deleted (Dusan Klinec)
-rw-r--r--contrib/epee/src/net_ssl.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/contrib/epee/src/net_ssl.cpp b/contrib/epee/src/net_ssl.cpp
index 7154d4d33..eb0b0ad65 100644
--- a/contrib/epee/src/net_ssl.cpp
+++ b/contrib/epee/src/net_ssl.cpp
@@ -74,22 +74,23 @@ bool create_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
{
MGINFO("Generating SSL certificate");
pkey = EVP_PKEY_new();
- openssl_pkey pkey_deleter{pkey};
if (!pkey)
{
MERROR("Failed to create new private key");
return false;
}
+
+ openssl_pkey pkey_deleter{pkey};
RSA *rsa = RSA_generate_key(4096, RSA_F4, NULL, NULL);
if (!rsa)
{
MERROR("Error generating RSA private key");
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");
+ RSA_free(rsa);
return false;
}
@@ -117,6 +118,7 @@ bool create_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
X509_free(cert);
return false;
}
+ (void)pkey_deleter.release();
return true;
}