81,092
社区成员
发帖
与我相关
我的任务
分享
String contextPath = "./certs";
System.out.println("contextPath=" + contextPath);
HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(port)
.getConduit();
TLSClientParameters tlsCP = new TLSClientParameters();
// 服务器证书库
String keyPassword = "password";
KeyStore keyStore = KeyStore.getInstance("JKS");
String keyStoreLoc = contextPath + "/wibble.jks";
keyStore.load(new FileInputStream(keyStoreLoc),
keyPassword.toCharArray());
KeyManager[] myKeyManagers = getKeyManagers(keyStore, keyPassword);
tlsCP.setKeyManagers(myKeyManagers);
// 证书信任库
KeyStore trustStore = KeyStore.getInstance("JKS");
String trustStoreLoc = contextPath + "/truststore.jks";
trustStore.load(new FileInputStream(trustStoreLoc),
keyPassword.toCharArray());
TrustManager[] myTrustStoreKeyManagers = getTrustManagers(trustStore);
tlsCP.setTrustManagers(myTrustStoreKeyManagers);
// The following is not recommended and would not be done in a
// prodcution environment,
// this is just for illustrative purpose
tlsCP.setDisableCNCheck(true);
httpConduit.setTlsClientParameters(tlsCP);