author | prr |
Thu, 18 Dec 2014 10:45:45 -0800 | |
changeset 29908 | 83e2c403fefd |
parent 23052 | 241885315119 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
10328
diff
changeset
|
2 |
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4280338 |
|
27 |
* @summary "Unsupported SSL message version" SSLProtocolException |
|
28 |
* w/SSL_RSA_WITH_NULL_MD5 |
|
10328 | 29 |
* @run main/othervm JSSERenegotiate |
30 |
* |
|
31 |
* SunJSSE does not support dynamic system properties, no way to re-use |
|
32 |
* system properties in samevm/agentvm mode. |
|
2 | 33 |
* |
34 |
* @author Ram Marti |
|
35 |
* @author Brad Wetmore |
|
36 |
*/ |
|
37 |
||
38 |
import java.io.*; |
|
39 |
import java.net.*; |
|
40 |
import javax.net.ssl.*; |
|
41 |
||
42 |
public class JSSERenegotiate { |
|
43 |
||
44 |
static final String suite1 = "SSL_RSA_WITH_NULL_MD5"; |
|
45 |
static final String suite2 = "SSL_RSA_WITH_NULL_SHA"; |
|
46 |
||
47 |
static final String dataString = "This is a test"; |
|
48 |
||
49 |
||
50 |
/* |
|
51 |
* ============================================================= |
|
52 |
* Set the various variables needed for the tests, then |
|
53 |
* specify what tests to run on each side. |
|
54 |
*/ |
|
55 |
||
56 |
/* |
|
57 |
* Should we run the client or server in a separate thread? |
|
58 |
* Both sides can throw exceptions, but do you have a preference |
|
59 |
* as to which side should be the main thread. |
|
60 |
*/ |
|
61 |
static boolean separateServerThread = false; |
|
62 |
||
63 |
/* |
|
64 |
* Where do we find the keystores? |
|
65 |
*/ |
|
23052
241885315119
8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents:
14342
diff
changeset
|
66 |
static String pathToStores = "../etc"; |
2 | 67 |
static String keyStoreFile = "keystore"; |
68 |
static String trustStoreFile = "truststore"; |
|
69 |
static String passwd = "passphrase"; |
|
70 |
||
71 |
/* |
|
72 |
* Is the server ready to serve? |
|
73 |
*/ |
|
74 |
volatile static boolean serverReady = false; |
|
75 |
||
76 |
/* |
|
77 |
* Turn on SSL debugging? |
|
78 |
*/ |
|
79 |
static boolean debug = false; |
|
80 |
||
81 |
/* |
|
82 |
* If the client or server is doing some kind of object creation |
|
83 |
* that the other side depends on, and that thread prematurely |
|
84 |
* exits, you may experience a hang. The test harness will |
|
85 |
* terminate all hung threads after its timeout has expired, |
|
86 |
* currently 3 minutes by default, but you might try to be |
|
87 |
* smart about it.... |
|
88 |
*/ |
|
89 |
||
90 |
/* |
|
91 |
* Define the server side of the test. |
|
92 |
* |
|
93 |
* If the server prematurely exits, serverReady will be set to true |
|
94 |
* to avoid infinite hangs. |
|
95 |
*/ |
|
96 |
void doServerSide() throws Exception { |
|
97 |
SSLServerSocketFactory sslssf = |
|
98 |
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); |
|
99 |
SSLServerSocket sslServerSocket = |
|
100 |
(SSLServerSocket) sslssf.createServerSocket(serverPort, 3); |
|
101 |
||
102 |
sslServerSocket.setNeedClientAuth(true); |
|
103 |
sslServerSocket.setEnabledCipherSuites(new String[] {suite1, suite2 }); |
|
104 |
||
105 |
serverPort = sslServerSocket.getLocalPort(); |
|
106 |
||
107 |
/* |
|
108 |
* Signal Client, we're ready for his connect. |
|
109 |
*/ |
|
110 |
serverReady = true; |
|
111 |
||
112 |
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); |
|
113 |
||
114 |
DataInputStream sslIS = |
|
115 |
new DataInputStream(sslSocket.getInputStream()); |
|
116 |
DataOutputStream sslOS = |
|
117 |
new DataOutputStream(sslSocket.getOutputStream()); |
|
118 |
while (true) { |
|
119 |
try { |
|
120 |
System.out.println("Received: " + sslIS.readUTF()); |
|
121 |
} catch (SSLException e) { |
|
122 |
System.out.println ("Received wrong exception"); |
|
123 |
break; |
|
124 |
} catch (IOException e) { |
|
125 |
System.out.println ("Received right exception"); |
|
126 |
break; |
|
127 |
} |
|
128 |
} |
|
129 |
sslSocket.close(); |
|
130 |
} |
|
131 |
||
132 |
/* |
|
133 |
* Define the client side of the test. |
|
134 |
* |
|
135 |
* If the server prematurely exits, serverReady will be set to true |
|
136 |
* to avoid infinite hangs. |
|
137 |
*/ |
|
138 |
void doClientSide() throws Exception { |
|
139 |
||
140 |
/* |
|
141 |
* Wait for server to get started. |
|
142 |
*/ |
|
143 |
while (!serverReady) { |
|
144 |
Thread.sleep(50); |
|
145 |
} |
|
146 |
||
147 |
SSLSocketFactory sslsf = |
|
148 |
(SSLSocketFactory) SSLSocketFactory.getDefault(); |
|
149 |
SSLSocket sslSocket = (SSLSocket) |
|
150 |
sslsf.createSocket("localhost", serverPort); |
|
151 |
||
152 |
sslSocket.setEnabledCipherSuites(new String[] { suite1 }); |
|
153 |
System.out.println("Enabled " + suite1); |
|
154 |
||
155 |
DataInputStream sslIS = |
|
156 |
new DataInputStream(sslSocket.getInputStream()); |
|
157 |
DataOutputStream sslOS = |
|
158 |
new DataOutputStream(sslSocket.getOutputStream()); |
|
159 |
BufferedReader in = new BufferedReader( |
|
160 |
new InputStreamReader(sslSocket.getInputStream())); |
|
161 |
sslOS.writeUTF("With " + suite1); |
|
162 |
||
163 |
sslSocket.setEnabledCipherSuites(new String[] { suite2 }); |
|
164 |
sslSocket.startHandshake(); |
|
165 |
||
166 |
System.out.println("Enabled " + suite2); |
|
167 |
// write the message a few times - see bug 4462616 why we do this |
|
168 |
sslOS.writeUTF("With " + suite2); |
|
169 |
sslOS.writeUTF("With " + suite2); |
|
170 |
sslOS.writeUTF("With " + suite2); |
|
171 |
||
172 |
sslSocket.setEnabledCipherSuites(new String[] { suite1 }); |
|
173 |
sslSocket.startHandshake(); |
|
174 |
System.out.println("Re-enabled " + suite1); |
|
175 |
sslOS.writeUTF("With " + suite1); |
|
176 |
sslOS.writeUTF("With " + suite1); |
|
177 |
sslOS.writeUTF("With " + suite1); |
|
178 |
sslSocket.close(); |
|
179 |
} |
|
180 |
||
181 |
/* |
|
182 |
* ============================================================= |
|
183 |
* The remainder is just support stuff |
|
184 |
*/ |
|
185 |
||
186 |
// use any free port by default |
|
187 |
volatile int serverPort = 0; |
|
188 |
||
189 |
volatile Exception serverException = null; |
|
190 |
volatile Exception clientException = null; |
|
191 |
||
192 |
public static void main(String[] args) throws Exception { |
|
193 |
String keyFilename = |
|
194 |
System.getProperty("test.src", "./") + "/" + pathToStores + |
|
195 |
"/" + keyStoreFile; |
|
196 |
String trustFilename = |
|
197 |
System.getProperty("test.src", "./") + "/" + pathToStores + |
|
198 |
"/" + trustStoreFile; |
|
199 |
||
200 |
System.setProperty("javax.net.ssl.keyStore", keyFilename); |
|
201 |
System.setProperty("javax.net.ssl.keyStorePassword", passwd); |
|
202 |
System.setProperty("javax.net.ssl.trustStore", trustFilename); |
|
203 |
System.setProperty("javax.net.ssl.trustStorePassword", passwd); |
|
204 |
||
205 |
if (debug) |
|
206 |
System.setProperty("javax.net.debug", "all"); |
|
207 |
||
208 |
/* |
|
209 |
* Start the tests. |
|
210 |
*/ |
|
211 |
new JSSERenegotiate(); |
|
212 |
} |
|
213 |
||
214 |
Thread clientThread = null; |
|
215 |
Thread serverThread = null; |
|
216 |
||
217 |
/* |
|
218 |
* Primary constructor, used to drive remainder of the test. |
|
219 |
* |
|
220 |
* Fork off the other side, then do your work. |
|
221 |
*/ |
|
222 |
JSSERenegotiate() throws Exception { |
|
223 |
try { |
|
224 |
if (separateServerThread) { |
|
225 |
startServer(true); |
|
226 |
startClient(false); |
|
227 |
} else { |
|
228 |
startClient(true); |
|
229 |
startServer(false); |
|
230 |
} |
|
231 |
} catch (Exception e) { |
|
232 |
// swallow for now. Show later |
|
233 |
} |
|
234 |
||
235 |
/* |
|
236 |
* Wait for other side to close down. |
|
237 |
*/ |
|
238 |
if (separateServerThread) { |
|
239 |
serverThread.join(); |
|
240 |
} else { |
|
241 |
clientThread.join(); |
|
242 |
} |
|
243 |
||
244 |
/* |
|
245 |
* When we get here, the test is pretty much over. |
|
246 |
* Which side threw the error? |
|
247 |
*/ |
|
248 |
Exception local; |
|
249 |
Exception remote; |
|
250 |
String whichRemote; |
|
251 |
||
252 |
if (separateServerThread) { |
|
253 |
remote = serverException; |
|
254 |
local = clientException; |
|
255 |
whichRemote = "server"; |
|
256 |
} else { |
|
257 |
remote = clientException; |
|
258 |
local = serverException; |
|
259 |
whichRemote = "client"; |
|
260 |
} |
|
261 |
||
262 |
/* |
|
263 |
* If both failed, return the curthread's exception, but also |
|
264 |
* print the remote side Exception |
|
265 |
*/ |
|
266 |
if ((local != null) && (remote != null)) { |
|
267 |
System.out.println(whichRemote + " also threw:"); |
|
268 |
remote.printStackTrace(); |
|
269 |
System.out.println(); |
|
270 |
throw local; |
|
271 |
} |
|
272 |
||
273 |
if (remote != null) { |
|
274 |
throw remote; |
|
275 |
} |
|
276 |
||
277 |
if (local != null) { |
|
278 |
throw local; |
|
279 |
} |
|
280 |
} |
|
281 |
||
282 |
void startServer(boolean newThread) throws Exception { |
|
283 |
if (newThread) { |
|
284 |
serverThread = new Thread() { |
|
285 |
public void run() { |
|
286 |
try { |
|
287 |
doServerSide(); |
|
288 |
} catch (Exception e) { |
|
289 |
/* |
|
290 |
* Our server thread just died. |
|
291 |
* |
|
292 |
* Release the client, if not active already... |
|
293 |
*/ |
|
294 |
System.err.println("Server died..."); |
|
295 |
serverReady = true; |
|
296 |
serverException = e; |
|
297 |
} |
|
298 |
} |
|
299 |
}; |
|
300 |
serverThread.start(); |
|
301 |
} else { |
|
302 |
try { |
|
303 |
doServerSide(); |
|
304 |
} catch (Exception e) { |
|
305 |
serverException = e; |
|
306 |
} finally { |
|
307 |
serverReady = true; |
|
308 |
} |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
void startClient(boolean newThread) throws Exception { |
|
313 |
if (newThread) { |
|
314 |
clientThread = new Thread() { |
|
315 |
public void run() { |
|
316 |
try { |
|
317 |
doClientSide(); |
|
318 |
} catch (Exception e) { |
|
319 |
/* |
|
320 |
* Our client thread just died. |
|
321 |
*/ |
|
322 |
System.err.println("Client died..."); |
|
323 |
clientException = e; |
|
324 |
} |
|
325 |
} |
|
326 |
}; |
|
327 |
clientThread.start(); |
|
328 |
} else { |
|
329 |
try { |
|
330 |
doClientSide(); |
|
331 |
} catch (Exception e) { |
|
332 |
clientException = e; |
|
333 |
} |
|
334 |
} |
|
335 |
} |
|
336 |
} |