我需要将 SNI 设置为我的 socketFactory。所以我一直在使用这个类SSLCertificateSocketFactory
。在创建套接字时,它给了我一个sslpeerunverifiedexception
服务器证书,因为没有 SAN 集。我可以如何抑制这个异常,并要求它允许创建套接字而不考虑服务器证书?
以下是我的代码:
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLCertificateSocketFactory ssf = (SSLCertificateSocketFactory) SSLCertificateSocketFactory
.getDefault(0);
ssf.setTrustManagers(new TrustManager[] { tm });
m_sslsocket = (SSLSocket) ssf.createSocket(m_socket, m_host, m_port, false);