gpt4 book ai didi

带有自签名证书的 Java SSLHandshakeException

转载 作者:太空宇宙 更新时间:2023-11-03 14:08:07 31 4
gpt4 key购买 nike

我正在尝试使用自签名证书访问本地 https 站点。我修改了主机文件并为我的本地站点分配了一个 IP 地址;我用来访问网站的代码:

 String httpsURL = "https://test-ssl.com";
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
InputStream ins = con.getInputStream();
InputStreamReader isr = new InputStreamReader(ins);
BufferedReader in = new BufferedReader(isr);

String inputLine;

while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
}

in.close();
}

我收到此错误消息:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1904)

我已使用以下命令将自签名证书导入 keystore :

keytool -import -alias site-ssl -keystore cacerts -file site-ssl.com.cer

证书导入成功

我在这里错过了什么?

最佳答案

您应该尝试使用主机名而不是 URL 中的 IP 地址。它正在尝试进行主机名验证,但证书不包含 192.168.1.6 的主题备用名称。

关于带有自签名证书的 Java SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36929826/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com