我正在尝试创建一个使用 TSLv1.2 协议执行握手的 SSL 套接字工厂。
到目前为止我所拥有的[1/18 更新]:
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
ServerSocketFactory sf = SSLServerSocketFactory.getDefault();
KeyManager[] km = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()).getKeyManagers();
TrustManager[] tm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()).getTrustManagers();
SecureRandom random = new SecureRandom();
sslContext.init(km, tm, random);
requestContext.put(BindingProviderProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
我希望从 中获取 KeyManager、TrustManager 和 SecureRandom 对象SSLServerSocketFactory.getDefault()
,但没有获取器。
我可以从另一个地方拉这个吗?或更有效的方法来做到这一点?
我不想手动创建密钥和信任管理器以避免需要系统特定的配置。
完整方法供参考:
public MyOutBoundClientWSImpl(URL wsdlUrl){
super(wsdlUrl, serviceName);
this.wsUrl=wsdlUrl;
this.mService = this.getMySoapHttpPort();
Map<String, Object> requestContext = ((BindingProvider)mService).getRequestContext();
requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, REQUEST_TIMEOUT); // Timeout in millis
requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT); // Timeout in millis
try {
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
ServerSocketFactory sf = SSLServerSocketFactory.getDefault();
KeyManager[] km = ??;
TrustManager[] tm = ??;
SecureRandom random = ??;
sslContext.init(km, tm, random);
requestContext.put(BindingProviderProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory());
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}