1/*
2 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 4667976 8130181
27 * @modules java.base/com.sun.net.ssl
28 * @compile JavaxSSLContextImpl.java ComSSLContextImpl.java
29 *      JavaxTrustManagerFactoryImpl.java ComTrustManagerFactoryImpl.java
30 *      JavaxKeyManagerFactoryImpl.java ComKeyManagerFactoryImpl.java
31 * @run main/othervm ProviderTest
32 * @summary brokenness in the com.sun.net.ssl.SSLSecurity wrappers
33 */
34
35import java.security.*;
36import com.sun.net.ssl.*;
37
38public class ProviderTest {
39
40    public static void main(String args[]) throws Exception {
41        SSLContext sslc;
42        TrustManagerFactory tmf;
43        KeyManagerFactory kmf;
44
45        Provider extraProvider = new MyProvider();
46        Security.addProvider(extraProvider);
47        try {
48            System.out.println("getting a javax SSLContext");
49            sslc = SSLContext.getInstance("javax");
50            sslc.init(null, null, null);
51            System.out.println("\ngetting a com SSLContext");
52            sslc = SSLContext.getInstance("com");
53            sslc.init(null, null, null);
54
55            System.out.println("\ngetting a javax TrustManagerFactory");
56            tmf = TrustManagerFactory.getInstance("javax");
57            tmf.init((KeyStore) null);
58            System.out.println("\ngetting a com TrustManagerFactory");
59            tmf = TrustManagerFactory.getInstance("com");
60            tmf.init((KeyStore) null);
61
62            System.out.println("\ngetting a javax KeyManagerFactory");
63            kmf = KeyManagerFactory.getInstance("javax");
64            kmf.init((KeyStore) null, null);
65            System.out.println("\ngetting a com KeyManagerFactory");
66            kmf = KeyManagerFactory.getInstance("com");
67            kmf.init((KeyStore) null, null);
68        } finally {
69            Security.removeProvider(extraProvider.getName());
70        }
71    }
72}
73
74class MyProvider extends Provider {
75
76    private static String info = "Brad's provider";
77
78    /**
79     * Installs the JSSE provider.
80     */
81    public static synchronized void install()
82    {
83        /* nop. Remove this method in the future. */
84    }
85
86    public MyProvider()
87    {
88        super("BRAD", "1.0", info);
89
90        AccessController.doPrivileged(new java.security.PrivilegedAction() {
91            public Object run() {
92
93                put("SSLContext.javax", "JavaxSSLContextImpl");
94                put("SSLContext.com",   "ComSSLContextImpl");
95                put("TrustManagerFactory.javax",
96                                        "JavaxTrustManagerFactoryImpl");
97                put("TrustManagerFactory.com",
98                                        "ComTrustManagerFactoryImpl");
99                put("KeyManagerFactory.javax",
100                                        "JavaxKeyManagerFactoryImpl");
101                put("KeyManagerFactory.com",
102                                        "ComKeyManagerFactoryImpl");
103
104                return null;
105            }
106        });
107
108    }
109}
110