Path: blob/master/test/jdk/sun/security/ssl/X509KeyManager/CertificateAuthorities.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// SunJSSE does not support dynamic system properties, no way to re-use25// system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 820692531* @summary Support the "certificate_authorities" extension32* @library /javax/net/ssl/templates33* @run main/othervm CertificateAuthorities34* @run main/othervm -Djdk.tls.client.enableCAExtension=false35* CertificateAuthorities36* @run main/othervm -Djdk.tls.client.enableCAExtension=true37* CertificateAuthorities38*39* @run main/othervm CertificateAuthorities NEED_CLIENT_AUTH40* @run main/othervm -Djdk.tls.client.enableCAExtension=false41* CertificateAuthorities NEED_CLIENT_AUTH42* @run main/othervm -Djdk.tls.client.enableCAExtension=true43* CertificateAuthorities NEED_CLIENT_AUTH44*45* @run main/othervm CertificateAuthorities WANT_CLIENT_AUTH46* @run main/othervm -Djdk.tls.client.enableCAExtension=false47* CertificateAuthorities WANT_CLIENT_AUTH48* @run main/othervm -Djdk.tls.client.enableCAExtension=true49* CertificateAuthorities WANT_CLIENT_AUTH50*/5152import javax.net.ssl.SSLServerSocket;5354public final class CertificateAuthorities extends SSLSocketTemplate {55final ClientAuthMode clientAuthMode;5657/*58* Run the test case.59*/60public static void main(String[] args) throws Exception {61CertificateAuthorities testCase;62if (args.length != 0) {63testCase = new CertificateAuthorities(64ClientAuthMode.valueOf(args[0]));65} else {66testCase = new CertificateAuthorities(67ClientAuthMode.NO_CLIENT_AUTH);68}6970testCase.run();71}7273CertificateAuthorities(ClientAuthMode mode) {74this.clientAuthMode = mode;75}7677@Override78protected void configureServerSocket(SSLServerSocket socket) {79if (clientAuthMode == ClientAuthMode.NEED_CLIENT_AUTH) {80socket.setNeedClientAuth(true);81} else if (clientAuthMode == ClientAuthMode.WANT_CLIENT_AUTH) {82socket.setWantClientAuth(true);83}84}8586private static enum ClientAuthMode {87NEED_CLIENT_AUTH,88WANT_CLIENT_AUTH,89NO_CLIENT_AUTH90}91}929394