Author: remy.maucherat(a)jboss.com
Date: 2013-12-09 06:40:09 -0500 (Mon, 09 Dec 2013)
New Revision: 2321
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
Log:
Port minor addition to allow replacing SSL context.
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2013-12-05
15:24:11 UTC (rev 2320)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2013-12-09
11:40:09 UTC (rev 2321)
@@ -87,6 +87,13 @@
public static final String SSL_TRUSTSTORE_PWD_PROPERTY =
"org.apache.tomcat.websocket.SSL_TRUSTSTORE_PWD";
public static final String SSL_TRUSTSTORE_PWD_DEFAULT = "changeit";
+ /**
+ * Property name to set to configure used SSLContext. The value should be an
+ * instance of SSLContext. If this property is present, the SSL_TRUSTSTORE*
+ * properties are ignored.
+ */
+ public static final String SSL_CONTEXT_PROPERTY =
+ "org.apache.tomcat.websocket.SSL_CONTEXT";
/**
* Property name to set to configure the timeout (in milliseconds) when
@@ -645,42 +652,48 @@
throws DeploymentException {
try {
- // Create the SSL Context
- SSLContext sslContext = SSLContext.getInstance("TLS");
+ // See if a custom SSLContext has been provided
+ SSLContext sslContext =
+ (SSLContext) userProperties.get(SSL_CONTEXT_PROPERTY);
- // Trust store
- String sslTrustStoreValue =
- (String) userProperties.get(SSL_TRUSTSTORE_PROPERTY);
- if (sslTrustStoreValue != null) {
- String sslTrustStorePwdValue = (String) userProperties.get(
- SSL_TRUSTSTORE_PWD_PROPERTY);
- if (sslTrustStorePwdValue == null) {
- sslTrustStorePwdValue = SSL_TRUSTSTORE_PWD_DEFAULT;
- }
+ if (sslContext == null) {
+ // Create the SSL Context
+ sslContext = SSLContext.getInstance("TLS");
- File keyStoreFile = new File(sslTrustStoreValue);
- KeyStore ks = KeyStore.getInstance("JKS");
- InputStream is = null;
- try {
- is = new FileInputStream(keyStoreFile);
- ks.load(is, sslTrustStorePwdValue.toCharArray());
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException ioe) {
- // Ignore
+ // Trust store
+ String sslTrustStoreValue =
+ (String) userProperties.get(SSL_TRUSTSTORE_PROPERTY);
+ if (sslTrustStoreValue != null) {
+ String sslTrustStorePwdValue = (String) userProperties.get(
+ SSL_TRUSTSTORE_PWD_PROPERTY);
+ if (sslTrustStorePwdValue == null) {
+ sslTrustStorePwdValue = SSL_TRUSTSTORE_PWD_DEFAULT;
+ }
+
+ File keyStoreFile = new File(sslTrustStoreValue);
+ KeyStore ks = KeyStore.getInstance("JKS");
+ InputStream is = null;
+ try {
+ is = new FileInputStream(keyStoreFile);
+ ks.load(is, sslTrustStorePwdValue.toCharArray());
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException ioe) {
+ // Ignore
+ }
}
}
- }
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(
- TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(ks);
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(
+ TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(ks);
- sslContext.init(null, tmf.getTrustManagers(), null);
- } else {
- sslContext.init(null, null, null);
+ sslContext.init(null, tmf.getTrustManagers(), null);
+ } else {
+ sslContext.init(null, null, null);
+ }
}
SSLEngine engine = sslContext.createSSLEngine();
Show replies by date