2014-01-28 45 views

回答

0

我认为 “正常” 的代码初始化SSLContext将工作。

示例如何加载信任:

String path = .... 
char[] password = .... 
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); 
keyStore.load(new FileInputStream(path), password); 
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
tmf.init(keyStore); 
SSLContext ctx = SSLContext.getInstance("SSL"); 
ctx.init(null, tmf.getTrustManagers(), null); 

如果您还需要客户端证书密钥库,以类似的方式使用KeyStoreFactory或实施KeyManager

+0

难道我不需要添加密钥库和TrustStore到ClientConfig,比如Jersey客户端? // import com.sun.jersey.api.client.config.ClientConfig; // import com.sun.jersey.api.client.config.DefaultClientConfig; ClientConfig config = new DefaultClientConfig(); (),HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,new HTTPSProperties(getHostnameVerifier(),getSSLContext()));这个方法可以用来创建一个新的HTTPSProperties对象。 – DarVar

+0

据我记得,默认使用HttpsURLConnection,这意味着将使用默认的SSLContext。 – Tarlog

+0

您可以配置到眨眼使用Apache HTTP客户端,在这种情况下,你需要SSL配置传递到客户端 – Tarlog

相关问题