gpt4 book ai didi

JAVA 6 不支持 SNI,还有其他方法可以通过 TLS 验证和接受 SSL 证书吗?

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:47 25 4
gpt4 key购买 nike

我知道浏览器和 java7 不受影响的原因是因为它们将 Server Name Indication-SNI 作为 SSL 信息的一部分发送。因此,apache 在开始 SSL 握手并返回正确的证书之前知道要使用哪个虚拟主机。 Java 6 不支持 SNI。所以我的问题是,如何验证并允许证书在 Java 6 中被接受。

我做了一个 spring 客户端来使用 webservice,这是我的代码

public class classname1 {

static {
System.setProperty("javax.net.ssl.trustStore", "E://Workspace//keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("https.protocols", "SSLv3");
System.setProperty("https.protocols", "TLSv1");

}
static {

HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
{
public boolean verify(String hostname, SSLSession session)
{
if (hostname.equals("192.168.10.22"))
return true;
return false;
}
});
}

private static void main(String[] args) {
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

String url = "https://192.168.10.22/getInformationSearch.asmx?wsdl";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
printSOAPResponse(soapResponse);
soapConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}

private static SOAPMessage createSOAPRequest() throws Exception {
// ... Code for request, which will be hitted to url
}

private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
// ... Code for response, which will fetch information from webservice
// URL
}

}

如您所见,我创建了两个方法,1. 用于请求 createSOAPRequest() 2. 用于响应 printSOAPResponse()。 (在上面的代码段中更改了网址名称)

main() 方法中,下面一行将生成请求并将该请求发送到给定的 url SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); 之后它进入静态 block ,如上所示 HttpsURLConnection.setDefaultHostnameVerifier() 方法。

当时,调试器说:ssl 握手失败,SSL 对等端错误关闭。它只发生在 JAVA 6 中,但这些代码可以在 Java 7/8 中正常工作。

我在 java 6 中尝试了以下代码,而不是那个静态 block

 HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName,
SSLSession session) {
return true;
}
};

但无论如何都行不通!!!

我正在使用以下 jars xercesImpl.jar、saaj-api.jar、saaj-impl.jar、spring-ws-core-1.5.6.jar、spring-ws-security-1.5.6.jar 和证书这个 SSL 域已经导入到 keystore 中并且它在 java7/8 中工作,所以信任库中没有问题,对吗? (我也使用 java 6 和 7 的 keytool 制作了 2 个证书,两者在 java7/8 中都可以正常工作,但在 6 中不行)

我关注了这个thread但它不会工作。那么有没有其他方法可以在 Java 6 环境中验证证书并获得响应,或者我应该更改任何 JAR 吗?

最佳答案

如果服务器未配置为允许您在没有 SNI 的情况下进行连接,则您不能。

如果没有 SNI,在建立 SSL 连接之后之前,服务器无法判断您想要哪个虚拟主机。

要查看区别,如果您有 OpenSSL,则可以使用 the s_client option提取所提供的不同证书,或者当您不使用 SNI 时可能会注意到连接失败:

国家安全局:

echo | openssl s_client -servername www.virtualhost.com -connect 192.168.1.55:443 | openssl x509 -text

192.168.1.55 替换为服务器的实际 IP 地址,并将 www.virtualhost.com 替换为您要连接的虚拟主机的主机名。管道前面的 echo 命令可防止 openssl 在等待输入时挂起。

没有 SNI:

echo | openssl s_client -connect 192.168.1.55:443 | openssl x509 -text

如果没有 SNI,您可能会看到一个完全不同的证书,或者您可能会遇到连接错误。

关于JAVA 6 不支持 SNI,还有其他方法可以通过 TLS 验证和接受 SSL 证书吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39932652/

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