Search in sources :

Example 1 with SecureServerSocketFactory

use of org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory in project nanohttpd by NanoHttpd.

the class ServerSocketFactoryTest method testSSLServerSocketFail.

@Test
public void testSSLServerSocketFail() {
    String[] protocols = { "" };
    System.setProperty("javax.net.ssl.trustStore", new File("src/test/resources/keystore.jks").getAbsolutePath());
    IFactoryThrowing<ServerSocket, IOException> ssFactory = new SecureServerSocketFactory(null, protocols);
    ServerSocket ss = null;
    try {
        ss = ssFactory.create();
    } catch (Exception e) {
    }
    Assert.assertTrue(ss == null);
}
Also used : SecureServerSocketFactory(org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with SecureServerSocketFactory

use of org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory in project nanohttpd by NanoHttpd.

the class SSLServerSocketFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("javax.net.ssl.trustStore", new File("src/test/resources/keystore.jks").getAbsolutePath());
    this.testServer = new TestServer(9043);
    this.testServer.setServerSocketFactory(new SecureServerSocketFactory(NanoHTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()), null));
    this.tempFileManager = new TestTempFileManager();
    this.testServer.start();
    try {
        long start = System.currentTimeMillis();
        Thread.sleep(100L);
        while (!this.testServer.wasStarted()) {
            Thread.sleep(100L);
            if (System.currentTimeMillis() - start > 2000) {
                Assert.fail("could not start server");
            }
        }
    } catch (InterruptedException e) {
    }
}
Also used : SecureServerSocketFactory(org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory) File(java.io.File) Before(org.junit.Before)

Example 3 with SecureServerSocketFactory

use of org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory in project nanohttpd by NanoHttpd.

the class SSLServerSocketFactoryTest method testCreatePassesTheProtocolsToServerSocket.

@Test
public void testCreatePassesTheProtocolsToServerSocket() throws IOException {
    // first find the supported protocols
    SecureServerSocketFactory secureServerSocketFactory = new SecureServerSocketFactory(NanoHTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()), null);
    SSLServerSocket socket = (SSLServerSocket) secureServerSocketFactory.create();
    String[] protocols = socket.getSupportedProtocols();
    // remove one element from supported protocols
    if (protocols.length > 0) {
        protocols = Arrays.copyOfRange(protocols, 0, protocols.length - 1);
    }
    // test
    secureServerSocketFactory = new SecureServerSocketFactory(NanoHTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()), protocols);
    socket = (SSLServerSocket) secureServerSocketFactory.create();
    Assert.assertArrayEquals("Enabled protocols specified in the factory were not set to the socket.", protocols, socket.getEnabledProtocols());
}
Also used : SecureServerSocketFactory(org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory) SSLServerSocket(javax.net.ssl.SSLServerSocket) Test(org.junit.Test)

Aggregations

SecureServerSocketFactory (org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory)3 File (java.io.File)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ServerSocket (java.net.ServerSocket)1 SSLServerSocket (javax.net.ssl.SSLServerSocket)1 Before (org.junit.Before)1