Correctly delete SelfSignedCertificate once done with it.

Motivation:

In OpenSsl init code we create a SelfSignedCertificate which we not explicitly delete. This can lead to have the deletion delayed.

Modifications:

Delete the SelfSignedCertificate once done with it.

Result:

Fixes [#6716]
This commit is contained in:
Norman Maurer 2017-05-08 19:57:26 +02:00
parent 63f5cdb0d5
commit ec935c5a7b

View File

@ -122,6 +122,7 @@ public final class OpenSsl {
final long sslCtx = SSLContext.make(SSL.SSL_PROTOCOL_ALL, SSL.SSL_MODE_SERVER);
long privateKeyBio = 0;
long certBio = 0;
SelfSignedCertificate cert = null;
try {
SSLContext.setCipherSuite(sslCtx, "ALL");
final long ssl = SSL.newSSL(sslCtx, true);
@ -140,7 +141,7 @@ public final class OpenSsl {
logger.debug("Hostname Verification not supported.");
}
try {
SelfSignedCertificate cert = new SelfSignedCertificate();
cert = new SelfSignedCertificate();
certBio = ReferenceCountedOpenSslContext.toBIO(cert.cert());
SSL.setCertificateChainBio(ssl, certBio, false);
supportsKeyManagerFactory = true;
@ -166,6 +167,9 @@ public final class OpenSsl {
if (certBio != 0) {
SSL.freeBIO(certBio);
}
if (cert != null) {
cert.delete();
}
}
} finally {
SSLContext.free(sslCtx);