1 /** 2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it under 6 * the terms of the GNU General Public License version 2 only, as published by 7 * the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more 12 * details (a copy is included in the LICENSE file that accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 2 15 * along with this work; if not, write to the Free Software Foundation, Inc., 51 16 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA or 19 * visit www.oracle.com if you need additional information or have any 20 * questions. 21 */ 22 23 import static java.lang.System.out; 24 import java.security.Provider; 25 import java.security.Security; 26 27 /** 28 * @test 29 * @bug 8049429 30 * @library ../../../../lib/testlibrary/ 31 * @build jdk.testlibrary.Utils 32 * @compile CipherTestUtils.java JSSEClient.java JSSEServer.java 33 * @summary Test that all cipher suites work in all versions and all client 34 * authentication types. The way this is setup the server is stateless and 35 * all checking is done on the client side. 36 * @run main/othervm -DSERVER_PROTOCOL=SSLv3 37 * -DCLIENT_PROTOCOL=SSLv3 38 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 39 * @run main/othervm -DSERVER_PROTOCOL=TLSv1 40 * -DCLIENT_PROTOCOL=SSLv3,TLSv1,TLSv1.1,TLSv1.2 41 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 42 * @run main/othervm -DSERVER_PROTOCOL=TLSv1.1 43 * -DCLIENT_PROTOCOL=SSLv3,TLSv1,TLSv1.1,TLSv1.2 44 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 45 * @run main/othervm -DSERVER_PROTOCOL=TLSv1.2 46 * -DCLIENT_PROTOCOL=SSLv3,TLSv1,TLSv1.1,TLSv1.2 47 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 48 * @run main/othervm -DSERVER_PROTOCOL=SSLv3,TLSv1 49 * -DCLIENT_PROTOCOL=TLSv1 -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 50 * @run main/othervm -DSERVER_PROTOCOL=SSLv3,TLSv1,TLSv1.1 51 * -DCLIENT_PROTOCOL=TLSv1.1 -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 52 * @run main/othervm -DSERVER_PROTOCOL=SSLv3 53 * -DCLIENT_PROTOCOL=TLSv1.1,TLSv1.2 54 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 55 * TestJSSE javax.net.ssl.SSLHandshakeException 56 * @run main/othervm -DSERVER_PROTOCOL=TLSv1 57 * -DCLIENT_PROTOCOL=TLSv1.1,TLSv1.2 58 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 59 * TestJSSE javax.net.ssl.SSLHandshakeException 60 * @run main/othervm -DSERVER_PROTOCOL=SSLv3,TLSv1,TLSv1.1,TLSv1.2 61 * -DCLIENT_PROTOCOL=TLSv1.2 -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 62 * @run main/othervm -DSERVER_PROTOCOL=SSLv2Hello,SSLv3,TLSv1 63 * -DCLIENT_PROTOCOL=DEFAULT -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 64 * @run main/othervm -DSERVER_PROTOCOL=SSLv2Hello,SSLv3,TLSv1,TLSv1.1,TLSv1.2 65 * -DCLIENT_PROTOCOL=DEFAULT -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 66 * @run main/othervm -DSERVER_PROTOCOL=SSLv2Hello,SSLv3,TLSv1,TLSv1.1,TLSv1.2 67 * -DCLIENT_PROTOCOL=DEFAULT -Djdk.tls.client.protocols=TLSv1 68 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 TestJSSE 69 * @run main/othervm -DSERVER_PROTOCOL=SSLv2Hello,SSLv3,TLSv1 70 * -DCLIENT_PROTOCOL=DEFAULT -Djdk.tls.client.protocols=TLSv1.2 71 * -DCIPHER=SSL_RSA_WITH_RC4_128_MD5 72 * TestJSSE javax.net.ssl.SSLHandshakeException 73 * @key intermittent 74 * 75 */ 76 77 public class TestJSSE { 78 79 private static final String LOCAL_IP = "127.0.0.1"; 80 81 public static void main(String... args) throws Exception { 82 // reset the security property to make sure that the algorithms 83 // and keys used in this test are not disabled. 84 Security.setProperty("jdk.tls.disabledAlgorithms", ""); 85 86 String serverProtocol = System.getProperty("SERVER_PROTOCOL"); 87 String clientProtocol = System.getProperty("CLIENT_PROTOCOL"); 88 int port = jdk.testlibrary.Utils.getFreePort(); 89 String cipher = System.getProperty("CIPHER"); 90 if (serverProtocol == null 91 || clientProtocol == null 92 || cipher == null) { 93 throw new IllegalArgumentException("SERVER_PROTOCOL " 94 + "or CLIENT_PROTOCOL or CIPHER is missing"); 95 } 96 out.println("ServerProtocol =" + serverProtocol); 97 out.println("ClientProtocol =" + clientProtocol); 98 out.println("Cipher =" + cipher); 99 server(serverProtocol, cipher, port, args); 100 client(port, clientProtocol, cipher, args); 101 102 } 103 104 public static void client(int testPort, 105 String testProtocols, String testCipher, 106 String... exception) throws Exception { 107 String expectedException = exception.length >= 1 108 ? exception[0] : null; 109 out.println("========================================="); 110 out.println(" Testing - https://" + LOCAL_IP + ":" + testPort); 111 out.println(" Testing - Protocol : " + testProtocols); 112 out.println(" Testing - Cipher : " + testCipher); 113 Provider p = new sun.security.ec.SunEC(); 114 Security.insertProviderAt(p, 1); 115 try { 116 CipherTestUtils.main(new JSSEFactory(LOCAL_IP, 117 testPort, testProtocols, 118 testCipher, "client JSSE"), 119 "client", expectedException); 120 } catch (Exception e) { 121 throw new RuntimeException(e); 122 } 123 } 124 125 public static void server(String testProtocol, String testCipher, 126 int testPort, 127 String... exception) throws Exception { 128 String expectedException = exception.length >= 1 129 ? exception[0] : null; 130 out.println(" This is Server"); 131 out.println(" Testing Protocol: " + testProtocol); 132 out.println(" Testing Cipher: " + testCipher); 133 out.println(" Testing Port: " + testPort); 134 Provider p = new sun.security.ec.SunEC(); 135 Security.insertProviderAt(p, 1); 136 try { 137 CipherTestUtils.main(new JSSEFactory(null, testPort, 138 testProtocol, testCipher, "Server JSSE"), 139 "Server", expectedException); 140 } catch (Exception e) { 141 throw new RuntimeException(e); 142 } 143 } 144 145 private static class JSSEFactory extends CipherTestUtils.PeerFactory { 146 147 final String testedCipherSuite, testedProtocol, testHost; 148 final int testPort; 149 final String name; 150 151 JSSEFactory(String testHost, int testPort, String testedProtocol, 152 String testedCipherSuite, String name) { 153 this.testedCipherSuite = testedCipherSuite; 154 this.testedProtocol = testedProtocol; 155 this.testHost = testHost; 156 this.testPort = testPort; 157 this.name = name; 158 } 159 160 @Override 161 String getName() { 162 return name; 163 } 164 165 @Override 166 String getTestedCipher() { 167 return testedCipherSuite; 168 } 169 170 @Override 171 String getTestedProtocol() { 172 return testedProtocol; 173 } 174 175 @Override 176 CipherTestUtils.Client newClient(CipherTestUtils cipherTest) 177 throws Exception { 178 return new JSSEClient(cipherTest, testHost, testPort, 179 testedProtocol, testedCipherSuite); 180 } 181 182 @Override 183 CipherTestUtils.Server newServer(CipherTestUtils cipherTest) 184 throws Exception { 185 return new JSSEServer(cipherTest, testPort, 186 testedProtocol, testedCipherSuite); 187 } 188 } 189 }