httpsServer.setHttpsConfigurator ( new HttpsConfigurator( sslContext )
@Override public void configure( final HttpsParameters params ) { final SSLContext sslContext = getSSLContext(); final SSLParameters sslParams = sslContext.getDefaultSSLParameters(); params.setSSLParameters( sslParams ); super.configure( params ); } } );
public void setHttpsConfigurator (HttpsConfigurator config) { if (config == null) { throw new NullPointerException ("null HttpsConfigurator"); } if (started) { throw new IllegalStateException ("server already started"); } this.httpsConfig = config; sslContext = config.getSSLContext(); }
private void configureEngine(HttpsConfigurator cfg, InetSocketAddress addr){ if (cfg != null) { Parameters params = new Parameters (cfg, addr); cfg.configure (params); { /* tiger compatibility */ if (params.getCipherSuites() != null) { try { engine.setEnabledCipherSuites ( params.getCipherSuites() ); } catch (IllegalArgumentException e) { /* LOG */} } engine.setNeedClientAuth (params.getNeedClientAuth()); engine.setWantClientAuth (params.getWantClientAuth()); if (params.getProtocols() != null) { try { engine.setEnabledProtocols ( params.getProtocols() ); } catch (IllegalArgumentException e) { /* LOG */} } } } }
SSLContext sslContext = getSSLContext(); SSLParameters sslParams = sslContext.getDefaultSSLParameters(); sslParams.setNeedClientAuth(true);
final boolean isHttp = "http".equalsIgnoreCase(scheme); final boolean isHttps = "https".equalsIgnoreCase(scheme); final HttpsConfigurator httpsConfigurator = sslContext != null ? new HttpsConfigurator(sslContext) : null;
/** * Internal method which creates and starts the server. * * @param httpsMode True if the server to be started is HTTPS, false otherwise. * @return Started server. */ private static GridEmbeddedHttpServer createAndStart(boolean httpsMode) throws Exception { HttpServer httpSrv; InetSocketAddress addrToBind = new InetSocketAddress(HOSTNAME_TO_BIND_SRV, getAvailablePort()); if (httpsMode) { HttpsServer httpsSrv = HttpsServer.create(addrToBind, 0); httpsSrv.setHttpsConfigurator(new HttpsConfigurator(GridTestUtils.sslContext())); httpSrv = httpsSrv; } else httpSrv = HttpServer.create(addrToBind, 0); GridEmbeddedHttpServer embeddedHttpSrv = new GridEmbeddedHttpServer(); embeddedHttpSrv.proto = httpsMode ? "https" : "http"; embeddedHttpSrv.httpSrv = httpSrv; embeddedHttpSrv.httpSrv.start(); return embeddedHttpSrv; }
SSLContext ssl = SSLContext.getInstance("TLS"); KeyManagerFactory keyFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); KeyStore store = KeyStore.getInstance("JKS"); store.load(new FileInputStream(keystoreFile),keyPass.toCharArray()); keyFactory.init(store, keyPass.toCharArray()); TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustFactory.init(store); ssl.init(keyFactory.getKeyManagers(), trustFactory.getTrustManagers(), new SecureRandom()); HttpsConfigurator configurator = new HttpsConfigurator(ssl); HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(hostname, port), port); httpsServer.setHttpsConfigurator(configurator); HttpContext httpContext = httpsServer.createContext(uri); httpsServer.start(); endpoint.publish(httpContext);
SSLContext sslContext = SSLContext.getInstance("TLS"); char[] keystorePassword = "password".toCharArray(); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream("filename.jks"), keystorePassword); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, keystorePassword); sslContext.init(kmf.getKeyManagers(), null, null); HttpsConfigurator configurator = new HttpsConfigurator(sslContext);
HttpsConfigurator cfg = new HttpsConfigurator(sslCtx){ public void configure(HttpsParameters params) { SSLParameters sslparams = getSSLContext().getDefaultSSLParameters(); // Modify the default params: // Using this, server will require client certs //sslparams.setNeedClientAuth(true); // Using this, server will request client certs. But if not available, // it will continue anyway. sslparams.setWantClientAuth(true); params.setSSLParameters(sslparams); } }; HttpsServer httpsS = HttpsServer.create(new InetSocketAddress(8081), 50); httpsS.setHttpsConfigurator(cfg);
private static HttpsServer createHttpsServer(int port) throws Exception { generateCertificate(); HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(port), 0); SSLContext sslContext = getSslContext(); httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); return httpsServer; }
final boolean isHttp = "http".equalsIgnoreCase(scheme); final boolean isHttps = "https".equalsIgnoreCase(scheme); final HttpsConfigurator httpsConfigurator = sslContext != null ? new HttpsConfigurator(sslContext) : null;