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