Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/TLSv11/GenericStreamCipher.java
38853 views
1
/*
2
* Copyright (c) 2010, 2015, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
* @test
28
* @bug 4873188
29
* @summary Support TLS 1.1
30
* @run main/othervm GenericStreamCipher
31
*
32
* SunJSSE does not support dynamic system properties, no way to re-use
33
* system properties in samevm/agentvm mode.
34
*
35
* @author Xuelei Fan
36
*/
37
38
import java.io.*;
39
import java.security.Security;
40
import javax.net.ssl.*;
41
42
public class GenericStreamCipher {
43
44
/*
45
* =============================================================
46
* Set the various variables needed for the tests, then
47
* specify what tests to run on each side.
48
*/
49
50
/*
51
* Should we run the client or server in a separate thread?
52
* Both sides can throw exceptions, but do you have a preference
53
* as to which side should be the main thread.
54
*/
55
static boolean separateServerThread = false;
56
57
/*
58
* Where do we find the keystores?
59
*/
60
static String pathToStores = "../etc";
61
static String keyStoreFile = "keystore";
62
static String trustStoreFile = "truststore";
63
static String passwd = "passphrase";
64
65
/*
66
* Is the server ready to serve?
67
*/
68
volatile static boolean serverReady = false;
69
70
/*
71
* Turn on SSL debugging?
72
*/
73
static boolean debug = false;
74
75
/*
76
* If the client or server is doing some kind of object creation
77
* that the other side depends on, and that thread prematurely
78
* exits, you may experience a hang. The test harness will
79
* terminate all hung threads after its timeout has expired,
80
* currently 3 minutes by default, but you might try to be
81
* smart about it....
82
*/
83
84
/*
85
* Define the server side of the test.
86
*
87
* If the server prematurely exits, serverReady will be set to true
88
* to avoid infinite hangs.
89
*/
90
void doServerSide() throws Exception {
91
SSLServerSocketFactory sslssf =
92
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
93
SSLServerSocket sslServerSocket =
94
(SSLServerSocket) sslssf.createServerSocket(serverPort);
95
96
// enable a stream cipher
97
sslServerSocket.setEnabledCipherSuites(
98
new String[] {"SSL_RSA_WITH_RC4_128_MD5"});
99
100
serverPort = sslServerSocket.getLocalPort();
101
102
/*
103
* Signal Client, we're ready for his connect.
104
*/
105
serverReady = true;
106
107
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
108
InputStream sslIS = sslSocket.getInputStream();
109
OutputStream sslOS = sslSocket.getOutputStream();
110
111
sslIS.read();
112
sslOS.write('A');
113
sslOS.flush();
114
115
sslSocket.close();
116
}
117
118
/*
119
* Define the client side of the test.
120
*
121
* If the server prematurely exits, serverReady will be set to true
122
* to avoid infinite hangs.
123
*/
124
void doClientSide() throws Exception {
125
126
/*
127
* Wait for server to get started.
128
*/
129
while (!serverReady) {
130
Thread.sleep(50);
131
}
132
133
SSLSocketFactory sslsf =
134
(SSLSocketFactory) SSLSocketFactory.getDefault();
135
SSLSocket sslSocket = (SSLSocket)
136
sslsf.createSocket("localhost", serverPort);
137
138
// enable TLSv1.1 only
139
sslSocket.setEnabledProtocols(new String[] {"TLSv1.1"});
140
141
// enable a stream cipher
142
sslSocket.setEnabledCipherSuites(
143
new String[] {"SSL_RSA_WITH_RC4_128_MD5"});
144
145
InputStream sslIS = sslSocket.getInputStream();
146
OutputStream sslOS = sslSocket.getOutputStream();
147
148
sslOS.write('B');
149
sslOS.flush();
150
sslIS.read();
151
152
sslSocket.close();
153
}
154
155
/*
156
* =============================================================
157
* The remainder is just support stuff
158
*/
159
160
// use any free port by default
161
volatile int serverPort = 0;
162
163
volatile Exception serverException = null;
164
volatile Exception clientException = null;
165
166
public static void main(String[] args) throws Exception {
167
// reset the security property to make sure that the algorithms
168
// and keys used in this test are not disabled.
169
Security.setProperty("jdk.tls.disabledAlgorithms", "");
170
171
String keyFilename =
172
System.getProperty("test.src", ".") + "/" + pathToStores +
173
"/" + keyStoreFile;
174
String trustFilename =
175
System.getProperty("test.src", ".") + "/" + pathToStores +
176
"/" + trustStoreFile;
177
178
System.setProperty("javax.net.ssl.keyStore", keyFilename);
179
System.setProperty("javax.net.ssl.keyStorePassword", passwd);
180
System.setProperty("javax.net.ssl.trustStore", trustFilename);
181
System.setProperty("javax.net.ssl.trustStorePassword", passwd);
182
183
if (debug)
184
System.setProperty("javax.net.debug", "all");
185
186
/*
187
* Start the tests.
188
*/
189
new GenericStreamCipher();
190
}
191
192
Thread clientThread = null;
193
Thread serverThread = null;
194
195
/*
196
* Primary constructor, used to drive remainder of the test.
197
*
198
* Fork off the other side, then do your work.
199
*/
200
GenericStreamCipher() throws Exception {
201
try {
202
if (separateServerThread) {
203
startServer(true);
204
startClient(false);
205
} else {
206
startClient(true);
207
startServer(false);
208
}
209
} catch (Exception e) {
210
// swallow for now. Show later
211
}
212
213
/*
214
* Wait for other side to close down.
215
*/
216
if (separateServerThread) {
217
serverThread.join();
218
} else {
219
clientThread.join();
220
}
221
222
/*
223
* When we get here, the test is pretty much over.
224
* Which side threw the error?
225
*/
226
Exception local;
227
Exception remote;
228
String whichRemote;
229
230
if (separateServerThread) {
231
remote = serverException;
232
local = clientException;
233
whichRemote = "server";
234
} else {
235
remote = clientException;
236
local = serverException;
237
whichRemote = "client";
238
}
239
240
/*
241
* If both failed, return the curthread's exception, but also
242
* print the remote side Exception
243
*/
244
if ((local != null) && (remote != null)) {
245
System.out.println(whichRemote + " also threw:");
246
remote.printStackTrace();
247
System.out.println();
248
throw local;
249
}
250
251
if (remote != null) {
252
throw remote;
253
}
254
255
if (local != null) {
256
throw local;
257
}
258
}
259
260
void startServer(boolean newThread) throws Exception {
261
if (newThread) {
262
serverThread = new Thread() {
263
public void run() {
264
try {
265
doServerSide();
266
} catch (Exception e) {
267
/*
268
* Our server thread just died.
269
*
270
* Release the client, if not active already...
271
*/
272
System.err.println("Server died...");
273
serverReady = true;
274
serverException = e;
275
}
276
}
277
};
278
serverThread.start();
279
} else {
280
try {
281
doServerSide();
282
} catch (Exception e) {
283
serverException = e;
284
} finally {
285
serverReady = true;
286
}
287
}
288
}
289
290
void startClient(boolean newThread) throws Exception {
291
if (newThread) {
292
clientThread = new Thread() {
293
public void run() {
294
try {
295
doClientSide();
296
} catch (Exception e) {
297
/*
298
* Our client thread just died.
299
*/
300
System.err.println("Client died...");
301
clientException = e;
302
}
303
}
304
};
305
clientThread.start();
306
} else {
307
try {
308
doClientSide();
309
} catch (Exception e) {
310
clientException = e;
311
}
312
}
313
}
314
}
315
316