title: SSL Sockets - Java and Certificates?
body: <p>I am trying to implement a SSL socket between an Android App and a Python API.</p>
  
  <p>The code below...</p>
  
  <pre><code>SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
  Socket s = ssf.createSocket("10.0.2.2", 5001);
  DataOutputStream myDataOut = new DataOutputStream(s.getOutputStream());
  myDataOut.writeUTF("Hello Server");
  myDataOut.flush();
  myDataOut.close();
  s.close();
  </code></pre>
  
  <p>doesn't work as you can see:</p>
  
  <pre><code>590.0750 - Establishing connection to ('127.0.0.1', 50888)
  590.0970 - Error while connecting
  590.0970 - Error information: [SSL: SSLV3_ALERT_CERTIFICATE_UNKNOWN] sslv3 alert certificate unknown (_ssl.c:590)
  </code></pre>
  
  <p>I believe it doesn't because I am not specifying the certificate.
  See a Python working example of client:</p>
  
  <pre><code>import socket, ssl, pprint
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  ssl_sock = ssl.wrap_socket(s,
                             ca_certs="server.crt",
                             cert_reqs=ssl.CERT_REQUIRED)
  
  ssl_sock.connect(('localhost', 5001))
  
  print repr(ssl_sock.getpeername())
  print ssl_sock.cipher()
  print pprint.pformat(ssl_sock.getpeercert())
  
  ssl_sock.write("Hello from the client...")
  </code></pre>
  
  <p>How can I specify the certificate in Java like I did in Python?</p>