gpt4 book ai didi

java - 使用 jdk 1.6 时出现 SSLHandshake 异常

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:35 28 4
gpt4 key购买 nike

我正在尝试使用 HTTPClient/URLConnection 连接到 REST 网络服务。这是一段在 jdk 1.7 中运行良好但在使用 jdk1.6 时抛出 SSLHandshake 异常的简单代码

    IO Exception:  javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching your.domain.name.com found.
...

Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching your.domain.name.com found.

此外,代码非常基础

URL url = new URL("https://your.domain.name.com/services/");
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + encodedCredenials);
urlConnection.setRequestProperty("Content-Type", "application/vnd.mtdomain.gold+json");
InputStream is = urlConnection.getInputStream();

这是 jdk 1.6 和 1.7 之间的已知问题吗?我们怎样才能解决这个问题?我不太了解 SSL 相关问题。

最佳答案

此问题可能由于以下原因(错误的 URL、损坏的证书或无效的证书)而发生。

要安装证书,请使用以下语法。

默认 keystore 将证书安装到默认 keystore (JDK cacerts)1.从服务器导出证书(.cer)2. 打开命令提示符并转到 JAVA_HOME/jre/lib/security3.执行以下命令

window

keytool -import -v -alias -keystore cacerts -file \.cer

Password: changeit

Unix

/bin/keytool -import -v -alias -keystore cacerts -file \.cer

Password: changeit

  1. 选择"is"选项并按回车键

自定义 keystore 将证书安装到自定义 keystore 1.从服务器导出证书(.cer)2. 打开命令提示符并转到要创建自定义 keystore 的位置3.执行以下命令 window keytool -import -v -trustcacerts -alias -file\.cer -keystore .jks -keypass changeit密码:changeit

Unix/bin/keytool -import -v -trustcacerts -alias -file\.cer -keystore .jks -keypass changeit密码:changeit

  1. 选择"is"选项并按回车键

在调用自定义 keystore 时添加以下系统变量

-Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=CustomTrust -
Dweblogic.security.CustomTrustKeyStoreFileName=<location>/<keystore-name>.jks -Djavax.net.ssl.trustStore=<location>/<keystore-name>.jks -Djavax.net.ssl.trustStorePassword=changeit

关于java - 使用 jdk 1.6 时出现 SSLHandshake 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28560406/

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