Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/AppInputStream/RemoveMarkReset.java
41152 views
1
/*
2
* Copyright (c) 2001, 2011, 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
* @test
26
* @bug 4413664
27
* @summary remove mark/reset functionality from AppInputStream
28
* @run main/othervm RemoveMarkReset
29
*
30
* SunJSSE does not support dynamic system properties, no way to re-use
31
* system properties in samevm/agentvm mode.
32
* @author Brad Wetmore
33
*/
34
35
import java.io.*;
36
import java.net.*;
37
import javax.net.ssl.*;
38
39
public class RemoveMarkReset {
40
41
/*
42
* =============================================================
43
* Set the various variables needed for the tests, then
44
* specify what tests to run on each side.
45
*/
46
47
/*
48
* Should we run the client or server in a separate thread?
49
* Both sides can throw exceptions, but do you have a preference
50
* as to which side should be the main thread.
51
*/
52
static boolean separateServerThread = false;
53
54
/*
55
* Where do we find the keystores?
56
*/
57
static String pathToStores = "../../../../javax/net/ssl/etc";
58
static String keyStoreFile = "keystore";
59
static String trustStoreFile = "truststore";
60
static String passwd = "passphrase";
61
62
/*
63
* Is the server ready to serve?
64
*/
65
volatile static boolean serverReady = false;
66
67
/*
68
* Turn on SSL debugging?
69
*/
70
static boolean debug = false;
71
72
73
/*
74
* Define the server side of the test.
75
*/
76
void doServerSide() throws Exception {
77
SSLServerSocketFactory sslssf =
78
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
79
SSLServerSocket sslServerSocket =
80
(SSLServerSocket) sslssf.createServerSocket(serverPort);
81
82
serverPort = sslServerSocket.getLocalPort();
83
84
/*
85
* Signal Client, we're ready for his connect.
86
*/
87
serverReady = true;
88
89
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
90
InputStream sslIS = sslSocket.getInputStream();
91
OutputStream sslOS = sslSocket.getOutputStream();
92
93
sslIS.read();
94
sslOS.write(85);
95
sslOS.flush();
96
97
if (sslIS.markSupported())
98
throw new Exception("sslIS.markSupported() reported true");
99
sslIS.mark(10);
100
try {
101
sslIS.reset();
102
throw new Exception("sslIS.reset() didn't throw exception");
103
} catch (IOException e) {
104
/*
105
* swallow. This worked correctly.
106
*/
107
}
108
109
sslIS.close();
110
sslOS.close();
111
sslSocket.close();
112
}
113
114
/*
115
* Define the client side of the test.
116
*/
117
void doClientSide() throws Exception {
118
119
/*
120
* Wait for server to get started.
121
*/
122
while (!serverReady) {
123
Thread.sleep(50);
124
}
125
126
SSLSocketFactory sslsf =
127
(SSLSocketFactory) SSLSocketFactory.getDefault();
128
SSLSocket sslSocket = (SSLSocket)
129
sslsf.createSocket("localhost", serverPort);
130
131
InputStream sslIS = sslSocket.getInputStream();
132
OutputStream sslOS = sslSocket.getOutputStream();
133
134
sslOS.write(280);
135
sslOS.flush();
136
sslIS.read();
137
138
sslIS.close();
139
sslOS.close();
140
sslSocket.close();
141
}
142
143
/*
144
* =============================================================
145
* The remainder is just support stuff
146
*/
147
148
// use any free port by default
149
volatile int serverPort = 0;
150
151
volatile Exception serverException = null;
152
volatile Exception clientException = null;
153
154
public static void main(String[] args) throws Exception {
155
String keyFilename =
156
System.getProperty("test.src", "./") + "/" + pathToStores +
157
"/" + keyStoreFile;
158
String trustFilename =
159
System.getProperty("test.src", "./") + "/" + pathToStores +
160
"/" + trustStoreFile;
161
162
System.setProperty("javax.net.ssl.keyStore", keyFilename);
163
System.setProperty("javax.net.ssl.keyStorePassword", passwd);
164
System.setProperty("javax.net.ssl.trustStore", trustFilename);
165
System.setProperty("javax.net.ssl.trustStorePassword", passwd);
166
167
if (debug)
168
System.setProperty("javax.net.debug", "all");
169
170
/*
171
* Start the tests.
172
*/
173
new RemoveMarkReset();
174
}
175
176
Thread clientThread = null;
177
Thread serverThread = null;
178
179
/*
180
* Primary constructor, used to drive remainder of the test.
181
*
182
* Fork off the other side, then do your work.
183
*/
184
RemoveMarkReset () throws Exception {
185
if (separateServerThread) {
186
startServer(true);
187
startClient(false);
188
} else {
189
startClient(true);
190
startServer(false);
191
}
192
193
/*
194
* Wait for other side to close down.
195
*/
196
if (separateServerThread) {
197
serverThread.join();
198
} else {
199
clientThread.join();
200
}
201
202
/*
203
* When we get here, the test is pretty much over.
204
*
205
* If the main thread excepted, that propagates back
206
* immediately. If the other thread threw an exception, we
207
* should report back.
208
*/
209
if (serverException != null)
210
throw serverException;
211
if (clientException != null)
212
throw clientException;
213
}
214
215
void startServer(boolean newThread) throws Exception {
216
if (newThread) {
217
serverThread = new Thread() {
218
public void run() {
219
try {
220
doServerSide();
221
} catch (Exception e) {
222
/*
223
* Our server thread just died.
224
*
225
* Release the client, if not already active...
226
*/
227
System.out.println("Server died...");
228
serverReady = true;
229
serverException = e;
230
}
231
}
232
};
233
serverThread.start();
234
} else {
235
doServerSide();
236
}
237
}
238
239
void startClient(boolean newThread) throws Exception {
240
if (newThread) {
241
clientThread = new Thread() {
242
public void run() {
243
try {
244
doClientSide();
245
} catch (Exception e) {
246
/*
247
* Our client thread just died.
248
*/
249
System.out.println("Client died...");
250
clientException = e;
251
}
252
}
253
};
254
clientThread.start();
255
} else {
256
doClientSide();
257
}
258
}
259
}
260
261