Using javax.xml.ws.Endpoint with HTTPS

后端 未结 1 540
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 03:36

I\'m working on a project to control light and heating in buildings. The backend (written in Java) will run on a Mac Mini and should be accessible via SOAP.

I want

1条回答
  •  青春惊慌失措
    2020-12-24 04:40

    For server:

    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);
    

    For client, be sure you do this:

    System.setProperty("javax.net.ssl.trustStore", "path");
    System.setProperty("javax.net.ssl.keyStore", "password");
    System.setProperty("javax.net.ssl.keyStorePassword", "password");
    System.setProperty("javax.net.ssl.keyStoreType", "JKS");
    //done to prevent CN verification in client keystore
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
       @Override
       public boolean verify(String hostname, SSLSession session) {
         return true;
       }
    });
    

    0 讨论(0)
提交回复
热议问题