title: SSL Communication between Android Marshmallow and Java server
body: <p>I have an Android client and a Java Server that communicate with a SSL socket. The communication works well with an Android version &lt; 6.0. With Android 6.0 I have this exception:</p>
  
  <pre><code>javax.net.ssl.SSLHandshakeException: no cipher suites in common
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
  at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
  at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
  at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:292)
  at sun.security.ssl.ServerHandshaker.chooseCipherSuite(ServerHandshaker.java:1036)
  at sun.security.ssl.ServerHandshaker.clientHello(ServerHandshaker.java:739)
  at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:221)
  at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
  at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
  at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)
  at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
  at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
  at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
  at java.io.ObjectOutputStream.&lt;init&gt;(ObjectOutputStream.java:247)
  </code></pre>
  
  <p>This is my server code:</p>
  
  <pre><code>ServerSocket server = null;
  Socket socket=null;
  SSLContext ctx;
  KeyManagerFactory kmf;
  KeyStore ks;
  try{
       char[] passphrase = "password".toCharArray();
       String keyfile = "keyName";
       ctx = SSLContext.getInstance("TLS");
       kmf = KeyManagerFactory.getInstance("SunX509");
       ks = KeyStore.getInstance("JKS");
       ks.load(new FileInputStream(keyfile), passphrase);
       kmf.init(ks, passphrase);
       ctx.init(kmf.getKeyManagers(), null, null);
       ServerSocketFactory ssf = ctx.getServerSocketFactory();
       server = ssf.createServerSocket(port);
  }catch (IOException e){
       e.printStackTrace();
  }               
  while (true) {              
       socket = server.accept();
       new Thread(new WorkerThread(socket));                
  }
  </code></pre>
  
  <p>This is my Android code:</p>
  
  <pre><code>        Socket clientSocket = null;
          KeyStore store = KeyStore.getInstance("BKS");
          InputStream in2 = ctx.getResources().openRawResource(
                  R.raw.server);
          store.load(in2, "password".toCharArray());
  
          TrustManagerFactory tmf = TrustManagerFactory
                  .getInstance(KeyManagerFactory.getDefaultAlgorithm());
          tmf.init(store);
          SSLContext sslcontext = SSLContext.getInstance("SSL");
          sslcontext.init(null, tmf.getTrustManagers(),
                  new SecureRandom());
          SSLSocketFactory sslsocketfactory = sslcontext
                  .getSocketFactory();
          clientSocket = (SSLSocket) sslsocketfactory.createSocket(
                  Constants.SERVER_HOST, port);
          ObjectInputStream obi = new ObjectInputStream(
                  clientSocket.getInputStream());
          ObjectOutputStream obs = new ObjectOutputStream(
                  clientSocket.getOutputStream());
  
          obs.writeObject("text");
          obs.flush();
  </code></pre>
  
  <p>I have also tried to set the cipher suite but without result.</p>