2017-06-02 58 views
2

從java應用程序中,我想使用兩個信任庫,一個連接到jms代理,另一個連接到Web服務。我知道我可以將證書導入到一個信任庫中,並且工作正常。然而,我在徘徊是否可以使用系統屬性javax.net.ssl.trustStore傳遞不同信任庫列表?Java應用程序使用兩個單獨的信任庫

回答

0

不,你不能。要使用不同的信任庫,您應該以編程方式設置其中一個或兩者。

查看來自該post示例下面:

SSLContext ssl = SSLContext.getInstance("SSLv3"); 
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 
    KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType()); 
    String password = Configuration.getConfig("keyStorePassword"); 
    store.load(new FileInputStream(new File(Configuration.getConfig("keyStore"))), password.toCharArray()); 
    kmf.init(store, password.toCharArray()); 
    KeyManager[] keyManagers = new KeyManager[1]; 
    keyManagers = kmf.getKeyManagers(); 
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
    tmf.init(store); 
    TrustManager[] trustManagers = tmf.getTrustManagers(); 
    ssl.init(keyManagers, trustManagers, new SecureRandom()); 

    HttpsConfigurator configurator = new HttpsConfigurator(ssl); 
    Integer port = Integer.parseInt(Configuration.getConfig("port")); 
    HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(Configuration.getConfig("host"), port), 0); 
    httpsServer.setHttpsConfigurator(configurator); 

    Implementor implementor = new Implementor(); // class with @WebService etc. 
    HttpContext context = (HttpContext) httpsServer.createContext("/EventWebService"); 
    Endpoint endpoint = Endpoint.create(implementor); 
    endpoint.publish(context); 
相關問題