Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/sanity/ciphersuites/SystemPropCipherSuitesOrder.java
38861 views
/*1* Copyright (c) 2019, 2020, 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*/22import java.util.Arrays;23import javax.net.ssl.SSLServerSocket;24import javax.net.ssl.SSLSocket;2526/*27* @test28* @bug 823472829* @library /javax/net/ssl/templates30* /javax/net/ssl/TLSCommon31* /lib/security32* @summary Test TLS ciphersuites order set through System properties33* @run main/othervm34* -Djdk.tls.client.cipherSuites=TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA38435* -Djdk.tls.server.cipherSuites=TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA25636* -Djdk.tls.client.protocols="TLSv1.3,TLSv1.2,TLSv1.1,TLSv1,SSLv3"37* SystemPropCipherSuitesOrder TLSv1.338* @run main/othervm39* -Djdk.tls.client.cipherSuites=TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA38440* -Djdk.tls.client.protocols="TLSv1.3,TLSv1.2,TLSv1.1,TLSv1,SSLv3"41* SystemPropCipherSuitesOrder TLSv1.342* @run main/othervm43* -Djdk.tls.server.cipherSuites=TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA38444* -Djdk.tls.client.protocols="TLSv1.3,TLSv1.2,TLSv1.1,TLSv1,SSLv3"45* SystemPropCipherSuitesOrder TLSv1.346* @run main/othervm47* -Djdk.tls.client.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38448* -Djdk.tls.server.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38449* SystemPropCipherSuitesOrder TLSv1.250* @run main/othervm51* -Djdk.tls.client.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38452* SystemPropCipherSuitesOrder TLSv1.253* @run main/othervm54* -Djdk.tls.server.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38455* SystemPropCipherSuitesOrder TLSv1.256* @run main/othervm57* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA58* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA59* SystemPropCipherSuitesOrder TLSv1.160* @run main/othervm61* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA62* SystemPropCipherSuitesOrder TLSv1.163* @run main/othervm64* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA65* SystemPropCipherSuitesOrder TLSv1.166* @run main/othervm67* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA68* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA69* SystemPropCipherSuitesOrder TLSv170* @run main/othervm71* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA72* SystemPropCipherSuitesOrder TLSv173* @run main/othervm74* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA75* SystemPropCipherSuitesOrder TLSv176*/77public class SystemPropCipherSuitesOrder extends SSLSocketTemplate {7879private final String protocol;80private static String[] servercipherSuites;81private static String[] clientcipherSuites;8283public static void main(String[] args) {84servercipherSuites85= toArray(System.getProperty("jdk.tls.server.cipherSuites"));86clientcipherSuites87= toArray(System.getProperty("jdk.tls.client.cipherSuites"));88System.out.printf("SYSTEM PROPERTIES: ServerProp:%s - ClientProp:%s%n",89Arrays.deepToString(servercipherSuites),90Arrays.deepToString(clientcipherSuites));9192try {93new SystemPropCipherSuitesOrder(args[0]).run();94} catch (Exception e) {95throw new RuntimeException(e);96}97}9899private SystemPropCipherSuitesOrder(String protocol) {100this.protocol = protocol;101// Re-enable protocol if disabled.102if (protocol.equals("TLSv1") || protocol.equals("TLSv1.1")) {103SecurityUtils.removeFromDisabledTlsAlgs(protocol);104}105}106107// Servers are configured before clients, increment test case after.108@Override109protected void configureClientSocket(SSLSocket socket) {110socket.setEnabledProtocols(new String[]{protocol});111}112113@Override114protected void configureServerSocket(SSLServerSocket serverSocket) {115serverSocket.setEnabledProtocols(new String[]{protocol});116}117118protected void runServerApplication(SSLSocket socket) throws Exception {119if (servercipherSuites != null) {120System.out.printf("SERVER: SystemProperty:%s - "121+ "getEnabledCipherSuites:%s%n",122Arrays.deepToString(servercipherSuites),123Arrays.deepToString(socket.getEnabledCipherSuites()));124}125if (servercipherSuites != null && !Arrays.equals(126servercipherSuites, socket.getEnabledCipherSuites())) {127throw new RuntimeException("Unmatched server side CipherSuite order");128}129super.runServerApplication(socket);130}131132protected void runClientApplication(SSLSocket socket) throws Exception {133if (clientcipherSuites != null) {134System.out.printf("CLIENT: SystemProperty:%s - "135+ "getEnabledCipherSuites:%s%n",136Arrays.deepToString(clientcipherSuites),137Arrays.deepToString(socket.getEnabledCipherSuites()));138}139if (clientcipherSuites != null && !Arrays.equals(clientcipherSuites,140socket.getEnabledCipherSuites())) {141throw new RuntimeException("Unmatched client side CipherSuite order");142}143super.runClientApplication(socket);144}145146private static String[] toArray(String prop) {147return (prop != null) ? prop.split(",") : null;148}149}150151152