Skip to content

Commit

Permalink
epee: certificate generation fix, pkey deleted
Browse files Browse the repository at this point in the history
- pkey gets deleted by the pkey_deleter but the caller tries to serialize it which causes errors as the memory is freed
  • Loading branch information
ph4r05 committed Mar 10, 2019
1 parent d281b81 commit bb8eab2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions contrib/epee/src/net_ssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -117,6 +118,7 @@ bool create_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
X509_free(cert);
return false;
}
(void)pkey_deleter.release();
return true;
}

Expand Down

0 comments on commit bb8eab2

Please sign in to comment.