Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.security.cert.CertificateException:未找到与本地主机匹配的名称_Java_Ssl - Fatal编程技术网

java.security.cert.CertificateException:未找到与本地主机匹配的名称

java.security.cert.CertificateException:未找到与本地主机匹配的名称,java,ssl,Java,Ssl,在我的web应用程序中,当它试图向自身发出HTTP请求时,我得到了这个异常 javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl

在我的web应用程序中,当它试图向自身发出HTTP请求时,我得到了这个异常

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1946)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:316)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:310)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1639)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:223)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:965)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1064)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352)
    at com.smcc.od.common.capi.OdCommonHelper.processHttpURLConnection(OdCommonHelper.java:593)
    at com.smcc.od.common.pipelet.http.ProcessHttpURLConnection.execute(ProcessHttpURLConnection.java:113)
    at com.intershop.beehive.core.internal.pipeline.PipeletNode.executeNode(PipeletNode.java:346)
    at com.intershop.beehive.core.internal.pipeline.Pipeline.executeNode(Pipeline.java:1116)
    at com.intershop.beehive.core.internal.pipeline.Pipeline.executePipeline(Pipeline.java:944)
    at com.intershop.beehive.core.internal.pipeline.PipelineProcessorImpl.executePipeline(PipelineProcessorImpl.java:641)
    at com.intershop.beehive.core.internal.pipeline.PipelineProcessorImpl.executePipeline(PipelineProcessorImpl.java:484)
    at com.intershop.beehive.pipeline.internal.PipelineEngineImpl.executePipeline(PipelineEngineImpl.java:97)
    at com.intershop.beehive.core.internal.pipeline.PipelineProcessorImpl.executePipeline(PipelineProcessorImpl.java:421)
    at com.intershop.beehive.core.internal.pipeline.PipelineProcessorImpl.executePipeline(PipelineProcessorImpl.java:250)
    at com.intershop.beehive.core.pipelet.pipeline.ExecutePipeline$PipelineExecutor.run(ExecutePipeline.java:440)
    at com.intershop.beehive.core.internal.execute.ExecutorServiceImpl$ClosingCurrentResourcesRunnable.run(ExecutorServiceImpl.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.security.cert.CertificateException: No name matching localhost found
    at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:231)
    at sun.security.util.HostnameChecker.match(HostnameChecker.java:96)
    at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:462)
    at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:442)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:209)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:132)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1621)
    ... 28 common frames omitted
调用的URL类似于
https://localhost:448/foo/bar

为了寻找解决方案,我尝试创建一个自签名HTTPS证书,并将其导入JRE的密钥库

我已通过Powershell运行此命令,为
localhost
创建自签名证书:

New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName "localhost" -FriendlyName "localhost" -NotAfter (Get-Date).AddYears(10)
然后,我在受信任的根证书颁发机构下复制了该证书。我通过MMC文件将其导出到.cer中,并通过命令将其导入到JRE中

& 'C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\bin\keytool.exe' -importcert -file D:\temp\certificate\localhost.cer -keystore 'C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\jre\lib\security\cacerts' -alias "localhost"
返回的

Certificate was added to keystore
localhost, Oct 28, 2020, trustedCertEntry,
我已经重新启动了我的应用服务器,并尝试再次执行该自我HTTP请求,但仍然得到了SSLException

我已经检查了证书是否真的导入了JRE,它是:

& 'C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\bin\keytool.exe' -keystore 'C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\jre\lib\security\cacerts' -list | Select-String "localhost"
返回的

Certificate was added to keystore
localhost, Oct 28, 2020, trustedCertEntry,
我无法添加自定义的
javax.net.ssl.HostnameVerifier
实现以跳过
localhost
验证。是否缺少一些配置


我的本地环境在Windows 10上。我的web服务器是Apache。

只是向信任存储添加一个随机证书没有帮助。它必须与apache使用的证书相同。除非这只是为了发展,否则是行不通的。web服务器首先不应该向自身发送请求。