Java 类com.sun.net.httpserver.HttpsParameters 实例源码

项目:cosmic    文件:ConsoleProxySecureServerFactoryImpl.java   
@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;
}
项目:ant-http    文件:AbstractHttpServerTest.java   
protected void startHttpsServer() throws Exception {
  final InetSocketAddress addr = new InetSocketAddress(httpsServerPort);
  httpsServer = HttpsServer.create(addr, 0);
  httpsServer.setExecutor(Executors.newCachedThreadPool());
  attachHttpHandlers(httpsServer);

  final char[] passphrase = KEYSTORE_PASSWORD.toCharArray();
  final KeyStore ks = KeyStore.getInstance("JKS");
  ks.load(getKeyStore(), passphrase);

  final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmf.init(ks, passphrase);

  final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmf.init(ks);

  final SSLContext ssl = SSLContext.getInstance("TLS");
  ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

  httpsServer.setHttpsConfigurator(new HttpsConfigurator(ssl) {
    @Override
    public void configure(final HttpsParameters params) {
      final SSLContext c = getSSLContext();
      final SSLParameters sslparams = c.getDefaultSSLParameters();
      params.setSSLParameters(sslparams);
    }
  });

  httpsServer.start();
}
项目:cloudstack    文件:ConsoleProxySecureServerFactoryImpl.java   
@Override
public HttpServer createHttpServerInstance(int port) throws IOException {
    try {
        HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
        server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
            @Override
            public void configure(HttpsParameters params) {

                // get the remote address if needed
                InetSocketAddress remote = params.getClientAddress();
                SSLContext c = getSSLContext();

                // get the default parameters
                SSLParameters sslparams = c.getDefaultSSLParameters();

                params.setSSLParameters(sslparams);
                params.setProtocols(SSLUtils.getRecommendedProtocols());
                params.setCipherSuites(SSLUtils.getRecommendedCiphers());
                // 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 (Exception ioe) {
        s_logger.error(ioe.toString(), ioe);
    }
    return null;
}
项目:pi    文件:SimpleHttpsServerFactoryBeanTest.java   
@Test
public void shouldSetHttpsParametersOnEveryRequest() throws Exception {
    // setup
    final SSLParameters defaultSslParameters = mock(SSLParameters.class);
    final String[] cipherSuites = new String[0];
    final String[] protocols = new String[0];
    SSLEngine sslEngine = mock(SSLEngine.class);
    when(sslEngine.getEnabledCipherSuites()).thenReturn(cipherSuites);
    when(sslEngine.getEnabledProtocols()).thenReturn(protocols);

    when(sslContext.getDefaultSSLParameters()).thenReturn(defaultSslParameters);
    when(sslContext.createSSLEngine()).thenReturn(sslEngine);

    doAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {

            HttpsParameters httpsParameters = mock(HttpsParameters.class);

            HttpsConfigurator httpsConfigurator = (HttpsConfigurator) invocation.getArguments()[0];
            httpsConfigurator.configure(httpsParameters);

            verify(httpsParameters).setSSLParameters(defaultSslParameters);
            verify(httpsParameters).setNeedClientAuth(false);
            verify(httpsParameters).setWantClientAuth(false);
            verify(httpsParameters).setCipherSuites(cipherSuites);
            verify(httpsParameters).setProtocols(protocols);

            return null;
        }
    }).when(httpsServer).setHttpsConfigurator(isA(HttpsConfigurator.class));

    // act
    HttpServer result = simpleHttpsServerFactoryBean.getInitializedServer(inetSocketAddress);

    // assert
    verify(httpsServer).setHttpsConfigurator(isA(HttpsConfigurator.class));
    assertEquals(httpsServer, result);
}
项目:languagetool    文件:HTTPSServer.java   
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);
        }
      };
}
项目:openjdk-jdk10    文件:ManyRequests.java   
public void configure(HttpsParameters params) {
    params.setSSLParameters(getSSLContext().getSupportedSSLParameters());
}
项目:openjdk-jdk10    文件:ProxyTest.java   
@Override
public void configure (HttpsParameters params) {
    params.setSSLParameters (getSSLContext().getSupportedSSLParameters());
}
项目:openjdk-jdk10    文件:ProxyTest2.java   
@Override
public void configure (HttpsParameters params) {
    params.setSSLParameters (getSSLContext().getSupportedSSLParameters());
}
项目:openjdk-jdk10    文件:SmokeTest.java   
public void configure (HttpsParameters params) {
    params.setSSLParameters (getSSLContext().getSupportedSSLParameters());
}
项目:openjdk-jdk10    文件:HTTPTestServer.java   
@Override
public void configure (HttpsParameters params) {
    params.setSSLParameters (getSSLContext().getSupportedSSLParameters());
}
项目:TurteTracker_APIServer    文件:Server.java   
private static HttpServer setUpHttps(JSONObject config) throws Exception {
    HttpServer server = HttpsServer.create(new InetSocketAddress(config.getInt("httpsPort")), 0);
    SSLContext sslContext = SSLContext.getInstance("TLS");

    // initialise the keystore
    char[] password = "84267139".toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    FileInputStream fis = new FileInputStream("www_turtledev_org.jks");
    ks.load(fis, password);
    // setup the key manager factory
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks, password);

    // setup the trust manager factory
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    tmf.init(ks);

    // setup the HTTPS context and parameters
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    ((HttpsServer) server).setHttpsConfigurator(new HttpsConfigurator(sslContext) {
        @Override
        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 (NoSuchAlgorithmException ex) {
                System.out.println("Failed to create HTTPS port");
            }
        }
    });
    return server;
}
项目:GladiatorManager    文件:HttpsApiServer.java   
public void initHttpsServer(int port, String sslPassword)
{
  try
  {
    this.server = HttpsServer.create(new InetSocketAddress(port), 0);
    SSLContext sslContext = SSLContext.getInstance("TLS");
    char[] password = sslPassword.toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    FileInputStream fis = new FileInputStream("https_key.jks");
    ks.load(fis, password);
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks, password);
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    tmf.init(ks);
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    this.server.setHttpsConfigurator(new HttpsConfigurator(sslContext)
    {
      @Override
      public void configure(HttpsParameters params)
      {
        try
        {
          SSLContext c = SSLContext.getDefault();
          SSLEngine engine = c.createSSLEngine();
          params.setNeedClientAuth(false);
          params.setCipherSuites(engine.getEnabledCipherSuites());
          params.setProtocols(engine.getEnabledProtocols());
          SSLParameters defaultSSLParameters = c.getDefaultSSLParameters();
          params.setSSLParameters(defaultSSLParameters);
        }
        catch (Exception ex)
        {
          System.out.println("Failed to create HTTPS port");
        }
      }
    });
    this.server.setExecutor(null); // creates a default executor
  }
  catch (Exception e)
  {
    System.out.println("Exception while starting RequestListener.");
    e.printStackTrace();
  }
}
项目:AdobeSignJavaSdk    文件:LocalHttpsServer.java   
public void Start(int port) {
  try {
    // load certificate
    String keystoreFilename =  Constants.KEY_STORE_FILE;
    char[] storepass = Constants.KEY_STORE_PASSWORD.toCharArray();
    char[] keypass = Constants.KEY_STORE_PASSWORD.toCharArray();
    FileInputStream fIn = new FileInputStream(Constants.SERVER_PATH + keystoreFilename);
    KeyStore keystore = KeyStore.getInstance(KEY_STORE);
    keystore.load(fIn, storepass);

    // setup the key manager factory
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEY_MANAGER_FACTORY);
    kmf.init(keystore, keypass);

    // setup the trust manager factory
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(KEY_MANAGER_FACTORY);
    tmf.init(keystore);

    // create https server
    server = HttpsServer.create(new InetSocketAddress(port), 0);
    // create ssl context
    SSLContext sslContext = SSLContext.getInstance(protocol);
    // 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) {
          System.err.println(Errors.START_HTTPS_SERVER);
        }
      }
    });
    System.out.println(SERVER_STARTED + port);
    server.createContext(ROOT_ENDPOINT, new OAuthHandler.RootHandler());
    server.createContext(OAUTH_ENDPOINT, new OAuthHandler.AuthorizationHandler());
    server.createContext(REDIRECT_ENDPOINT, new OAuthHandler.RedirectUriHandler());
    server.setExecutor(null);
    server.start();
  } catch (Exception e) {
    System.err.println(e);
  }
}
项目:http-servlet    文件:HttpServer.java   
public Boolean start() {
    try {
        final Integer maxQueue = 256;
        final Executor executor = Executors.newFixedThreadPool(maxQueue);

        if (_useEncryption) {
            final HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(_tlsPort), maxQueue);
            final TlsCertificate tlsCertificate = TlsFactory.loadTlsCertificate(StringUtil.bytesToString(IoUtil.getFileContents(_certificateFile)), IoUtil.getFileContents(_certificateKeyFile));
            final SSLContext sslContext = TlsFactory.createContext(tlsCertificate);

            httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
                @Override
                public void configure(final HttpsParameters params) {
                    params.setProtocols(new String[]{ "TLSv1.1", "TLSv1.2", "TLSv1.3" });
                    params.setNeedClientAuth(false);
                }
            });

            _applyEndpoints(httpsServer);
            httpsServer.setExecutor(executor);

            _tlsServer = httpsServer;
            _tlsServer.start();
        }

        if (! _disableHttp) {
            _server = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(_port), maxQueue);

            if (_redirectToTls) {
                _server.createContext("/", new HttpHandler(_encryptionRedirectEndpoint, false));
            }
            else {
                _applyEndpoints(_server);
            }

            _server.setExecutor(executor);
            _server.start();
        }

        return true;
    }
    catch (final Exception e) {
        e.printStackTrace();
        return false;
    }
}
项目:processeditor    文件:ProcessEditorServer.java   
/**
 * Initialize HttpServer instance
 * @throws Exception
 */
