Path: blob/master/test/jdk/javax/net/ssl/TLS/TestJSSE.java
41152 views
/*1* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.security.Provider;24import java.security.Security;2526public class TestJSSE {2728private static final String LOCAL_IP = "127.0.0.1";2930public static void main(String... args) throws Exception {31// reset the security property to make sure that the algorithms32// and keys used in this test are not disabled.33Security.setProperty("jdk.tls.disabledAlgorithms", "");3435// enable debug output36System.setProperty("javax.net.debug", "ssl,record");3738String srvProtocol = System.getProperty("SERVER_PROTOCOL");39String clnProtocol = System.getProperty("CLIENT_PROTOCOL");40String cipher = System.getProperty("CIPHER");41if (srvProtocol == null || clnProtocol == null || cipher == null) {42throw new IllegalArgumentException("Incorrect parameters");43}4445System.out.println("ServerProtocol = " + srvProtocol);46System.out.println("ClientProtocol = " + clnProtocol);47System.out.println("Cipher = " + cipher);4849try (CipherTestUtils.Server srv = server(srvProtocol, cipher, args)) {50client(srv.getPort(), clnProtocol, cipher, args);51}52}5354public static void client(int port, String protocols, String cipher,55String... exceptions) throws Exception {5657String expectedExcp = exceptions.length >= 1 ? exceptions[0] : null;5859System.out.println("This is client");60System.out.println("Testing protocol: " + protocols);61System.out.println("Testing cipher : " + cipher);6263CipherTestUtils.mainClient(64new JSSEFactory(LOCAL_IP, protocols, cipher, "Client JSSE"),65port, expectedExcp);66}6768public static CipherTestUtils.Server server(String protocol,69String cipher, String... exceptions) throws Exception {7071String expectedExcp = exceptions.length >= 1 ? exceptions[0] : null;7273System.out.println("This is server");74System.out.println("Testing protocol: " + protocol);75System.out.println("Testing cipher : " + cipher);7677return CipherTestUtils.mainServer(78new JSSEFactory(null, protocol, cipher, "Server JSSE"),79expectedExcp);80}8182private static class JSSEFactory extends CipherTestUtils.PeerFactory {8384private final String cipher;85private final String protocol;86private final String host;87private final String name;8889JSSEFactory(String host, String protocol, String cipher, String name) {90this.cipher = cipher;91this.protocol = protocol;92this.host = host;93this.name = name;94}9596@Override97String getName() {98return name;99}100101@Override102String getTestedCipher() {103return cipher;104}105106@Override107String getTestedProtocol() {108return protocol;109}110111@Override112CipherTestUtils.Client newClient(CipherTestUtils cipherTest, int port)113throws Exception {114return new JSSEClient(cipherTest, host, port, protocol, cipher);115}116117@Override118CipherTestUtils.Server newServer(CipherTestUtils cipherTest, int port)119throws Exception {120return new JSSEServer(cipherTest, port, protocol, cipher);121}122}123}124125126