如何在IBM Java 1.6中启用TLS 1.2?

时间:2018-10-14 07:41:39

标签: java websphere tls1.2 sslhandshakeexception

我需要在IBM Java 1.6 [SR16 FP60]中启用TLS 1.2连接。我尝试通过建立连接

 public static void TLS() throws NoSuchAlgorithmException, KeyManagementException, IOException{

    System.setProperty("https.protocols", "TLSv1.2");

URL url = new URL("https://jsonplaceholder.typicode.com/posts");



    String XML = "<Test></test>"
     SSLContext ssl = SSLContext.getInstance("TLSv1.2"); 

    // ctx.init(null, null, null);

     ssl.init(null, null, null);
     SSLContext.setDefault(ssl);

     HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();


     connection.setSSLSocketFactory(ssl.getSocketFactory());
     connection.setRequestMethod("POST");
     connection.setRequestProperty("Content-Type", "application/xml");
     connection.setDoOutput(true);
        OutputStream os = connection.getOutputStream();
        os.write(XML.getBytes());
        os.flush();
        os.close();
    System.out.println(">>>Connection certificate"+connection.getServerCertificates());
    System.out.println(">>>Connection"+connection.getContent());
    int responseCode = connection.getResponseCode();


    System.out.println("POST Response Code :  " + responseCode);
    System.out.println("POST Response Message : " + connection.getResponseMessage());
    if (responseCode == HttpsURLConnection.HTTP_OK) { //success
        BufferedReader in = new BufferedReader(new InputStreamReader(
            connection.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in .readLine()) != null) {
            response.append(inputLine);
        } in .close();

        System.out.println(response.toString());}

 }

建立连接时会引发错误

  

收到致命警报:握手失败

请告知我们解决此问题的方法。

1 个答案:

答案 0 :(得分:2)

我猜您正在使用WebSphere 6?您必须升级到7.0.0.23、8.0.0.3或8.5。

请参见https://developer.ibm.com/answers/questions/206952/how-do-i-configure-websphere-application-server-ss.html

相关问题