public void init() throws Exception {
    InetAddress host = null;
    if (ProcessEditorServerHelper.getHost() != null) {
        host = InetAddress.getByName(ProcessEditorServerHelper.getHost());
    }

    if (host != null) {
        // Bind to specific interface
        address = new InetSocketAddress(host, port);
    } else {
        // Bind to all interfaces
        System.out.println("BINDING TO ALL INTERFACES");
        address = new InetSocketAddress(port);
    }
    //secure = true;
    if (ProcessEditorServerHelper.isSecure()) {
        KeyStore ks = KeyStore.getInstance("JKS");
        char[] pwd = "inubit".toCharArray();
        ks.load(ProcessEditorServer.class.getResourceAsStream(KEY_STORE), pwd);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(ks, pwd);

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(ks);

        SSLContext ssl = SSLContext.getInstance("TLS");
        ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        this.server = HttpsServer.create(address, 255);

        ((HttpsServer) this.server).setHttpsConfigurator(new HttpsConfigurator(ssl) {

            public void configure(HttpsParameters params) {
                // get the remote address if needed
                InetSocketAddress remote = params.getClientAddress();

                SSLContext c = getSSLContext();

                // get the default parameters
                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.

            }
        });
    } else {
        this.server = HttpServer.create(address, 255);
    }

    System.out.println("[Server] Setting up server at " + address.getAddress().getHostAddress() + ":" + address.getPort());
    logger.info("[Server] Setting up server at " + address.getAddress().getHostAddress() + ":" + address.getPort());

    for (AbstractHandler h : handlers) {
        server.createContext(h.getContextUri(), h);
    }

    BlockingQueue queue = new ProcessEditorBlockingQueue(1000);
    ThreadPoolExecutor exec = new ProcessEditorThreadPoolExecutor(10, 20, 5000, TimeUnit.MILLISECONDS, queue);

    TemporaryKeyManager.initialize();

    server.setExecutor(exec); // creates executor

    this.setup = true;
}
项目:ribbon    文件:MockHttpServer.java   
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());
}