author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 39140 | 86f21a96d0ab |
child 45028 | b0ea3c0bfb81 |
permissions | -rw-r--r-- |
39140
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
1 |
/* |
38430
e8d1995c38fa
8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents:
26337
diff
changeset
|
2 |
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
26337
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
4 |
* |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it under |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
6 |
* the terms of the GNU General Public License version 2 only, as published by |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
7 |
* the Free Software Foundation. |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
8 |
* |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT ANY |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
11 |
* A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
12 |
* details (a copy is included in the LICENSE file that accompanied this code). |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
13 |
* |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License version 2 |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
15 |
* along with this work; if not, write to the Free Software Foundation, Inc., 51 |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
16 |
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
17 |
* |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA or |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
19 |
* visit www.oracle.com if you need additional information or have any |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
20 |
* questions. |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
21 |
*/ |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
22 |
|
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
23 |
import java.io.IOException; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
24 |
import java.io.InputStream; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
25 |
import java.io.OutputStream; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
26 |
import javax.net.ssl.KeyManager; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
27 |
import javax.net.ssl.SSLContext; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
28 |
import javax.net.ssl.SSLServerSocket; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
29 |
import javax.net.ssl.SSLServerSocketFactory; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
30 |
import javax.net.ssl.SSLSocket; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
31 |
import javax.net.ssl.TrustManager; |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
32 |
|
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
33 |
public class JSSEServer extends CipherTestUtils.Server { |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
34 |
|
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
35 |
private final SSLServerSocket serverSocket; |
39140
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
36 |
private static volatile boolean closeServer = false; |
26337
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
37 |
|
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
38 |
JSSEServer(CipherTestUtils cipherTest, int serverPort, |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
39 |
String protocol, String cipherSuite) throws Exception { |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
40 |
super(cipherTest); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
41 |
SSLContext serverContext = SSLContext.getInstance("TLS"); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
42 |
serverContext.init(new KeyManager[]{cipherTest.getServerKeyManager()}, |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
43 |
new TrustManager[]{cipherTest.getServerTrustManager()}, |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
44 |
CipherTestUtils.secureRandom); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
45 |
SSLServerSocketFactory factory = |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
46 |
(SSLServerSocketFactory)serverContext.getServerSocketFactory(); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
47 |
serverSocket = |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
48 |
(SSLServerSocket) factory.createServerSocket(serverPort); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
49 |
serverSocket.setEnabledProtocols(protocol.split(",")); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
50 |
serverSocket.setEnabledCipherSuites(cipherSuite.split(",")); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
51 |
|
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
52 |
CipherTestUtils.printInfo(serverSocket); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
53 |
} |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
54 |
|
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
55 |
@Override |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
56 |
public void run() { |
39140
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
57 |
System.out.println("JSSE Server listening on port " + getPort()); |
26337
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
58 |
while (!closeServer) { |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
59 |
try (final SSLSocket socket = (SSLSocket) serverSocket.accept()) { |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
60 |
socket.setSoTimeout(CipherTestUtils.TIMEOUT); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
61 |
|
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
62 |
try (InputStream in = socket.getInputStream(); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
63 |
OutputStream out = socket.getOutputStream()) { |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
64 |
handleRequest(in, out); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
65 |
out.flush(); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
66 |
} catch (IOException e) { |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
67 |
CipherTestUtils.addFailure(e); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
68 |
System.out.println("Got IOException:"); |
39140
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
69 |
e.printStackTrace(System.out); |
26337
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
70 |
} |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
71 |
} catch (Exception e) { |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
72 |
CipherTestUtils.addFailure(e); |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
73 |
System.out.println("Exception:"); |
39140
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
74 |
e.printStackTrace(System.out); |
26337
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
75 |
} |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
76 |
} |
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
77 |
} |
38430
e8d1995c38fa
8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents:
26337
diff
changeset
|
78 |
|
e8d1995c38fa
8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents:
26337
diff
changeset
|
79 |
int getPort() { |
e8d1995c38fa
8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents:
26337
diff
changeset
|
80 |
return serverSocket.getLocalPort(); |
e8d1995c38fa
8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents:
26337
diff
changeset
|
81 |
} |
39140
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
82 |
|
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
83 |
@Override |
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
84 |
public void close() throws IOException { |
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
85 |
closeServer = true; |
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
86 |
if (serverSocket != null && !serverSocket.isClosed()) { |
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
87 |
serverSocket.close(); |
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
88 |
} |
86f21a96d0ab
8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents:
38430
diff
changeset
|
89 |
} |
26337
39f3ee5364e5
8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff
changeset
|
90 |
} |