use of javax.net.ssl.SSLServerSocketFactory in project nanohttpd by NanoHttpd.
the class NanoHTTPD method makeSSLSocketFactory.
/**
* Creates an SSLSocketFactory for HTTPS. Pass a loaded KeyStore and an
* array of loaded KeyManagers. These objects must properly
* loaded/initialized by the caller.
*/
public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManager[] keyManagers) throws IOException {
SSLServerSocketFactory res = null;
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(loadedKeyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
res = ctx.getServerSocketFactory();
} catch (Exception e) {
throw new IOException(e.getMessage());
}
return res;
}
use of javax.net.ssl.SSLServerSocketFactory in project cloudstack by apache.
the class ConsoleProxySecureServerFactoryImpl method createSSLServerSocket.
@Override
public SSLServerSocket createSSLServerSocket(int port) throws IOException {
try {
SSLServerSocket srvSock = null;
SSLServerSocketFactory ssf = sslContext.getServerSocketFactory();
srvSock = (SSLServerSocket) ssf.createServerSocket(port);
srvSock.setEnabledProtocols(SSLUtils.getSupportedProtocols(srvSock.getEnabledProtocols()));
s_logger.info("create SSL server socket on port: " + port);
return srvSock;
} catch (Exception ioe) {
s_logger.error(ioe.toString(), ioe);
}
return null;
}
use of javax.net.ssl.SSLServerSocketFactory in project jdk8u_jdk by JetBrains.
the class SSLEchoServer method init.
/*
* Creates server instance.
*
* @param cipherSuiteFilter Filter for enabled cipher suites
* @param sniMatcherPattern Pattern for SNI server hame
*/
static SSLEchoServer init(String cipherSuiteFilter, String sniPattern) throws NoSuchAlgorithmException, IOException {
SSLContext context = SSLContext.getDefault();
SSLServerSocketFactory ssf = (SSLServerSocketFactory) context.getServerSocketFactory();
SSLServerSocket ssocket = (SSLServerSocket) ssf.createServerSocket(0);
// specify enabled cipher suites
if (cipherSuiteFilter != null) {
String[] ciphersuites = UnboundSSLUtils.filterStringArray(ssf.getSupportedCipherSuites(), cipherSuiteFilter);
System.out.println("Server: enabled cipher suites: " + Arrays.toString(ciphersuites));
ssocket.setEnabledCipherSuites(ciphersuites);
}
// specify SNI matcher pattern
if (sniPattern != null) {
System.out.println("Server: set SNI matcher: " + sniPattern);
SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
List<SNIMatcher> matchers = new ArrayList<>();
matchers.add(matcher);
SSLParameters params = ssocket.getSSLParameters();
params.setSNIMatchers(matchers);
ssocket.setSSLParameters(params);
}
return new SSLEchoServer(ssocket);
}
use of javax.net.ssl.SSLServerSocketFactory in project jdk8u_jdk by JetBrains.
the class Timeout method main.
public static void main(String[] args) throws Exception {
// try {
SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket();
String[] protocols = ss.getSupportedProtocols();
for (int i = 0; i < protocols.length; i++) {
// try {
if (protocols[i].equals("SSLv2Hello")) {
continue;
}
SSLContext sslc = SSLContext.getInstance(protocols[i]);
SSLSessionContext sslsc = sslc.getServerSessionContext();
System.out.println("Protocol: " + protocols[i]);
sslsc.setSessionTimeout(Integer.MAX_VALUE);
int newtime = sslsc.getSessionTimeout();
if (newtime != Integer.MAX_VALUE) {
throw new Exception("Expected timeout: " + Integer.MAX_VALUE + ", got instead: " + newtime);
}
// } catch (Exception e) {
// }
}
// } catch (Exception e) {
// System.out.println(e);
// }
System.out.println("Finished");
}
use of javax.net.ssl.SSLServerSocketFactory in project jdk8u_jdk by JetBrains.
the class PrintSSL method main.
public static void main(String[] args) throws Exception {
System.setProperty("javax.net.ssl.keyStorePassword", "passphrase");
System.setProperty("javax.net.ssl.keyStore", System.getProperty("test.src", "./") + "/../../ssl/etc/keystore");
SSLServerSocketFactory sslssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
final ServerSocket server = sslssf.createServerSocket(0);
System.out.println(server.getLocalPort());
System.out.flush();
Thread t = new Thread() {
public void run() {
try {
Thread.sleep(30000);
server.close();
} catch (Exception e) {
;
}
throw new RuntimeException("Timeout");
}
};
t.setDaemon(true);
t.start();
((SSLSocket) server.accept()).startHandshake();
}
Aggregations