Java https URL主机名与公用名(CN)不匹配,尽管设置为';禁用cncheck';真实

Java https URL主机名与公用名(CN)不匹配,尽管设置为';禁用cncheck';真实,java,web-services,ssl,https,cxf,Java,Web Services,Ssl,Https,Cxf,我成功地正确配置了基于CXF的客户端,以便它为运行web服务的服务器找到正确的SSL证书: <http:conduit name="https://myserver/myws/register/soap?wsdl:{http://glob.reg.com/myws}.http-conduit"> <http:tlsClientParameters> <sec:keyManagers keyPassword="changeit">

我成功地正确配置了基于CXF的客户端,以便它为运行web服务的服务器找到正确的SSL证书:

  <http:conduit name="https://myserver/myws/register/soap?wsdl:{http://glob.reg.com/myws}.http-conduit">

    <http:tlsClientParameters>
      <sec:keyManagers keyPassword="changeit">
        <sec:keyStore type="JKS" password="changeit"
                  file="C:\Program Files (x86)\Java\jdk1.6.0_45\jre\lib\security\cacerts"/> 
       </sec:keyManagers>
      <sec:trustManagers>
        <sec:keyStore type="JKS" password="changeit"
                  file="C:\Program Files (x86)\Java\jdk1.6.0_45\jre\lib\security\cacerts"/> 
      </sec:trustManagers>
      <sec:cipherSuitesFilter>
        <!-- these filters ensure that a ciphersuite with
             export-suitable or null encryption is used,
             but exclude anonymous Diffie-Hellman key change as
             this is vulnerable to man-in-the-middle attacks -->
        <sec:include>.*_EXPORT_.*</sec:include>
        <sec:include>.*_EXPORT1024_.*</sec:include>
        <sec:include>.*_WITH_DES_.*</sec:include>
        <sec:include>.*_WITH_AES_.*</sec:include>
        <sec:include>.*_WITH_NULL_.*</sec:include>
        <sec:exclude>.*_DH_anon_.*</sec:exclude>
      </sec:cipherSuitesFilter>
    </http:tlsClientParameters>
    <http:authorization>
      <sec:UserName>Betty</sec:UserName>
      <sec:Password>password</sec:Password>
    </http:authorization>
    <http:client AutoRedirect="true" Connection="Keep-Alive"/>

  </http:conduit>
所以…因为这是一个开发/测试系统,所以我按照建议的消息做了(将CXF客户端TLS配置属性“disableCNCheck”设置为true):

但是…我仍然得到相同的错误:

Caused by: java.io.IOException: The https URL hostname does not match the Common Name (CN) on the server certificate in the client's truststore.  Make sure serv
er certificate is correct, or to disable this check (NOT recommended for production) set the CXF client TLS configuration property "disableCNCheck" to true.
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.onFirstWrite(HTTPConduit.java:1234)
        at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.onFirstWrite(URLConnectionHTTPConduit.java:183)
        at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
        at org.apache.cxf.io.AbstractThresholdOutputStream.write(AbstractThresholdOutputStream.java:69)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1293)
        ... 18 more
知道为什么吗

我的意思是,上面的一种变通方法应该足以让客户端忽略证书URL不匹配,但是,在我的情况下,这两种方法都不起作用,也不起作用


为什么?

我在以下几个例子中使用了CXF

<http:tlsClientParameters disableCNCheck="true">

已足够禁用CN检查

您确定您的客户机正在使用该导管配置吗?我的理解是,管道名称模式需要以某种方式匹配端点URI

尝试按如下所示设置导管名称,以便任何端点都匹配,并查看这是否会更改任何内容:

<http:conduit name="*.http-conduit">

2015年1月2日更新 原来
httpconductor
配置名称匹配有两种模式格式。一个涉及服务的名称空间和端口名。另一种受支持的格式是与用于创建客户端的WSDL中指定的URL端点相匹配的正则表达式

关于
http管道
元素的报价:

该名称包括服务的名称空间、WSDL端口名称(如下所示) 可在wsdl的wsdl:service部分找到),以及“.http管道”。 它遵循以下模板:

{WSDL Namespace}portName.http管道

注意:它是端口名,而不是服务名

另一种选择 name属性是一个reg-ex表达式(例如“:*”) 用于端点的原始URL。配置在以下位置匹配: 导管创建,以便在WSDL中使用或用于 名称可以使用JAX-WS Service.create(…)调用


-djse.enableSNIExtension=false
放入appserver虚拟机选项中。

添加下面的代码以设置disableCNCheck

 HTTPConduit httpConduit=(HTTPConduit)ClientProxy.getClient(port).getConduit();
        TLSClientParameters tlsCP = new TLSClientParameters();
        tlsCP.setDisableCNCheck(true);
        httpConduit.setTlsClientParameters(tlsCP);

仅在较低的环境中使用此代码,不建议在较高的环境中使用此代码。

调用url时使用主机的FQDN名称,因为它将尝试与证书中存在的url匹配,并且通常仅使用FQDN生成证书。
因为disableCNcheck不是一种可取的方法。

在使用tomcat运行时,这个解决方案对我很有效。创建一个禁用主机名验证的jar,并将其作为javaagent传递给运行时容器。

注意:这将禁用该JVM进程中所有其他SSL连接的CN检查#justsayinI在我的项目中尝试了这个方法(配置IntellijMaven运行程序来添加这个开关),但没有成功。
<http:tlsClientParameters disableCNCheck="true">
<http:conduit name="*.http-conduit">
 HTTPConduit httpConduit=(HTTPConduit)ClientProxy.getClient(port).getConduit();
        TLSClientParameters tlsCP = new TLSClientParameters();
        tlsCP.setDisableCNCheck(true);
        httpConduit.setTlsClientParameters(tlsCP);