我正在尝试连接到受相互身份验证保护的Web服务。
我正在使用cxf Web客户端,并且客户端的配置如下所示
KeyStore keyStore = KeyStore.getInstance("JKS");
KeyStore trustStore = KeyStore.getInstance("JKS");
String keystorepass = "***";
String trustpass = "***";
File truststore = new File("trustfile");
File keystoreFile = new File("keyfile");
keyStore.load(new FileInputStream(keystoreFile), keystorepass.toCharArray());
trustStore.load(new FileInputStream(truststore), trustpass.toCharArray());
tlsParams.setDisableCNCheck(true);
tlsParams.setSecureSocketProtocol("TLSv1.2");
TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(trustStore);
TrustManager[] tm = trustFactory.getTrustManagers();
tlsParams.setTrustManagers(tm);
KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyFactory.init(keyStore, keystorepass.toCharArray());
KeyManager[] km = keyFactory.getKeyManagers();
tlsParams.setKeyManagers(km);
FiltersType filter = new FiltersType();
filter.getInclude().add(".*_WITH_AES_.*");
filter.getExclude().add(".*_DH_anon_.*");
tlsParams.setCipherSuitesFilter(filter);
实际将消息发送到服务器的Web客户端代码如下
WebClient client = WebClient.create(tallyEndPoint);
client.path(partnerAuthUrl);
ClientConfiguration config = WebClient.getConfig(client);
config.getInInterceptors().add(new LoggingInInterceptor());
config.getOutInterceptors().add(new LoggingOutInterceptor());
HTTPConduit conduit =
(HTTPConduit) WebClient.getConfig(client).getConduit();
HTTPClientPolicy policy = conduit.getClient();
policy.setProxyServer(proxyUrl);
policy.setProxyServerPort(proxyPort);
conduit.setTlsClientParameters(tlsParams);
MultivaluedMap<String, String> formParams = new MultivaluedHashMap<>();
formParams.add("***", "***");
Form postForm = new Form(formParams);
client.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
Response response = client.form(postForm);enter code here
从服务器端数据包捕获中可以看到以下消息
我已在客户端中启用SSL调试,并且看到正在记录证书更改消息
我可以看到正在发生的动作
最后一个客户之后你好,我被断开了连接
tomcat-http--1,写:TLSv1.2握手,长度= 282
tomcat-http--1,处理异常:java.net.SocketException:连接重置
tomcat-http--1,发送TLSv1.2警报:致命,描述=意外消息
tomcat-http--1,写:TLSv1.2警报,长度= 2
tomcat-http--1,异常发送警报:java.net.SocketException:管道损坏
tomcat-http--1,称为closeSocket()
tomcat-http--1,写:TLSv1.2应用程序数据,长度= 472
tomcat-http--1,称为close()
tomcat-http--1,称为closeInternal(true)
tomcat-http--1,发送TLSv1.2警报:警告,说明= close_notify
tomcat-http--1,写:TLSv1.2警报,长度= 26
tomcat-http--1,称为closeSocket(true)
我确实拥有带有我的私钥的密钥库和一个添加并配置了服务器密钥链的信任库。
任何帮助都会得到极大的帮助