SSL握手错误:来自服务器

时间:2016-02-25 21:56:33

标签: ssl sslhandshakeexception sslexception

我正在尝试使用SSL证书调用API。从-Djavax.net.debug =所有日志我通过以下步骤。

  1. 收到"服务器Hello完成"
  2. 客户密钥交换:RSA PreMasterSecret,TLSv1
  3. 在客户密钥交换中收到完成状态
  4. 更改密码规范:失败

    RECV TLSv1 ALERT:  
    fatal, 
    handshake_failure
    %% Invalidated:  [Session-1, SSL_RSA_WITH_RC4_128_MD5]
    
  5. 我使用的是JDK1.7,带有JCE Unlimited Strength Policy文件。谢谢你的帮助。

    编辑:服务器Hello完成和客户端密钥交换之间

    *** ServerHelloDone
    [read] MD5 and SHA1 hashes:  len = 4
    0000: 0E 00 00 00                                        ....
    *** Certificate chain
    *** ClientKeyExchange, RSA PreMasterSecret, TLSv1
    

    设置SSL套接字工厂的代码:

    System.setProperty('javax.net.ssl.keyStore', 'jksfile')
    System.setProperty('javax.net.ssl.keyStorePassword', '')
    System.setProperty("https.protocols", "TLSv1");
    
    System.setProperty('javax.net.ssl.trustStore', 'C:/Program Files/Java/jdk1.7.0_79/jre/lib/security/cacerts')
    System.setProperty('javax.net.ssl.trustStorePassword', '')
    
    SSLContext sslcontext = SSLContext.getInstance("TLSv1");
            sslcontext.init(null, null, null);
    
        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    
    
        if (conn instanceof HttpsURLConnection){
            conn.setSSLSocketFactory(sslcontext.getSocketFactory());
        } 
    

0 个答案:

没有答案