author | dfuchs |
Thu, 12 Sep 2019 15:46:11 +0100 | |
changeset 58108 | 5302477c8285 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58108
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, 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 |
||
42464 | 24 |
// |
25 |
// SunJSSE does not support dynamic system properties, no way to re-use |
|
26 |
// system properties in samevm/agentvm mode. |
|
27 |
// |
|
28 |
||
2 | 29 |
/* |
30 |
* @test |
|
31 |
* @bug 4328195 |
|
32 |
* @summary Need to include the alternate subject DN for certs, |
|
33 |
* https should check for this |
|
41196
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
34 |
* @library /javax/net/ssl/templates |
42464 | 35 |
* @run main/othervm ServerIdentityTest dnsstore localhost |
36 |
* @run main/othervm ServerIdentityTest ipstore 127.0.0.1 |
|
10328 | 37 |
* |
2 | 38 |
* @author Yingxian Wang |
39 |
*/ |
|
40 |
||
42464 | 41 |
import java.io.InputStream; |
41196
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
42 |
import java.io.BufferedWriter; |
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
43 |
import java.io.OutputStreamWriter; |
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
44 |
import java.net.HttpURLConnection; |
58108
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
45 |
import java.net.InetAddress; |
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
46 |
import java.net.Proxy; |
41196
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
47 |
import java.net.URL; |
58108
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
48 |
import java.net.UnknownHostException; |
42668 | 49 |
|
41196
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
50 |
import javax.net.ssl.HttpsURLConnection; |
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
51 |
import javax.net.ssl.SSLContext; |
42464 | 52 |
import javax.net.ssl.SSLSocket; |
53 |
||
54 |
public final class ServerIdentityTest extends SSLSocketTemplate { |
|
2 | 55 |
|
42464 | 56 |
private static String keystore; |
57 |
private static String hostname; |
|
58 |
private static SSLContext context; |
|
2 | 59 |
|
42464 | 60 |
/* |
61 |
* Run the test case. |
|
62 |
*/ |
|
2 | 63 |
public static void main(String[] args) throws Exception { |
42464 | 64 |
// Get the customized arguments. |
65 |
initialize(args); |
|
66 |
||
67 |
(new ServerIdentityTest()).run(); |
|
68 |
} |
|
69 |
||
58108
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
70 |
ServerIdentityTest() throws UnknownHostException { |
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
71 |
serverAddress = InetAddress.getByName(hostname); |
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
72 |
} |
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
73 |
|
42464 | 74 |
@Override |
42466
321b4a747cec
8171003: A couple of JSSE tests have been failing after JDK-8170329
xuelei
parents:
42464
diff
changeset
|
75 |
protected boolean isCustomizedClientConnection() { |
42464 | 76 |
return true; |
77 |
} |
|
2 | 78 |
|
42464 | 79 |
@Override |
80 |
protected void runServerApplication(SSLSocket socket) throws Exception { |
|
42668 | 81 |
InputStream sslIS = socket.getInputStream(); |
82 |
sslIS.read(); |
|
42464 | 83 |
BufferedWriter bw = new BufferedWriter( |
84 |
new OutputStreamWriter(socket.getOutputStream())); |
|
85 |
bw.write("HTTP/1.1 200 OK\r\n\r\n\r\n"); |
|
86 |
bw.flush(); |
|
87 |
socket.getSession().invalidate(); |
|
88 |
} |
|
89 |
||
90 |
@Override |
|
91 |
protected void runClientApplication(int serverPort) throws Exception { |
|
92 |
URL url = new URL( |
|
93 |
"https://" + hostname + ":" + serverPort + "/index.html"); |
|
2 | 94 |
|
42464 | 95 |
HttpURLConnection urlc = null; |
96 |
InputStream is = null; |
|
97 |
try { |
|
58108
5302477c8285
8230858: Replace wildcard address with loopback or local host in tests - part 23
dfuchs
parents:
47216
diff
changeset
|
98 |
urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY); |
42464 | 99 |
is = urlc.getInputStream(); |
100 |
} finally { |
|
101 |
if (is != null) { |
|
102 |
is.close(); |
|
103 |
} |
|
104 |
if (urlc != null) { |
|
105 |
urlc.disconnect(); |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
@Override |
|
111 |
protected SSLContext createServerSSLContext() throws Exception { |
|
112 |
return context; |
|
113 |
} |
|
2 | 114 |
|
42464 | 115 |
@Override |
116 |
protected SSLContext createClientSSLContext() throws Exception { |
|
117 |
return context; |
|
118 |
} |
|
119 |
||
120 |
private static void initialize(String[] args) throws Exception { |
|
121 |
keystore = args[0]; |
|
122 |
hostname = args[1]; |
|
123 |
||
124 |
String password = "changeit"; |
|
125 |
String keyFilename = |
|
126 |
System.getProperty("test.src", ".") + "/" + keystore; |
|
127 |
String trustFilename = |
|
128 |
System.getProperty("test.src", ".") + "/" + keystore; |
|
129 |
||
130 |
System.setProperty("javax.net.ssl.keyStore", keyFilename); |
|
131 |
System.setProperty("javax.net.ssl.keyStorePassword", password); |
|
132 |
System.setProperty("javax.net.ssl.trustStore", trustFilename); |
|
133 |
System.setProperty("javax.net.ssl.trustStorePassword", password); |
|
134 |
||
135 |
context = SSLContext.getDefault(); |
|
41196
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
136 |
HttpsURLConnection.setDefaultSSLSocketFactory( |
240314163e51
8164591: sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java failed with SSLHandshakeException
asmotrak
parents:
23052
diff
changeset
|
137 |
context.getSocketFactory()); |
2 | 138 |
} |
139 |
} |