Path: blob/master/test/jdk/sun/security/ssl/CipherSuite/SupportedGroups.java
41152 views
/*1* Copyright (c) 2019, 2021, 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*/2223/*24* @test25* @bug 817127926* @library /javax/net/ssl/templates27* @summary Test TLS connection with each individual supported group28* @run main/othervm SupportedGroups x2551929* @run main/othervm SupportedGroups x44830* @run main/othervm SupportedGroups secp256r131* @run main/othervm SupportedGroups secp384r132* @run main/othervm SupportedGroups secp521r133* @run main/othervm SupportedGroups ffdhe204834* @run main/othervm SupportedGroups ffdhe307235* @run main/othervm SupportedGroups ffdhe409636* @run main/othervm SupportedGroups ffdhe614437* @run main/othervm SupportedGroups ffdhe819238*/39import java.net.InetAddress;40import java.util.Arrays;41import javax.net.ssl.SSLSocket;42import javax.net.ssl.SSLServerSocket;4344public class SupportedGroups extends SSLSocketTemplate {4546private static volatile int index;47private static final String[][][] protocols = {48{{"TLSv1.3"}, {"TLSv1.3"}},49{{"TLSv1.3", "TLSv1.2"}, {"TLSv1.2"}},50{{"TLSv1.2"}, {"TLSv1.3", "TLSv1.2"}},51{{"TLSv1.2"}, {"TLSv1.2"}}52};5354public SupportedGroups() {55this.serverAddress = InetAddress.getLoopbackAddress();56}5758// Servers are configured before clients, increment test case after.59@Override60protected void configureClientSocket(SSLSocket socket) {61String[] ps = protocols[index][0];6263System.out.print("Setting client protocol(s): ");64Arrays.stream(ps).forEachOrdered(System.out::print);65System.out.println();6667socket.setEnabledProtocols(ps);68}6970@Override71protected void configureServerSocket(SSLServerSocket serverSocket) {72String[] ps = protocols[index][1];7374System.out.print("Setting server protocol(s): ");75Arrays.stream(ps).forEachOrdered(System.out::print);76System.out.println();7778serverSocket.setEnabledProtocols(ps);79}8081/*82* Run the test case.83*/84public static void main(String[] args) throws Exception {85System.setProperty("jdk.tls.namedGroups", args[0]);8687for (index = 0; index < protocols.length; index++) {88(new SupportedGroups()).run();89}90}91}929394