我正在尝试使用SSLCertificateSocketFactory.setHostname添加SNI支持,通过wireshark我看到客户端和启用SNI的服务器之间的通信,CLIENT HELLO进入服务器(设置了正确的主机名),Server响应Server Hello并将证书发送给客户端但是在那之后客户端没有发送证书和通信/握手停止,通过openssl命令openssl s_client -connect theclient -servername thehostname -cert thecertificate一切顺利,握手成功发生..
我正在使用套接字和socket.startHandshake我得到异常:IOException:javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚.
final SSLCertificateSocketFactory sslSocketFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0);
socket = (SSLSocket) sslSocketFactory.createSocket(InetAddress.getByName("theserver"), 443);
socket.setEnabledProtocols(socket.getSupportedProtocols());
String[] cipherArray = socket.getEnabledCipherSuites();
for(int i = 0; i<cipherArray.length; i++) {
Log.e("","Available Cipher:"+cipherArray[i]);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
sslSocketFactory.setHostname(socket, "thehostname");
} else {
try {
java.lang.reflect.Method setHostnameMethod = socket.getClass().getMethod("setHostname", String.class);
setHostnameMethod.invoke(socket, "thehostname");
} catch (Exception e) {
Log.w("", "SNI not useable", e);
}
}
socket.setSoTimeout(20000);
socket.setUseClientMode(true);
Log.i(getClass().toString(), "Connected.");
socket.startHandshake();
SSLSession session = socket.getSession();
boolean secured = …Run Code Online (Sandbox Code Playgroud)