author | sundar |
Mon, 16 May 2016 14:50:43 +0530 | |
changeset 37951 | ce2744a0f1a7 |
parent 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29615
b0057b63b4e7
8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents:
29097
diff
changeset
|
2 |
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4387882 4451038 |
|
27 |
* @summary Need to revisit the javadocs for JSSE, especially the |
|
28 |
* promoted classes, and HttpsURLConnection.getCipherSuite throws |
|
29 |
* NullPointerException |
|
30820 | 30 |
* @modules java.base/com.sun.net.ssl |
31 |
* java.base/com.sun.net.ssl.internal.www.protocol.https |
|
10328 | 32 |
* @run main/othervm ComURLNulls |
33 |
* |
|
34 |
* SunJSSE does not support dynamic system properties, no way to re-use |
|
35 |
* system properties in samevm/agentvm mode. |
|
2 | 36 |
* @author Brad Wetmore |
37 |
*/ |
|
38 |
||
39 |
import java.net.*; |
|
40 |
import java.io.*; |
|
41 |
import javax.net.ssl.*; |
|
42 |
import com.sun.net.ssl.HttpsURLConnection; |
|
10328 | 43 |
import com.sun.net.ssl.HostnameVerifier; |
2 | 44 |
|
45 |
/* |
|
46 |
* Tests that the com null argument changes made it in ok. |
|
47 |
*/ |
|
48 |
||
49 |
public class ComURLNulls { |
|
50 |
||
29097 | 51 |
private static class ComSunHTTPSHandlerFactory implements URLStreamHandlerFactory { |
52 |
private static String SUPPORTED_PROTOCOL = "https"; |
|
53 |
||
54 |
public URLStreamHandler createURLStreamHandler(String protocol) { |
|
55 |
if (!protocol.equalsIgnoreCase(SUPPORTED_PROTOCOL)) |
|
56 |
return null; |
|
57 |
||
58 |
return new com.sun.net.ssl.internal.www.protocol.https.Handler(); |
|
59 |
} |
|
60 |
} |
|
61 |
||
2 | 62 |
public static void main(String[] args) throws Exception { |
10328 | 63 |
HostnameVerifier reservedHV = |
64 |
HttpsURLConnection.getDefaultHostnameVerifier(); |
|
2 | 65 |
try { |
29097 | 66 |
URL.setURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory()); |
67 |
||
10328 | 68 |
/** |
69 |
* This test does not establish any connection to the specified |
|
70 |
* URL, hence a dummy URL is used. |
|
71 |
*/ |
|
72 |
URL foobar = new URL("https://example.com/"); |
|
73 |
||
74 |
HttpsURLConnection urlc = |
|
75 |
(HttpsURLConnection) foobar.openConnection(); |
|
2 | 76 |
|
10328 | 77 |
try { |
78 |
urlc.getCipherSuite(); |
|
79 |
} catch (IllegalStateException e) { |
|
80 |
System.out.print("Caught proper exception: "); |
|
81 |
System.out.println(e.getMessage()); |
|
82 |
} |
|
83 |
||
84 |
try { |
|
29615
b0057b63b4e7
8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents:
29097
diff
changeset
|
85 |
urlc.getServerCertificates(); |
10328 | 86 |
} catch (IllegalStateException e) { |
87 |
System.out.print("Caught proper exception: "); |
|
88 |
System.out.println(e.getMessage()); |
|
89 |
} |
|
2 | 90 |
|
10328 | 91 |
try { |
92 |
urlc.setDefaultHostnameVerifier(null); |
|
93 |
} catch (IllegalArgumentException e) { |
|
94 |
System.out.print("Caught proper exception: "); |
|
95 |
System.out.println(e.getMessage()); |
|
96 |
} |
|
97 |
||
98 |
try { |
|
99 |
urlc.setHostnameVerifier(null); |
|
100 |
} catch (IllegalArgumentException e) { |
|
101 |
System.out.print("Caught proper exception: "); |
|
102 |
System.out.println(e.getMessage()); |
|
103 |
} |
|
2 | 104 |
|
10328 | 105 |
try { |
106 |
urlc.setDefaultSSLSocketFactory(null); |
|
107 |
} catch (IllegalArgumentException e) { |
|
108 |
System.out.print("Caught proper exception: "); |
|
109 |
System.out.println(e.getMessage()); |
|
110 |
} |
|
111 |
||
112 |
try { |
|
113 |
urlc.setSSLSocketFactory(null); |
|
114 |
} catch (IllegalArgumentException e) { |
|
115 |
System.out.print("Caught proper exception"); |
|
116 |
System.out.println(e.getMessage()); |
|
117 |
} |
|
118 |
System.out.println("TESTS PASSED"); |
|
119 |
} finally { |
|
120 |
HttpsURLConnection.setDefaultHostnameVerifier(reservedHV); |
|
2 | 121 |
} |
122 |
} |
|
123 |
} |