基于HTTPS/SSL的Java客户端证书我正在使用Java 6,并试图创建一个HttpsURLConnection针对远程服务器,使用客户端证书。服务器正在使用自签名根证书,并要求提供受密码保护的客户端证书。我已经将服务器根证书和客户端证书添加到默认的java密钥存储库中,我在/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/security/cacerts(OSX 10.5)。keystore文件的名称似乎表明客户端证书不应该放在那里?无论如何,将根证书添加到这个商店解决了臭名昭著的问题。javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed' problem.但是,我现在仍在研究如何使用客户端证书。我试过两种方法,但都没办法。首先,并优先尝试:SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();URL url = new URL("
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();conn.setSSLSocketFactory(sslsocketfactory);
InputStream inputstream = conn.getInputStream();// The last line fails, and gives:
// javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure我尝试过跳过HttpsURLConnection类(因为我想与服务器对话HTTP,所以不太理想),然后这样做:SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("somehost.dk", 3049);
InputStream inputstream = sslsocket.getInputStream();
// do anything with the inputstream results in:
// java.net.SocketTimeoutException: Read timed out我甚至不确定客户端证书是否是这里的问题。
添加回答
举报
0/150
提交
取消