You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2018/11/02 18:49:56 UTC

svn commit: r1845619 - /tomcat/tc8.5.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java

Author: markt
Date: Fri Nov  2 18:49:55 2018
New Revision: 1845619

URL: http://svn.apache.org/viewvc?rev=1845619&view=rev
Log:
Java 7 doesn't use TLS v1.2 by default. Make sure the client does for these tests.

Modified:
    tomcat/tc8.5.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java

Modified: tomcat/tc8.5.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java?rev=1845619&r1=1845618&r2=1845619&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java (original)
+++ tomcat/tc8.5.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java Fri Nov  2 18:49:55 2018
@@ -16,11 +16,17 @@
  */
 package org.apache.tomcat.websocket;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
 import java.net.URI;
+import java.security.KeyStore;
 import java.util.Queue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
 import javax.websocket.ClientEndpointConfig;
 import javax.websocket.ContainerProvider;
 import javax.websocket.MessageHandler;
@@ -57,9 +63,10 @@ public class TestWebSocketFrameClientSSL
                 ContainerProvider.getWebSocketContainer();
         ClientEndpointConfig clientEndpointConfig =
                 ClientEndpointConfig.Builder.create().build();
+
         clientEndpointConfig.getUserProperties().put(
-                Constants.SSL_TRUSTSTORE_PROPERTY,
-                TesterSupport.CA_JKS);
+                Constants.SSL_CONTEXT_PROPERTY, createSSLContext());
+
         Session wsSession = wsContainer.connectToServer(
                 TesterProgrammaticEndpoint.class,
                 clientEndpointConfig,
@@ -104,9 +111,10 @@ public class TestWebSocketFrameClientSSL
                 ContainerProvider.getWebSocketContainer();
         ClientEndpointConfig clientEndpointConfig =
                 ClientEndpointConfig.Builder.create().build();
+
         clientEndpointConfig.getUserProperties().put(
-                Constants.SSL_TRUSTSTORE_PROPERTY,
-                TesterSupport.CA_JKS);
+                Constants.SSL_CONTEXT_PROPERTY, createSSLContext());
+
         Session wsSession = wsContainer.connectToServer(
                 TesterProgrammaticEndpoint.class,
                 clientEndpointConfig,
@@ -150,4 +158,26 @@ public class TestWebSocketFrameClientSSL
         // Close the client session.
         wsSession.close();
     }
+
+
+    private SSLContext createSSLContext() throws Exception {
+        // Create the SSL Context
+        // Java 7 doesn't default to TLSv1.2 but the tests do
+        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
+
+        // Trust store
+        File keyStoreFile = new File(TesterSupport.CA_JKS);
+        KeyStore ks = KeyStore.getInstance("JKS");
+        try (InputStream is = new FileInputStream(keyStoreFile)) {
+            ks.load(is, Constants.SSL_TRUSTSTORE_PWD_DEFAULT.toCharArray());
+        }
+
+        TrustManagerFactory tmf = TrustManagerFactory.getInstance(
+                TrustManagerFactory.getDefaultAlgorithm());
+        tmf.init(ks);
+
+        sslContext.init(null, tmf.getTrustManagers(), null);
+
+        return sslContext;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org