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