2
|
1 |
/*
|
|
2 |
* Copyright 2002-2005 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
import java.io.*;
|
|
25 |
import java.net.*;
|
|
26 |
import java.util.*;
|
|
27 |
import java.util.concurrent.*;
|
|
28 |
|
|
29 |
import java.security.*;
|
|
30 |
import java.security.cert.*;
|
|
31 |
import java.security.cert.Certificate;
|
|
32 |
|
|
33 |
import javax.net.ssl.*;
|
|
34 |
|
|
35 |
class JSSEServer extends CipherTest.Server {
|
|
36 |
|
|
37 |
SSLServerSocket serverSocket;
|
|
38 |
|
|
39 |
JSSEServer(CipherTest cipherTest) throws Exception {
|
|
40 |
super(cipherTest);
|
|
41 |
SSLContext serverContext = SSLContext.getInstance("TLS");
|
|
42 |
serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom);
|
|
43 |
|
|
44 |
SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();
|
|
45 |
serverSocket = (SSLServerSocket)factory.createServerSocket(cipherTest.serverPort);
|
|
46 |
cipherTest.serverPort = serverSocket.getLocalPort();
|
|
47 |
serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());
|
|
48 |
// serverSocket.setWantClientAuth(true);
|
|
49 |
}
|
|
50 |
|
|
51 |
public void run() {
|
|
52 |
System.out.println("JSSE Server listening on port " + cipherTest.serverPort);
|
|
53 |
Executor exec = Executors.newFixedThreadPool
|
|
54 |
(cipherTest.THREADS, DaemonThreadFactory.INSTANCE);
|
|
55 |
try {
|
|
56 |
while (true) {
|
|
57 |
final SSLSocket socket = (SSLSocket)serverSocket.accept();
|
|
58 |
socket.setSoTimeout(cipherTest.TIMEOUT);
|
|
59 |
Runnable r = new Runnable() {
|
|
60 |
public void run() {
|
|
61 |
try {
|
|
62 |
InputStream in = socket.getInputStream();
|
|
63 |
OutputStream out = socket.getOutputStream();
|
|
64 |
handleRequest(in, out);
|
|
65 |
out.flush();
|
|
66 |
socket.close();
|
|
67 |
socket.getSession().invalidate();
|
|
68 |
} catch (IOException e) {
|
|
69 |
cipherTest.setFailed();
|
|
70 |
e.printStackTrace();
|
|
71 |
} finally {
|
|
72 |
if (socket != null) {
|
|
73 |
try {
|
|
74 |
socket.close();
|
|
75 |
} catch (IOException e) {
|
|
76 |
cipherTest.setFailed();
|
|
77 |
System.out.println("Exception closing socket on server side:");
|
|
78 |
e.printStackTrace();
|
|
79 |
}
|
|
80 |
}
|
|
81 |
}
|
|
82 |
}
|
|
83 |
};
|
|
84 |
exec.execute(r);
|
|
85 |
}
|
|
86 |
} catch (IOException e) {
|
|
87 |
cipherTest.setFailed();
|
|
88 |
e.printStackTrace();
|
|
89 |
//
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
}
|