Path: blob/master/test/jdk/sun/security/ssl/SSLSocketImpl/DisableExtensions.java
41152 views
/*1* Copyright (c) 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 821763326* @library /javax/net/ssl/templates27* @summary Configurable extensions with system properties28* @run main/othervm DisableExtensions supported_versions TLSv1.3 fail29* @run main/othervm DisableExtensions supported_versions TLSv1.230*/3132import javax.net.ssl.SSLSocket;33import javax.net.ssl.SSLException;3435public class DisableExtensions extends SSLSocketTemplate {3637private final String[] protocols;3839public DisableExtensions(String[] protocols) {40this.protocols = protocols;41}4243@Override44protected void configureClientSocket(SSLSocket socket) {45socket.setEnabledProtocols(protocols);46}4748// Run the test case.49//50// Check that the extension could be disabled, and the impact may be51// different for different protocols.52public static void main(String[] args) throws Exception {53System.setProperty("jdk.tls.client.disableExtensions", args[0]);5455boolean shouldSuccess = (args.length != 3);5657try {58(new DisableExtensions(new String[] {args[1]})).run();59} catch (SSLException | IllegalStateException ssle) {60if (shouldSuccess) {61throw new RuntimeException(62"The extension " + args[0] + " is disabled");63}6465return;66}6768if (!shouldSuccess) {69throw new RuntimeException(70"The extension " + args[0] +71" should be disabled and the connection should fail");72}73}74}757677