author | asmotrak |
Tue, 26 Jan 2016 13:32:07 -0800 | |
changeset 35379 | 1e8e336ef66b |
parent 29983 | 244149c6b998 |
child 43106 | 4a7670d316ee |
permissions | -rw-r--r-- |
2 | 1 |
/* |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
2 |
* Copyright (c) 2002, 2016, 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 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
24 |
import java.io.IOException; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
25 |
import java.io.InputStream; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
26 |
import java.io.OutputStream; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
27 |
import java.util.concurrent.Executor; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
28 |
import java.util.concurrent.Executors; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
29 |
import javax.net.ssl.KeyManager; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
30 |
import javax.net.ssl.SSLContext; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
31 |
import javax.net.ssl.SSLServerSocket; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
32 |
import javax.net.ssl.SSLServerSocketFactory; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
33 |
import javax.net.ssl.SSLSocket; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
34 |
import javax.net.ssl.TrustManager; |
2 | 35 |
|
36 |
class JSSEServer extends CipherTest.Server { |
|
37 |
||
38 |
SSLServerSocket serverSocket; |
|
39 |
||
40 |
JSSEServer(CipherTest cipherTest) throws Exception { |
|
41 |
super(cipherTest); |
|
42 |
SSLContext serverContext = SSLContext.getInstance("TLS"); |
|
43 |
serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom); |
|
44 |
||
45 |
SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory(); |
|
29983
244149c6b998
8078348: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java fails with BindException
vinnie
parents:
5506
diff
changeset
|
46 |
serverSocket = (SSLServerSocket)factory.createServerSocket(0); |
2 | 47 |
cipherTest.serverPort = serverSocket.getLocalPort(); |
48 |
serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites()); |
|
49 |
serverSocket.setWantClientAuth(true); |
|
50 |
} |
|
51 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
52 |
@Override |
2 | 53 |
public void run() { |
54 |
System.out.println("JSSE Server listening on port " + cipherTest.serverPort); |
|
55 |
Executor exec = Executors.newFixedThreadPool |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
56 |
(CipherTest.THREADS, DaemonThreadFactory.INSTANCE); |
2 | 57 |
try { |
58 |
while (true) { |
|
59 |
final SSLSocket socket = (SSLSocket)serverSocket.accept(); |
|
60 |
socket.setSoTimeout(cipherTest.TIMEOUT); |
|
61 |
Runnable r = new Runnable() { |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
29983
diff
changeset
|
62 |
@Override |
2 | 63 |
public void run() { |
64 |
try { |
|
65 |
InputStream in = socket.getInputStream(); |
|
66 |
OutputStream out = socket.getOutputStream(); |
|
67 |
handleRequest(in, out); |
|
68 |
out.flush(); |
|
69 |
socket.close(); |
|
70 |
socket.getSession().invalidate(); |
|
71 |
} catch (IOException e) { |
|
72 |
cipherTest.setFailed(); |
|
73 |
e.printStackTrace(); |
|
74 |
} finally { |
|
75 |
if (socket != null) { |
|
76 |
try { |
|
77 |
socket.close(); |
|
78 |
} catch (IOException e) { |
|
79 |
cipherTest.setFailed(); |
|
80 |
System.out.println("Exception closing socket on server side:"); |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
}; |
|
87 |
exec.execute(r); |
|
88 |
} |
|
89 |
} catch (IOException e) { |
|
90 |
cipherTest.setFailed(); |
|
91 |
e.printStackTrace(); |
|
92 |
// |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
} |