1 /* 2 * Copyright (c) 2010, 2016, 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 java.security.Provider; 24 import java.security.Security; 25 26 public class TestJSSE { 27 28 private static final String LOCAL_IP = "127.0.0.1"; 29 30 public static void main(String... args) throws Exception { 31 // reset the security property to make sure that the algorithms 32 // and keys used in this test are not disabled. 33 Security.setProperty("jdk.tls.disabledAlgorithms", ""); 34 35 // enable debug output 36 System.setProperty("javax.net.debug", "ssl,record"); 37 38 String srvProtocol = System.getProperty("SERVER_PROTOCOL"); 39 String clnProtocol = System.getProperty("CLIENT_PROTOCOL"); 40 String cipher = System.getProperty("CIPHER"); 41 if (srvProtocol == null || clnProtocol == null || cipher == null) { 42 throw new IllegalArgumentException("Incorrect parameters"); 43 } 44 45 System.out.println("ServerProtocol = " + srvProtocol); 46 System.out.println("ClientProtocol = " + clnProtocol); 47 System.out.println("Cipher = " + cipher); 48 49 try (CipherTestUtils.Server srv = server(srvProtocol, cipher, args)) { 50 client(srv.getPort(), clnProtocol, cipher, args); 51 } 52 } 53 54 public static void client(int port, String protocols, String cipher, 55 String... exceptions) throws Exception { 56 57 String expectedExcp = exceptions.length >= 1 ? exceptions[0] : null; 58 59 System.out.println("This is client"); 60 System.out.println("Testing protocol: " + protocols); 61 System.out.println("Testing cipher : " + cipher); 62 63 CipherTestUtils.mainClient( 64 new JSSEFactory(LOCAL_IP, protocols, cipher, "Client JSSE"), 65 port, expectedExcp); 66 } 67 68 public static CipherTestUtils.Server server(String protocol, 69 String cipher, String... exceptions) throws Exception { 70 71 String expectedExcp = exceptions.length >= 1 ? exceptions[0] : null; 72 73 System.out.println("This is server"); 74 System.out.println("Testing protocol: " + protocol); 75 System.out.println("Testing cipher : " + cipher); 76 77 return CipherTestUtils.mainServer( 78 new JSSEFactory(null, protocol, cipher, "Server JSSE"), 79 expectedExcp); 80 } 81 82 private static class JSSEFactory extends CipherTestUtils.PeerFactory { 83 84 private final String cipher; 85 private final String protocol; 86 private final String host; 87 private final String name; 88 89 JSSEFactory(String host, String protocol, String cipher, String name) { 90 this.cipher = cipher; 91 this.protocol = protocol; 92 this.host = host; 93 this.name = name; 94 } 95 96 @Override 97 String getName() { 98 return name; 99 } 100 101 @Override 102 String getTestedCipher() { 103 return cipher; 104 } 105 106 @Override 107 String getTestedProtocol() { 108 return protocol; 109 } 110 111 @Override 112 CipherTestUtils.Client newClient(CipherTestUtils cipherTest, int port) 113 throws Exception { 114 return new JSSEClient(cipherTest, host, port, protocol, cipher); 115 } 116 117 @Override 118 CipherTestUtils.Server newServer(CipherTestUtils cipherTest, int port) 119 throws Exception { 120 return new JSSEServer(cipherTest, port, protocol, cipher); 121 } 122 } 123 }