Search in sources :

Example 6 with HttpsParameters

use of com.sun.net.httpserver.HttpsParameters in project data-transfer-project by google.

the class ReferenceApiServer method createServer.

private HttpServer createServer(int port) throws Exception {
    if (trustManagerFactory == null || keyManagerFactory == null) {
        return HttpServer.create(new InetSocketAddress(port), 0);
    }
    HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 0);
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
    server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {

        public void configure(HttpsParameters params) {
            try {
                SSLContext context = SSLContext.getDefault();
                SSLEngine engine = context.createSSLEngine();
                params.setCipherSuites(engine.getEnabledCipherSuites());
                params.setProtocols(engine.getEnabledProtocols());
                SSLParameters defaultSSLParameters = context.getDefaultSSLParameters();
                params.setSSLParameters(defaultSSLParameters);
                params.setNeedClientAuth(false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return server;
}
Also used : HttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator) SSLParameters(javax.net.ssl.SSLParameters) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) HttpsParameters(com.sun.net.httpserver.HttpsParameters) SSLContext(javax.net.ssl.SSLContext) HttpsServer(com.sun.net.httpserver.HttpsServer)

Example 7 with HttpsParameters

use of com.sun.net.httpserver.HttpsParameters in project cloudstack by apache.

the class ConsoleProxySecureServerFactoryImpl method createHttpServerInstance.

@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;
}
Also used : HttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator) SSLParameters(javax.net.ssl.SSLParameters) InetSocketAddress(java.net.InetSocketAddress) HttpsParameters(com.sun.net.httpserver.HttpsParameters) SSLContext(javax.net.ssl.SSLContext) HttpsServer(com.sun.net.httpserver.HttpsServer) IOException(java.io.IOException)

Aggregations

HttpsConfigurator (com.sun.net.httpserver.HttpsConfigurator)7 HttpsParameters (com.sun.net.httpserver.HttpsParameters)7 SSLContext (javax.net.ssl.SSLContext)7 SSLParameters (javax.net.ssl.SSLParameters)7 HttpsServer (com.sun.net.httpserver.HttpsServer)5 InetSocketAddress (java.net.InetSocketAddress)5 IOException (java.io.IOException)3 SSLEngine (javax.net.ssl.SSLEngine)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 HttpHandler (com.sun.net.httpserver.HttpHandler)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 BindException (java.net.BindException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1