Search code examples
javasslcryptographybouncycastle

How can I edit the list of cipher suite in Java using Bouncy Castle


The following code lists the supported cipher suites by Java SE 8:

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Arrays;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
public class ListCiphers {

    public static void main(String[] args) throws UnknownHostException, IOException
    {
        SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory(); 
        String[] cipherSuites = factory.getSupportedCipherSuites();
        System.out.println(Arrays.toString(cipherSuites));

    } //end main
}

I want to make SSL client which is configured with some specific list of cipher suites. The cipher suites I want to use are standardized but not supported by Jva SE 8. For example, this cipher is listed in firefox:

ECDHE_ECDSA_WITH_AES_256_SHA

Please, help me with any way that allows me to edit the list of cipher suite in my SSL client. Does Bouncy Castle help in this? How? Please, give me clear step by step. Also if you knwo what I want can be achieved by using another language such as python, also please help me.


Solution

  • How can I edit the list of cipher suite in Java using Bouncy Castle

    See Which Cipher Suites to enable for SSL Socket? and use SSLSocketFactoryEx. Its a drop-in replacement for Java's SSLSocketFactory

    If you don't want to use SSLSocketFactoryEx, then rip the code to find the intersection of cipher suites.

    It controls both protocols and cipher suites. There are no unexpected surprises, like getting a SSLv3 socket back from SSLSocketFactory.getInstance("TLS");.

    Nothing is configurable, so the user cannot shoot themselves in the foot. It's also ready for TLS 1.3