【发布时间】:2017-06-02 08:47:45
【问题描述】:
从一个 java 应用程序中,我想使用两个信任库,一个连接到 jms 代理,另一个连接到 Web 服务。我知道我可以将证书导入到一个信任库中,这很有效。但是,我在徘徊是否可以使用系统属性 javax.net.ssl.trustStore 传递不同信任库的列表?
【问题讨论】:
从一个 java 应用程序中,我想使用两个信任库,一个连接到 jms 代理,另一个连接到 Web 服务。我知道我可以将证书导入到一个信任库中,这很有效。但是,我在徘徊是否可以使用系统属性 javax.net.ssl.trustStore 传递不同信任库的列表?
【问题讨论】:
不,你不能。要使用不同的信任库,您应该以编程方式设置其中之一或两者。
请参阅下面来自 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);
【讨论】: