Received fatal alert: handshake_failure through SSLHandshakeException

前端 未结 19 2179
暖寄归人
暖寄归人 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:09

    In my case, the website just can use TLSv1.2. and i use apache httpclient 4.5.6, i use this code and install jce to solve this (JDK1.7):

    jce

    jdk7 http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

    jdk 8 http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

    code:

    SSLContext sslContext = SSLContext.getDefault();
    
      SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(
          sslContext,
          new String[]{"TLSv1.2"}, // important
          null,
          NoopHostnameVerifier.INSTANCE);
    
      Registry registry = RegistryBuilder.create()
          .register("https", sslConnectionFactory)
          .register("http", PlainConnectionSocketFactory.INSTANCE)
          .build();
    
      HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
      httpclient = HttpClientBuilder.create().
          .setSSLSocketFactory(sslConnectionFactory)
          .setConnectionManager(ccm)
          .build();
    

提交回复
热议问题