Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/net/ssl/SSLSecurity/ProviderTest.java
38867 views
/*1* Copyright (c) 2002, 2013, 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 466797626* @compile JavaxSSLContextImpl.java ComSSLContextImpl.java27* JavaxTrustManagerFactoryImpl.java ComTrustManagerFactoryImpl.java28* JavaxKeyManagerFactoryImpl.java ComKeyManagerFactoryImpl.java29* @run main/othervm ProviderTest30* @summary brokenness in the com.sun.net.ssl.SSLSecurity wrappers31*/3233import java.security.*;34import com.sun.net.ssl.*;3536public class ProviderTest {3738public static void main(String args[]) throws Exception {39SSLContext sslc;40TrustManagerFactory tmf;41KeyManagerFactory kmf;4243Provider extraProvider = new MyProvider();44Security.addProvider(extraProvider);45try {46System.out.println("getting a javax SSLContext");47sslc = SSLContext.getInstance("javax");48sslc.init(null, null, null);49System.out.println("\ngetting a com SSLContext");50sslc = SSLContext.getInstance("com");51sslc.init(null, null, null);5253System.out.println("\ngetting a javax TrustManagerFactory");54tmf = TrustManagerFactory.getInstance("javax");55tmf.init((KeyStore) null);56System.out.println("\ngetting a com TrustManagerFactory");57tmf = TrustManagerFactory.getInstance("com");58tmf.init((KeyStore) null);5960System.out.println("\ngetting a javax KeyManagerFactory");61kmf = KeyManagerFactory.getInstance("javax");62kmf.init((KeyStore) null, null);63System.out.println("\ngetting a com KeyManagerFactory");64kmf = KeyManagerFactory.getInstance("com");65kmf.init((KeyStore) null, null);66} finally {67Security.removeProvider(extraProvider.getName());68}69}70}7172class MyProvider extends Provider {7374private static String info = "Brad's provider";7576/**77* Installs the JSSE provider.78*/79public static synchronized void install()80{81/* nop. Remove this method in the future. */82}8384public MyProvider()85{86super("BRAD", 1.0, info);8788AccessController.doPrivileged(new java.security.PrivilegedAction() {89public Object run() {9091put("SSLContext.javax", "JavaxSSLContextImpl");92put("SSLContext.com", "ComSSLContextImpl");93put("TrustManagerFactory.javax",94"JavaxTrustManagerFactoryImpl");95put("TrustManagerFactory.com",96"ComTrustManagerFactoryImpl");97put("KeyManagerFactory.javax",98"JavaxKeyManagerFactoryImpl");99put("KeyManagerFactory.com",100"ComKeyManagerFactoryImpl");101102return null;103}104});105106}107}108109110