Received fatal alert: handshake_failure through SSLHandshakeException

前端 未结 19 2421
暖寄归人
暖寄归人 2020-11-22 01:33

I have a problem with authorized SSL connection. I have created Struts Action that connects to external server with Client Authorized SSL certificate. In my Action I am tryi

19条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 02:21

    I meet the same problem today with OkHttp client to GET a https based url. It was caused by Https protocol version and Cipher method mismatch between server side and client side.

    1) check your website https Protocol version and Cipher method.

    openssl>s_client -connect your_website.com:443 -showcerts

    You will get many detail info, the key info is listed as follows:

    SSL-Session:
        Protocol  : TLSv1
        Cipher    : RC4-SHA
    
    2) config your http client, for example, in OkHttp client case:
    @Test()
    public void testHttpsByOkHttp() {
        ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
                .tlsVersions(TlsVersion.TLS_1_0) //protocol version
                .cipherSuites(
                        CipherSuite.TLS_RSA_WITH_RC4_128_SHA, //cipher method
                        CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                        CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
                        CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
                .build();
    
        OkHttpClient client = new OkHttpClient();
        client.setConnectionSpecs(Collections.singletonList(spec));
        Request request = new Request.Builder().url("https://your_website.com/").build();
        try {
            Response response = client.newCall(request).execute();
            if(response.isSuccessful()){
                logger.debug("result= {}", response.body().string());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    This will get what we want.

提交回复
热议问题