ASF Bugzilla – Attachment 31080 Details for
Bug 55801
Add ability to provide custom SSLContext for websocket client
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Corrected patch
WsWebSocketContainer.patch (text/plain), 5.18 KB, created by
Maciej Lypik
on 2013-11-27 09:17:28 UTC
(
hide
)
Description:
Corrected patch
Filename:
MIME Type:
Creator:
Maciej Lypik
Created:
2013-11-27 09:17:28 UTC
Size:
5.18 KB
patch
obsolete
>Index: java/org/apache/tomcat/websocket/WsWebSocketContainer.java >=================================================================== >--- java/org/apache/tomcat/websocket/WsWebSocketContainer.java (revision 1545953) >+++ java/org/apache/tomcat/websocket/WsWebSocketContainer.java (working copy) >@@ -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. >+ */ >+ public static final String SSL_CONTEXT_PROPERTY = >+ "org.apache.tomcat.websocket.SSL_CONTEXT"; > > /** > * Property name to set to configure the timeout (in milliseconds) when >@@ -671,42 +678,52 @@ > throws DeploymentException { > > try { >- // Create the SSL Context >- SSLContext sslContext = SSLContext.getInstance("TLS"); >+ // SSL Context >+ SSLContext sslContextValue = (SSLContext) userProperties >+ .get(SSL_CONTEXT_PROPERTY); >+ >+ SSLContext sslContext; > >- // 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 (sslContextValue != null) { >+ sslContext = sslContextValue; >+ } else { >+ 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(); >Index: webapps/docs/web-socket-howto.xml >=================================================================== >--- webapps/docs/web-socket-howto.xml (revision 1545953) >+++ webapps/docs/web-socket-howto.xml (working copy) >@@ -128,8 +128,13 @@ > <li><code>org.apache.tomcat.websocket.SSL_PROTOCOLS</code></li> > <li><code>org.apache.tomcat.websocket.SSL_TRUSTSTORE</code></li> > <li><code>org.apache.tomcat.websocket.SSL_TRUSTSTORE_PWD</code></li> >+ <li><code>org.apache.tomcat.websocket.SSL_CONTEXT</code></li> > </ul> > <p>The default truststore password is <code>changeit</code>.</p> >+ >+<p>Using <code>SSL_CONTEXT</code> property it is possible to provide custom >+ SSLContext for WebSocket client. If this property is set, <code>SSL_TRUSTSTORE >+ </code> will be ignored.</p> > </section> > > <section name="Deprecated proprietary API">
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 55801
:
31059
| 31080