use of com.sun.net.httpserver.HttpsParameters in project cosmic by MissionCriticalCloud.
the class ConsoleProxySecureServerFactoryImpl method createHttpServerInstance.
@Override
public HttpServer createHttpServerInstance(final int port) throws IOException {
try {
final HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
@Override
public void configure(final HttpsParameters params) {
final SSLContext c = getSSLContext();
// get the default parameters
final SSLParameters sslparams = c.getDefaultSSLParameters();
params.setSSLParameters(sslparams);
// statement above could throw IAE if any params invalid.
// eg. if app has a UI and parameters supplied by a user.
}
});
s_logger.info("create HTTPS server instance on port: " + port);
return server;
} catch (final Exception ioe) {
s_logger.error(ioe.toString(), ioe);
}
return null;
}
use of com.sun.net.httpserver.HttpsParameters in project ribbon by Netflix.
the class MockHttpServer method before.
public void before(final Description description) throws Exception {
this.service = Executors.newFixedThreadPool(threadCount, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("TestHttpServer-%d").build());
InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 0);
if (hasSsl) {
byte[] sampleTruststore1 = Base64.decode(TEST_TS1);
byte[] sampleKeystore1 = Base64.decode(TEST_KS1);
keystore = File.createTempFile("SecureAcceptAllGetTest", ".keystore");
truststore = File.createTempFile("SecureAcceptAllGetTest", ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(keystore);
try {
keystoreFileOut.write(sampleKeystore1);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(truststore);
try {
truststoreFileOut.write(sampleTruststore1);
} finally {
truststoreFileOut.close();
}
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keystore), PASSWORD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, PASSWORD.toCharArray());
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(new FileInputStream(truststore), PASSWORD.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
HttpsServer secureServer = HttpsServer.create(inetSocketAddress, 0);
secureServer.setHttpsConfigurator(new HttpsConfigurator(sc) {
public void configure(HttpsParameters params) {
SSLContext c = getSSLContext();
SSLParameters sslparams = c.getDefaultSSLParameters();
params.setSSLParameters(sslparams);
}
});
server = secureServer;
} else {
server = HttpServer.create(inetSocketAddress, 0);
}
server.setExecutor(service);
for (Entry<String, HttpHandler> handler : handlers.entrySet()) {
server.createContext(handler.getKey(), handler.getValue());
}
server.start();
localHttpServerPort = server.getAddress().getPort();
System.out.println(description.getClassName() + " TestServer is started: " + getServerUrl());
}
use of com.sun.net.httpserver.HttpsParameters in project gradle by gradle.
the class BlockingHttpsServer method configure.
/**
* @param testKeyStore The key store to configure this server from.
* @param tlsProtocolFilter Used to prune the supported set of TLS versions
*/
public void configure(TestKeyStore testKeyStore, Predicate<String> tlsProtocolFilter) {
HttpsServer httpsServer = (HttpsServer) this.server;
SSLContext context = testKeyStore.asSSLContext();
httpsServer.setHttpsConfigurator(new HttpsConfigurator(context) {
@Override
public void configure(HttpsParameters params) {
SSLContext c = getSSLContext();
SSLEngine engine = c.createSSLEngine();
params.setNeedClientAuth(false);
params.setCipherSuites(engine.getEnabledCipherSuites());
// TLS protocols need to be filtered off both the HttpsParameters & SSLParameters
params.setProtocols(stripFilteredProtocols(engine.getEnabledProtocols()));
SSLParameters parameters = c.getDefaultSSLParameters();
parameters.setProtocols(stripFilteredProtocols(parameters.getProtocols()));
params.setSSLParameters(parameters);
}
private String[] stripFilteredProtocols(String[] allProtocols) {
return Arrays.stream(allProtocols).filter(tlsProtocolFilter).toArray(String[]::new);
}
});
}
use of com.sun.net.httpserver.HttpsParameters in project languagetool by languagetool-org.
the class HTTPSServer method getConfigurator.
private HttpsConfigurator getConfigurator(SSLContext sslContext) {
return new HttpsConfigurator(sslContext) {
@Override
public void configure(HttpsParameters params) {
SSLContext context = getSSLContext();
SSLParameters sslParams = context.getDefaultSSLParameters();
params.setNeedClientAuth(false);
params.setSSLParameters(sslParams);
}
};
}
use of com.sun.net.httpserver.HttpsParameters in project GNS by MobilityFirst.
the class GNSHttpsServer method tryPort.
/**
* Try to start the http server at the port.
*
* @param port
* @return true if it was started
*/
@Override
public boolean tryPort(int port) {
try {
InetSocketAddress addr = new InetSocketAddress(port);
httpsServer = HttpsServer.create(addr, 0);
SSLContext sslContext = createSSLContext();
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
@Override
public void configure(HttpsParameters parameters) {
// initialise the SSL context
SSLContext context = getSSLContext();
SSLEngine engine = context.createSSLEngine();
//parameters.setNeedClientAuth(false);
parameters.setCipherSuites(engine.getEnabledCipherSuites());
parameters.setProtocols(engine.getEnabledProtocols());
// get the default parameters
SSLParameters sslParameters = context.getDefaultSSLParameters();
sslParameters.setNeedClientAuth(true);
parameters.setNeedClientAuth(true);
parameters.setSSLParameters(sslParameters);
}
});
httpsServer.createContext("/", new EchoHttpHandler());
httpsServer.createContext("/" + GNS_PATH, new DefaultHttpHandler());
httpsServer.setExecutor(Executors.newCachedThreadPool());
httpsServer.start();
// Need to do this for the places where we expose the secure http service to the user
requestHandler.setHttpsServerPort(port);
LOG.log(Level.INFO, "HTTPS server is listening on port {0}", port);
return true;
} catch (BindException e) {
LOG.log(Level.FINE, "HTTPS server failed to start on port {0} due to {1}", new Object[] { port, e.getMessage() });
return false;
} catch (IOException | NoSuchAlgorithmException | KeyStoreException | CertificateException | UnrecoverableKeyException | KeyManagementException e) {
LOG.log(Level.FINE, "HTTPS server failed to start on port {0} due to {1}", new Object[] { port, e.getMessage() });
e.printStackTrace();
return false;
}
}
Aggregations