我们在为证书进行握手时遇到问题,例如
javax.net.ssl.SSLPeerUnverifiedException: Certificate for <g.i.t.n.c.com> doesn't match any of the subject alternative names: [*.t.n.c.com]
我们的入口配置为提供具有备用名称的证书
g.i.t.n.c.com
(如果我们通过 DNS 名称访问它)和 *.t.n.c.com
(如果我们通过 IP 访问)。
但是在我们的代码中,我们只有一个
Spring WS
客户端在后台使用 Apache Http Client
。
Caused by: javax.net.ssl.SSLPeerUnverifiedException: Certificate for <g.i.t.n.c.com> doesn't match any of the subject alternative names: [*.t.n.c.com]
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:507)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:437)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.springframework.ws.transport.http.HttpComponentsConnection.onSendAfterWrite(HttpComponentsConnection.java:121)
at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:48)
at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:658)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
由于未知的原因,这种情况在某个时候开始发生,在某个时候一切正常,并建立了
SslSocket
来检索正确的证书(就像它通过 Ingress
主机名和 DNS
主机名数据访问我们的 SNI
一样)在某些时候(导致上述异常),建立连接的调用使用的是没有 DNS hostname
且没有 SNI
数据的 IP,并且只有在 DNS name
中没有
SNI
的情况下访问我们的入口时才会出现损坏的证书.
要获取
SNI
详细信息(ClientHello
消息),您可以使用运行Java应用程序
-Djavax.net.debug=ssl:handshake:verbose:keymanager:trustmanager
您将有额外的登录权限
std.out
喜欢
javax.net.ssl|DEBUG|02 14|XNIO-1 task-9|2023-09-04 12:48:06.626 MSK|Finished.java:860|Consuming server Finished handshake message (
如何强制它只使用一种方式进行连接,即随时使用 DNS 名称?
我们使用 Java 11。
https://bugs.openjdk.org/browse/JDK-8220723这是问题的根本原因
为了解决这个问题,我们强制 TLS1.2 工作,以避免使用 TLS1.3
添加
-Djdk.tls.client.protocols=TLSv1.2
或
-Dhttps.protocols=TLSv1.2