use of javax.net.ssl.SSLServerSocketFactory in project nanohttpd by NanoHttpd.
the class LoadKeyStoreTest method loadKeyStoreFromResources.
@Test
public void loadKeyStoreFromResources() throws Exception {
String keyStorePath = "/keystore.jks";
InputStream resourceAsStream = this.getClass().getResourceAsStream(keyStorePath);
assertNotNull(resourceAsStream);
SSLServerSocketFactory sslServerSocketFactory = NanoHTTPD.makeSSLSocketFactory(keyStorePath, "password".toCharArray());
assertNotNull(sslServerSocketFactory);
}
use of javax.net.ssl.SSLServerSocketFactory in project apjp by jvansteirteghem.
the class HTTPS method createSSLServerSocket.
public static synchronized SSLServerSocket createSSLServerSocket() throws HTTPSException {
try {
KeyStore defaultKeyStore = getDefaultKeyStore();
SSLContext sslContext = SSLContext.getInstance("TLS");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(defaultKeyStore, "APJP".toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(defaultKeyStore);
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
SSLServerSocketFactory sslServerSocketFactory = (SSLServerSocketFactory) sslContext.getServerSocketFactory();
return (SSLServerSocket) sslServerSocketFactory.createServerSocket();
} catch (Exception e) {
logger.log(2, "HTTPS/CREATE_SSL_SERVER_SOCKET: EXCEPTION", e);
throw new HTTPSException("HTTPS/CREATE_SSL_SERVER_SOCKET", e);
}
}
use of javax.net.ssl.SSLServerSocketFactory in project robovm by robovm.
the class SSLContextSpiTest method test_commonTest_01.
/**
* SSLContextSpi#engineGetClientSessionContext()
* SSLContextSpi#engineGetServerSessionContext()
* SSLContextSpi#engineGetServerSocketFactory()
* SSLContextSpi#engineGetSocketFactory()
* Verify exception when SSLContextSpi object wasn't initialiazed.
*/
public void test_commonTest_01() {
SSLContextSpiImpl ssl = new SSLContextSpiImpl();
try {
SSLSessionContext slsc = ssl.engineGetClientSessionContext();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
try {
SSLSessionContext slsc = ssl.engineGetServerSessionContext();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
try {
SSLServerSocketFactory sssf = ssl.engineGetServerSocketFactory();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
try {
SSLSocketFactory ssf = ssl.engineGetSocketFactory();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
}
use of javax.net.ssl.SSLServerSocketFactory in project jdk8u_jdk by JetBrains.
the class CookieHttpsClientTest method doServerSide.
/*
* Define the server side of the test.
*
* If the server prematurely exits, serverReady will be set to true
* to avoid infinite hangs.
*/
void doServerSide() throws Exception {
SSLServerSocketFactory sslssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket = (SSLServerSocket) sslssf.createServerSocket(serverPort);
serverPort = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
serverReady = true;
SSLSocket sslSocket = null;
try {
sslSocket = (SSLSocket) sslServerSocket.accept();
sslSocket.setSoTimeout(TIMEOUT);
readOneRequest(sslSocket.getInputStream());
sslSocket.getOutputStream().write(replyString.getBytes());
readOneRequest(sslSocket.getInputStream());
sslSocket.getOutputStream().write(replyString.getBytes());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (sslSocket != null) {
sslSocket.close();
}
sslServerSocket.close();
} catch (IOException unused) {
/* gulp!burp! */
}
}
}
use of javax.net.ssl.SSLServerSocketFactory in project zm-mailbox by Zimbra.
the class NetUtil method main.
public static void main(String[] args) {
SSLServerSocketFactory sf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
String[] supportedCipherSuites = sf.getSupportedCipherSuites();
System.out.println("\nsupported cipher suites:\n");
for (String c : supportedCipherSuites) System.out.println(c);
}
Aggregations