Path: blob/master/test/jdk/sun/security/ssl/CipherSuite/DisabledCurve.java
41152 views
/*1* Copyright (c) 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*/2223/*24* @test25* @bug 824633026* @library /javax/net/ssl/templates /test/lib27* @run main/othervm -Djdk.tls.namedGroups="secp384r1"28DisabledCurve DISABLE_NONE PASS29* @run main/othervm -Djdk.tls.namedGroups="secp384r1"30DisabledCurve secp384r1 FAIL31*/32import java.security.Security;33import java.util.Arrays;34import javax.net.ssl.SSLSocket;35import javax.net.ssl.SSLServerSocket;36import javax.net.ssl.SSLContext;37import javax.net.ssl.SSLException;3839import jdk.test.lib.security.SecurityUtils;4041public class DisabledCurve extends SSLSocketTemplate {4243private static volatile int index;44private static final String[][][] protocols = {45{ { "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1" }, { "TLSv1.2" } },46{ { "TLSv1.2" }, { "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1" } },47{ { "TLSv1.2" }, { "TLSv1.2" } }, { { "TLSv1.1" }, { "TLSv1.1" } },48{ { "TLSv1" }, { "TLSv1" } } };4950protected SSLContext createClientSSLContext() throws Exception {51return createSSLContext(52new SSLSocketTemplate.Cert[] {53SSLSocketTemplate.Cert.CA_ECDSA_SECP384R1 },54new SSLSocketTemplate.Cert[] {55SSLSocketTemplate.Cert.EE_ECDSA_SECP384R1 },56getClientContextParameters());57}5859protected SSLContext createServerSSLContext() throws Exception {60return createSSLContext(61new SSLSocketTemplate.Cert[] {62SSLSocketTemplate.Cert.CA_ECDSA_SECP384R1 },63new SSLSocketTemplate.Cert[] {64SSLSocketTemplate.Cert.EE_ECDSA_SECP384R1 },65getServerContextParameters());66}6768@Override69protected void configureClientSocket(SSLSocket socket) {70String[] ps = protocols[index][0];7172System.out.print("Setting client protocol(s): ");73Arrays.stream(ps).forEachOrdered(System.out::print);74System.out.println();7576socket.setEnabledProtocols(ps);77}7879@Override80protected void configureServerSocket(SSLServerSocket serverSocket) {81String[] ps = protocols[index][1];8283System.out.print("Setting server protocol(s): ");84Arrays.stream(ps).forEachOrdered(System.out::print);85System.out.println();8687serverSocket.setEnabledProtocols(ps);88}8990public static void main(String[] args) throws Exception {91String expected = args[1];92String disabledName = ("DISABLE_NONE".equals(args[0]) ? "" : args[0]);93boolean disabled = false;94if (disabledName.equals("")) {95Security.setProperty("jdk.disabled.namedCurves", "");96} else {97disabled = true;98Security.setProperty("jdk.certpath.disabledAlgorithms", "secp384r1");99}100101// Re-enable TLSv1 and TLSv1.1 since test depends on it.102SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1");103104for (index = 0; index < protocols.length; index++) {105try {106(new DisabledCurve()).run();107if (expected.equals("FAIL")) {108throw new RuntimeException(109"Expected test to fail, but it passed");110}111} catch (SSLException | IllegalStateException ssle) {112if (expected.equals("FAIL") && disabled) {113System.out.println(114"Expected exception was thrown: TEST PASSED");115} else {116throw new RuntimeException(ssle);117}118119}120121}122}123}124125126