Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/pkcs11/fips/JSSEServer.java
38855 views
1
/*
2
* Copyright (c) 2002, 2005, 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
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
}
94
95