Skip to content

Commit

Permalink
Remove class hierarchy complexity (no client mode), and pass the JSSE…
Browse files Browse the repository at this point in the history
… session options to OpenSSL.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1731247 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmaucher committed Feb 19, 2016
1 parent d406edc commit 67d040c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 88 deletions.
4 changes: 2 additions & 2 deletions java/org/apache/tomcat/util/net/openssl/OpenSSLContext.java
Expand Up @@ -63,7 +63,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext {


private final SSLHostConfig sslHostConfig; private final SSLHostConfig sslHostConfig;
private final SSLHostConfigCertificate certificate; private final SSLHostConfigCertificate certificate;
private OpenSSLServerSessionContext sessionContext; private OpenSSLSessionContext sessionContext;


private final List<String> negotiableProtocols; private final List<String> negotiableProtocols;


Expand Down Expand Up @@ -373,7 +373,7 @@ public boolean verify(long ssl, byte[][] chain, String auth) {
SSLContext.setNpnProtos(ctx, protocolsArray, SSL.SSL_SELECTOR_FAILURE_NO_ADVERTISE); SSLContext.setNpnProtos(ctx, protocolsArray, SSL.SSL_SELECTOR_FAILURE_NO_ADVERTISE);
} }


sessionContext = new OpenSSLServerSessionContext(ctx); sessionContext = new OpenSSLSessionContext(ctx);
sslHostConfig.setOpenSslContext(Long.valueOf(ctx)); sslHostConfig.setOpenSslContext(Long.valueOf(ctx));
initialized = true; initialized = true;
} catch (Exception e) { } catch (Exception e) {
Expand Down

This file was deleted.

53 changes: 49 additions & 4 deletions java/org/apache/tomcat/util/net/openssl/OpenSSLSessionContext.java
Expand Up @@ -22,18 +22,19 @@
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSessionContext; import javax.net.ssl.SSLSessionContext;


import org.apache.tomcat.jni.SSL;
import org.apache.tomcat.jni.SSLContext; import org.apache.tomcat.jni.SSLContext;
import org.apache.tomcat.util.res.StringManager; import org.apache.tomcat.util.res.StringManager;


/** /**
* OpenSSL specific {@link SSLSessionContext} implementation. * OpenSSL specific {@link SSLSessionContext} implementation.
*/ */
public abstract class OpenSSLSessionContext implements SSLSessionContext { public class OpenSSLSessionContext implements SSLSessionContext {
private static final StringManager sm = StringManager.getManager(OpenSSLSessionContext.class); private static final StringManager sm = StringManager.getManager(OpenSSLSessionContext.class);
private static final Enumeration<byte[]> EMPTY = new EmptyEnumeration(); private static final Enumeration<byte[]> EMPTY = new EmptyEnumeration();


private final OpenSSLSessionStats stats; private final OpenSSLSessionStats stats;
final long context; private final long context;


OpenSSLSessionContext(long context) { OpenSSLSessionContext(long context) {
this.context = context; this.context = context;
Expand Down Expand Up @@ -67,13 +68,18 @@ public void setTicketKeys(byte[] keys) {
* *
* @param enabled {@code true} to enable caching, {@code false} to disable * @param enabled {@code true} to enable caching, {@code false} to disable
*/ */
public abstract void setSessionCacheEnabled(boolean enabled); public void setSessionCacheEnabled(boolean enabled) {
long mode = enabled ? SSL.SSL_SESS_CACHE_SERVER : SSL.SSL_SESS_CACHE_OFF;
SSLContext.setSessionCacheMode(context, mode);
}


/** /**
* @return {@code true} if caching of SSL sessions is enabled, {@code false} * @return {@code true} if caching of SSL sessions is enabled, {@code false}
* otherwise. * otherwise.
*/ */
public abstract boolean isSessionCacheEnabled(); public boolean isSessionCacheEnabled() {
return SSLContext.getSessionCacheMode(context) == SSL.SSL_SESS_CACHE_SERVER;
}


/** /**
* @return The statistics for this context. * @return The statistics for this context.
Expand All @@ -82,6 +88,45 @@ public OpenSSLSessionStats stats() {
return stats; return stats;
} }


@Override
public void setSessionTimeout(int seconds) {
if (seconds < 0) {
throw new IllegalArgumentException();
}
SSLContext.setSessionCacheTimeout(context, seconds);
}

@Override
public int getSessionTimeout() {
return (int) SSLContext.getSessionCacheTimeout(context);
}

@Override
public void setSessionCacheSize(int size) {
if (size < 0) {
throw new IllegalArgumentException();
}
SSLContext.setSessionCacheSize(context, size);
}

@Override
public int getSessionCacheSize() {
return (int) SSLContext.getSessionCacheSize(context);
}

/**
* Set the context within which session be reused (server side only)
* See <a href="http://www.openssl.org/docs/ssl/SSL_CTX_set_session_id_context.html">
* man SSL_CTX_set_session_id_context</a>
*
* @param sidCtx can be any kind of binary data, it is therefore possible to use e.g. the name
* of the application and/or the hostname and/or service name
* @return {@code true} if success, {@code false} otherwise.
*/
public boolean setSessionIdContext(byte[] sidCtx) {
return SSLContext.setSessionIdContext(context, sidCtx);
}

private static final class EmptyEnumeration implements Enumeration<byte[]> { private static final class EmptyEnumeration implements Enumeration<byte[]> {
@Override @Override
public boolean hasMoreElements() { public boolean hasMoreElements() {
Expand Down
4 changes: 3 additions & 1 deletion java/org/apache/tomcat/util/net/openssl/OpenSSLUtil.java
Expand Up @@ -98,6 +98,8 @@ public TrustManager[] getTrustManagers() throws Exception {


@Override @Override
public void configureSessionContext(SSLSessionContext sslSessionContext) { public void configureSessionContext(SSLSessionContext sslSessionContext) {
// do nothing. configuration is done in the init phase if (jsseUtil != null) {
jsseUtil.configureSessionContext(sslSessionContext);
}
} }
} }
3 changes: 3 additions & 0 deletions webapps/docs/changelog.xml
Expand Up @@ -110,6 +110,9 @@
<fix> <fix>
Bad processing of handshake errors in NIO2. (remm) Bad processing of handshake errors in NIO2. (remm)
</fix> </fix>
<fix>
Use JSSE session configuration options with OpenSSL. (remm)
</fix>
</changelog> </changelog>
</subsection> </subsection>
<subsection name="WebSocket"> <subsection name="WebSocket">
Expand Down

0 comments on commit 67d040c

Please sign in to comment.