Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/CertPathRestrictions/JSSEServer.java
41152 views
1
/*
2
* Copyright (c) 2017, 2018, 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.InputStream;
25
import java.io.OutputStream;
26
27
import javax.net.ssl.SSLContext;
28
import javax.net.ssl.SSLServerSocket;
29
import javax.net.ssl.SSLServerSocketFactory;
30
import javax.net.ssl.SSLSocket;
31
32
/*
33
* A SSL socket server.
34
*/
35
public class JSSEServer {
36
37
private SSLServerSocket server = null;
38
39
public JSSEServer(SSLContext context, String constraint,
40
boolean needClientAuth) throws Exception {
41
TLSRestrictions.setConstraint("Server", constraint);
42
43
SSLServerSocketFactory serverFactory = context.getServerSocketFactory();
44
server = (SSLServerSocket) serverFactory.createServerSocket(0);
45
server.setSoTimeout(TLSRestrictions.TIMEOUT);
46
server.setNeedClientAuth(needClientAuth); // for dual authentication
47
System.out.println("Server: port=" + getPort());
48
}
49
50
public Exception start() {
51
System.out.println("Server: started");
52
Exception exception = null;
53
try (SSLSocket socket = (SSLSocket) server.accept()) {
54
System.out.println("Server: accepted connection");
55
socket.setSoTimeout(TLSRestrictions.TIMEOUT);
56
InputStream sslIS = socket.getInputStream();
57
OutputStream sslOS = socket.getOutputStream();
58
sslIS.read();
59
sslOS.write('S');
60
sslOS.flush();
61
System.out.println("Server: finished");
62
} catch (Exception e) {
63
exception = e;
64
e.printStackTrace(System.out);
65
System.out.println("Server: failed");
66
}
67
68
return exception;
69
}
70
71
public int getPort() {
72
return server.getLocalPort();
73
}
74
}
75
76