Java - How can I disable a TLS cipher for only some protocols using JVM Config?

前端 未结 3 1640
眼角桃花
眼角桃花 2021-02-07 03:16

I\'ve seen lots of examples of disabling TLS ciphers in java using jdk.tls.disabledAlgorithms, for example:

 jdk.tls.disabledAlgorithms=MD2, RSA keySize < 102         


        
3条回答
  •  日久生厌
    2021-02-07 03:52

    JSSE docs say that the https.protocols property can store comma separated list of supported protocols in a given SSL context, however this property is used by current JSSE implementation, but could be disregarded by other vendors or future versions, so YMMV.

    Programatically you can achieve it like so:

    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    socket.setEnabledCipherSuites(new String[] {
        CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
        CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName,
    });
    
    //allow TLS1.2 only
    socket.setEnabledProtocols(new String[] {
        TlsVersion.TLS_1_2.javaName,
    });
    

提交回复
热议问题