Path: blob/master/test/jdk/javax/net/ssl/sanity/ciphersuites/SystemPropCipherSuitesOrder.java
41154 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;2526import jdk.test.lib.security.SecurityUtils;2728/*29* @test30* @bug 823472831* @library /javax/net/ssl/templates32* /javax/net/ssl/TLSCommon33* /test/lib34* @summary Test TLS ciphersuites order set through System properties35* @run main/othervm36* -Djdk.tls.client.cipherSuites=TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA38437* -Djdk.tls.server.cipherSuites=TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA25638* SystemPropCipherSuitesOrder TLSv1.339* @run main/othervm40* -Djdk.tls.client.cipherSuites=TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA38441* SystemPropCipherSuitesOrder TLSv1.342* @run main/othervm43* -Djdk.tls.server.cipherSuites=TLS_AES_128_GCM_SHA256,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_256_GCM_SHA38444* SystemPropCipherSuitesOrder TLSv1.345* @run main/othervm46* -Djdk.tls.client.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38447* -Djdk.tls.server.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38448* SystemPropCipherSuitesOrder TLSv1.249* @run main/othervm50* -Djdk.tls.client.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38451* SystemPropCipherSuitesOrder TLSv1.252* @run main/othervm53* -Djdk.tls.server.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38454* SystemPropCipherSuitesOrder TLSv1.255* @run main/othervm56* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA57* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA58* SystemPropCipherSuitesOrder TLSv1.159* @run main/othervm60* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA61* SystemPropCipherSuitesOrder TLSv1.162* @run main/othervm63* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA64* SystemPropCipherSuitesOrder TLSv1.165* @run main/othervm66* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA67* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA68* SystemPropCipherSuitesOrder TLSv169* @run main/othervm70* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA71* SystemPropCipherSuitesOrder TLSv172* @run main/othervm73* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA74* SystemPropCipherSuitesOrder TLSv175*/76public class SystemPropCipherSuitesOrder extends SSLSocketTemplate {7778private final String protocol;79private static String[] servercipherSuites;80private static String[] clientcipherSuites;8182public static void main(String[] args) {83servercipherSuites84= toArray(System.getProperty("jdk.tls.server.cipherSuites"));85clientcipherSuites86= toArray(System.getProperty("jdk.tls.client.cipherSuites"));87System.out.printf("SYSTEM PROPERTIES: ServerProp:%s - ClientProp:%s%n",88Arrays.deepToString(servercipherSuites),89Arrays.deepToString(clientcipherSuites));9091try {92new SystemPropCipherSuitesOrder(args[0]).run();93} catch (Exception e) {94throw new RuntimeException(e);95}96}9798private SystemPropCipherSuitesOrder(String protocol) {99this.protocol = protocol;100// Re-enable protocol if disabled.101if (protocol.equals("TLSv1") || protocol.equals("TLSv1.1")) {102SecurityUtils.removeFromDisabledTlsAlgs(protocol);103}104}105106// Servers are configured before clients, increment test case after.107@Override108protected void configureClientSocket(SSLSocket socket) {109socket.setEnabledProtocols(new String[]{protocol});110}111112@Override113protected void configureServerSocket(SSLServerSocket serverSocket) {114serverSocket.setEnabledProtocols(new String[]{protocol});115}116117protected void runServerApplication(SSLSocket socket) throws Exception {118if (servercipherSuites != null) {119System.out.printf("SERVER: SystemProperty:%s - "120+ "getEnabledCipherSuites:%s%n",121Arrays.deepToString(servercipherSuites),122Arrays.deepToString(socket.getEnabledCipherSuites()));123}124if (servercipherSuites != null && !Arrays.equals(125servercipherSuites, socket.getEnabledCipherSuites())) {126throw new RuntimeException("Unmatched server side CipherSuite order");127}128super.runServerApplication(socket);129}130131protected void runClientApplication(SSLSocket socket) throws Exception {132if (clientcipherSuites != null) {133System.out.printf("CLIENT: SystemProperty:%s - "134+ "getEnabledCipherSuites:%s%n",135Arrays.deepToString(clientcipherSuites),136Arrays.deepToString(socket.getEnabledCipherSuites()));137}138if (clientcipherSuites != null && !Arrays.equals(clientcipherSuites,139socket.getEnabledCipherSuites())) {140throw new RuntimeException("Unmatched client side CipherSuite order");141}142super.runClientApplication(socket);143}144145private static String[] toArray(String prop) {146return (prop != null) ? prop.split(",") : null;147}148}149150151