title: How to use ChaCha cipher in SSL ciphersuite using java
body: <p>I was trying to find way to edit the supported cipher suite in a Java SSL client so I can offer a specific list of cipher suites. </p>
  
  <p>One suggested solution was to use the <strong><em>SSLSocketFactoryEx</em></strong> class that was posted by @jww in this link: <a href="https://stackoverflow.com/questions/1037590/which-cipher-suites-to-enable-for-ssl-socket/23365536#23365536">Which Cipher Suites to enable for SSL Socket?</a></p>
  
  <p>I did added the <strong><em>SSLSocketFactoryEx</em></strong> class and run the code that lists the supported ciphers by this class (NOTE: I used GetCipherList(); instead of the getSupportedCipheSuites(); because the first is what I found in the <strong><em>SSLSocketFactoryEx</em></strong>) . The code is:</p>
  
  <pre><code>import java.io.IOException;
  import java.net.UnknownHostException;
  import java.security.KeyManagementException;
  import java.security.NoSuchAlgorithmException;
  import java.security.Security;
  import java.util.Arrays;
  
  import org.bouncycastle.jce.provider.BouncyCastleProvider;
  
  public class ListCiphers {
  
      public static void main(String[] args) throws UnknownHostException, IOException, KeyManagementException, NoSuchAlgorithmException
      {   
          Security.addProvider(new BouncyCastleProvider());
  
          //BC is the ID for the Bouncy Castle provider;
          if (Security.getProvider("BC") == null){
              System.out.println("Bouncy Castle provider is NOT available");
          }
          else{
              System.out.println("Bouncy Castle provider is available");
          }
  
          SSLSocketFactoryEx factory = new SSLSocketFactoryEx();
          String[] cipherSuites = factory.GetCipherList();
          System.out.println(Arrays.toString(cipherSuites));
  
      } //end main
  }
  </code></pre>
  
  <p>My code is supported by Bouncy Castle (BC) provider which says that it supports <strong><em>ChaCha</em></strong> cipher in the specification. See: <a href="https://www.bouncycastle.org/specifications.html" rel="nofollow noreferrer">https://www.bouncycastle.org/specifications.html</a></p>
  
  <p>the result of the code (the supported ciphers) are:</p>
  
  <pre><code>TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
  TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
  TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
  TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
  TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  TLS_DHE_DSS_WITH_AES_256_GCM_SHA384
  TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  TLS_DHE_DSS_WITH_AES_128_GCM_SHA256
  TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
  TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  TLS_DHE_DSS_WITH_AES_128_CBC_SHA
  TLS_RSA_WITH_AES_256_CBC_SHA256
  TLS_RSA_WITH_AES_256_CBC_SHA
  TLS_RSA_WITH_AES_128_CBC_SHA256
  TLS_RSA_WITH_AES_128_CBC_SHA
  TLS_EMPTY_RENEGOTIATION_INFO_SCSV
  </code></pre>
  
  <p>Why I can not see the ciphers with ChaCha cipher??</p>
  
  <p>If you look at the <strong><em>SSLSocketFactoryEx</em></strong> code, it includes several cipher suites with ChaCha.</p>
  
  <p>Why I can not get them in the supported cipher suites list after using BC provider? How can I add the following cipher suites in the supported cipher suites list so I can include them in the client hello message??</p>
  
  <pre><code>ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
  ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
  DHE_RSA_WITH_CHACHA20_POLY1305_SHA256
  </code></pre>
  
  <p>Please, help.</p>