Skip to content

Commit

Permalink
Using the finalizer for sensitive operations is not a good idea since…
Browse files Browse the repository at this point in the history
… nothing in Tomcat retains the SSLContext instances after using them to init.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1719106 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmaucher committed Dec 10, 2015
1 parent a464381 commit f936a46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 2 additions & 0 deletions java/org/apache/tomcat/util/net/SSLContext.java
Expand Up @@ -37,6 +37,8 @@ public interface SSLContext {
public void init(KeyManager[] kms, TrustManager[] tms,
SecureRandom sr) throws KeyManagementException;

public void destroy();

public SSLSessionContext getServerSessionContext();

public SSLEngine createSSLEngine();
Expand Down
4 changes: 4 additions & 0 deletions java/org/apache/tomcat/util/net/jsse/JSSESSLContext.java
Expand Up @@ -43,6 +43,10 @@ public void init(KeyManager[] kms, TrustManager[] tms, SecureRandom sr)
context.init(kms, tms, sr);
}

@Override
public void destroy() {
}

@Override
public SSLSessionContext getServerSessionContext() {
return context.getServerSessionContext();
Expand Down
24 changes: 9 additions & 15 deletions java/org/apache/tomcat/util/net/openssl/OpenSSLContext.java
Expand Up @@ -166,15 +166,20 @@ public OpenSSLContext(SSLHostConfig sslHostConfig, SSLHostConfigCertificate cert
throw new SSLException(sm.getString("openssl.errorSSLCtxInit"), e);
} finally {
if (!success) {
destroyPools();
destroy();
}
}
}

private void destroyPools() {
public synchronized void destroy() {
// Guard against multiple destroyPools() calls triggered by construction exception and finalize() later
if (aprPool != 0 && DESTROY_UPDATER.compareAndSet(this, 0, 1)) {
Pool.destroy(aprPool);
if (DESTROY_UPDATER.compareAndSet(this, 0, 1)) {
if (ctx != 0) {
SSLContext.free(ctx);
}
if (aprPool != 0) {
Pool.destroy(aprPool);
}
}
}

Expand Down Expand Up @@ -437,15 +442,4 @@ public SSLParameters getSupportedSSLParameters() {
throw new UnsupportedOperationException();
}

@Override
protected final void finalize() throws Throwable {
super.finalize();
synchronized (OpenSSLContext.class) {
if (ctx != 0) {
SSLContext.free(ctx);
}
}
//FIXME: this causes crashes in the testsuite
//destroyPools();
}
}

0 comments on commit f936a46

Please sign in to comment.