Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java
41161 views
1
/*
2
* Copyright (c) 2001, 2019, 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
// SunJSSE does not support dynamic system properties, no way to re-use
26
// system properties in samevm/agentvm mode.
27
//
28
29
/*
30
* @test
31
* @bug 4328195
32
* @summary Need to include the alternate subject DN for certs,
33
* https should check for this
34
* @library /javax/net/ssl/templates
35
* @run main/othervm ServerIdentityTest dnsstore localhost
36
* @run main/othervm ServerIdentityTest ipstore 127.0.0.1
37
*
38
* @author Yingxian Wang
39
*/
40
41
import java.io.InputStream;
42
import java.io.BufferedWriter;
43
import java.io.OutputStreamWriter;
44
import java.net.HttpURLConnection;
45
import java.net.InetAddress;
46
import java.net.Proxy;
47
import java.net.URL;
48
import java.net.UnknownHostException;
49
50
import javax.net.ssl.HttpsURLConnection;
51
import javax.net.ssl.SSLContext;
52
import javax.net.ssl.SSLSocket;
53
54
public final class ServerIdentityTest extends SSLSocketTemplate {
55
56
private static String keystore;
57
private static String hostname;
58
private static SSLContext context;
59
60
/*
61
* Run the test case.
62
*/
63
public static void main(String[] args) throws Exception {
64
// Get the customized arguments.
65
initialize(args);
66
67
(new ServerIdentityTest()).run();
68
}
69
70
ServerIdentityTest() throws UnknownHostException {
71
serverAddress = InetAddress.getByName(hostname);
72
}
73
74
@Override
75
protected boolean isCustomizedClientConnection() {
76
return true;
77
}
78
79
@Override
80
protected void runServerApplication(SSLSocket socket) throws Exception {
81
InputStream sslIS = socket.getInputStream();
82
sslIS.read();
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");
94
95
HttpURLConnection urlc = null;
96
InputStream is = null;
97
try {
98
urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
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
}
114
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();
136
HttpsURLConnection.setDefaultSSLSocketFactory(
137
context.getSocketFactory());
138
}
139
}
140
141