Skip to content

Commit

Permalink
Allow using SSLImplementationName configuration option with JSSE, sin…
Browse files Browse the repository at this point in the history
…ce it turns out SSLContext cannot be extended except by using JCE. In practical terms, this allows using an alternate SSL engine implementation without having to change additional things in Tomcat.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1676722 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmaucher committed Apr 29, 2015
1 parent 5ba80e8 commit b6fc4aa
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 8 deletions.
1 change: 0 additions & 1 deletion java/org/apache/tomcat/util/net/AbstractJsseEndpoint.java
Expand Up @@ -21,7 +21,6 @@
import java.util.Map;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSessionContext;
Expand Down
48 changes: 48 additions & 0 deletions java/org/apache/tomcat/util/net/SSLContext.java
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.tomcat.util.net;

import java.security.KeyManagementException;
import java.security.SecureRandom;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.TrustManager;

/**
* This interface is needed to override the default SSLContext class
* to allow SSL implementation pluggability without having to use JCE. With
* regular JSSE it will do nothing but delegate to the SSLContext.
*/
public interface SSLContext {

public abstract void init(KeyManager[] kms, TrustManager[] tms,
SecureRandom sr) throws KeyManagementException;

public abstract SSLSessionContext getServerSessionContext();

public abstract SSLEngine createSSLEngine();

public abstract SSLServerSocketFactory getServerSocketFactory();

public abstract SSLParameters getSupportedSSLParameters();

}
1 change: 0 additions & 1 deletion java/org/apache/tomcat/util/net/SSLUtil.java
Expand Up @@ -17,7 +17,6 @@
package org.apache.tomcat.util.net;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.TrustManager;

Expand Down
66 changes: 66 additions & 0 deletions java/org/apache/tomcat/util/net/jsse/JSSESSLContext.java
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.tomcat.util.net.jsse;

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.TrustManager;

import org.apache.tomcat.util.net.SSLContext;

class JSSESSLContext implements SSLContext {

private javax.net.ssl.SSLContext context;
JSSESSLContext(String protocol) throws NoSuchAlgorithmException {
context = javax.net.ssl.SSLContext.getInstance(protocol);
}

@Override
public void init(KeyManager[] kms, TrustManager[] tms, SecureRandom sr)
throws KeyManagementException {
context.init(kms, tms, sr);
}

@Override
public SSLSessionContext getServerSessionContext() {
return context.getServerSessionContext();
}

@Override
public SSLEngine createSSLEngine() {
return context.createSSLEngine();
}

@Override
public SSLServerSocketFactory getServerSocketFactory() {
return context.getServerSocketFactory();
}

@Override
public SSLParameters getSupportedSSLParameters() {
return context.getSupportedSSLParameters();
}

}
10 changes: 4 additions & 6 deletions java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java
Expand Up @@ -46,7 +46,6 @@
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSessionContext;
Expand All @@ -58,6 +57,7 @@
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.net.AbstractEndpoint;
import org.apache.tomcat.util.net.Constants;
import org.apache.tomcat.util.net.SSLContext;
import org.apache.tomcat.util.net.SSLHostConfig;
import org.apache.tomcat.util.net.SSLUtil;
import org.apache.tomcat.util.net.jsse.openssl.OpenSSLCipherConfigurationParser;
Expand Down Expand Up @@ -107,9 +107,9 @@ public JSSESocketFactory (AbstractEndpoint<?> endpoint, SSLHostConfig sslHostCon
sslProtocol = defaultProtocol;
}

SSLContext context;
javax.net.ssl.SSLContext context;
try {
context = SSLContext.getInstance(sslProtocol);
context = javax.net.ssl.SSLContext.getInstance(sslProtocol);
context.init(null, null, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
// This is fatal for the connector so throw an exception to prevent
Expand Down Expand Up @@ -376,9 +376,7 @@ public SSLContext createSSLContext() throws Exception {
protocol = defaultProtocol;
}

SSLContext context = SSLContext.getInstance(protocol);

return context;
return new JSSESSLContext(protocol);
}

@Override
Expand Down

0 comments on commit b6fc4aa

Please sign in to comment.