use of javax.net.ssl.SSLServerSocketFactory in project java-chassis by ServiceComb.
the class SSLManager method createSSLServerSocket.
public static SSLServerSocket createSSLServerSocket(SSLOption option, SSLCustom custom) {
try {
SSLContext context = createSSLContext(option, custom);
SSLServerSocketFactory factory = context.getServerSocketFactory();
SSLServerSocket socket = (SSLServerSocket) factory.createServerSocket();
socket.setEnabledProtocols(option.getProtocols().split(","));
String[] supported = socket.getSupportedCipherSuites();
String[] eanbled = option.getCiphers().split(",");
socket.setEnabledCipherSuites(getEnabledCiphers(supported, eanbled));
socket.setNeedClientAuth(option.isAuthPeer());
return socket;
} catch (UnknownHostException e) {
throw new IllegalArgumentException("unkown host");
} catch (IOException e) {
throw new IllegalArgumentException("unable create socket");
}
}
use of javax.net.ssl.SSLServerSocketFactory in project athenz by yahoo.
the class SocketTest method runPingServer.
private void runPingServer(int port, KeyRefresher keyRefresher) throws Exception {
SSLContext sslContext = Utils.buildSSLContext(keyRefresher.getKeyManagerProxy(), keyRefresher.getTrustManagerProxy());
SSLServerSocketFactory sslServerSocketFactory = sslContext.getServerSocketFactory();
SSLServerSocket sslServerSocket = (SSLServerSocket) sslServerSocketFactory.createServerSocket(port);
new Thread(() -> {
while (running) {
try {
final Socket s = sslServerSocket.accept();
new Thread(() -> {
try {
BufferedReader is = new BufferedReader(new InputStreamReader(s.getInputStream()));
OutputStream os = s.getOutputStream();
while (running) {
String line = is.readLine();
if (line.equals("ping")) {
os.write("pong\n".getBytes());
}
}
} catch (IOException ignored) {
// die
}
}).start();
} catch (IOException ignored) {
// die.
}
}
}).start();
}
Aggregations