- HttpsServer server = HttpsServer.create(new InetSocketAddress(iPort), 0);
- SSLContext sslContext = SSLContext.getInstance("TLS");
-
- // initialise the keystore
- char[] password = PASSWORD.toCharArray();
- KeyStore ks = KeyStore.getInstance(KEYINSTANCE);
- FileInputStream fis = new FileInputStream(strAddress + KEYEXT);
- ks.load(fis, password);
-
- // setup the key manager factory
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEYTYPE);
- kmf.init(ks, password);
-
- // setup the trust manager factory
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(KEYTYPE);
- tmf.init(ks);
-
- // setup the HTTPS context and parameters
- sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
- server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
- public void configure(HttpsParameters params) {
- try {
- // initialise the SSL context
- SSLContext c = SSLContext.getDefault();
- SSLEngine engine = c.createSSLEngine();
- params.setNeedClientAuth(false);
- params.setCipherSuites(engine.getEnabledCipherSuites());
- params.setProtocols(engine.getEnabledProtocols());
-
- // get the default parameters
- SSLParameters defaultSSLParameters = c.getDefaultSSLParameters();
- params.setSSLParameters(defaultSSLParameters);
-
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- });
-