title: Getting javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure Error
body: <p>I am trying to send push notification to iPhone using Java-pns but I am getting the following error - 
  <strong>javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure</strong></p>
  
  <p>My code is - </p>
  
  <pre><code>String token="95076d2846e8979b46efd1884206a590d99d0f3f6139d947635ac4186cdc5942";
  String host = "gateway.sandbox.push.apple.com";
  int port = 2195;
  String payload = "{\"aps\":{\"alert\":\"Message from Java o_O\"}}";
  
  NotificationTest.verifyKeystore("res/myFile.p12", "password", false);
  KeyStore keyStore = KeyStore.getInstance("PKCS12");
  keyStore.load(getClass().getResourceAsStream("res/myFile.p12"), "password".toCharArray());
  
  KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance("SunX509");
  keyMgrFactory.init(keyStore, "password".toCharArray());
  
  SSLContext sslContext = SSLContext.getInstance("TLS");
  sslContext.init(keyMgrFactory.getKeyManagers(), null, null);
  SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
  
  SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(host, port);
  String[] cipherSuites = sslSocket.getSupportedCipherSuites();
  sslSocket.setEnabledCipherSuites(cipherSuites);
  sslSocket.startHandshake();
  
  char[] t = token.toCharArray();
  byte[] b = Hex.decodeHex(t);
  
  OutputStream outputstream = sslSocket.getOutputStream();
  
  outputstream.write(0);
  outputstream.write(0);
  outputstream.write(32);
  outputstream.write(b);
  outputstream.write(0);
  outputstream.write(payload.length());
  outputstream.write(payload.getBytes());
  
  outputstream.flush();
  outputstream.close();
  
  System.out.println("Message sent .... ");
  </code></pre>
  
  <p>For <strong>NotificationTest.verifyKeystore</strong>  I am getting that this valid is File and Keystore.</p>
  
  <p>I am not understanding why I am getting this error.</p>
  
  <p>Please anybody can help me?</p>
  
  <p>Thanks in Advance ...</p>
  
  <p>In my log I have seen that</p>
  
  <p>** CertificateRequest</p>
  
  <p>Cert Types: RSA, DSS, ECDSA</p>
  
  <p>Cert Authorities:</p>
  
  <p>[read] MD5 and SHA1 hashes:  len = 10</p>
  
  <p>0000: 0D 00 00 06 03 01 02 40   00 00                    .......@..</p>
  
  <p>** ServerHelloDone</p>
  
  <p>[read] MD5 and SHA1 hashes:  len = 4</p>
  
  <p>0000: 0E 00 00 00                                        ....</p>
  
  <p>** Certificate chain</p>
  
  <p>**</p>
  
  <p>** ClientKeyExchange, RSA PreMasterSecret, TLSv1</p>
  
  <p>[write] MD5 and SHA1 hashes:  len = 269</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>main, READ: TLSv1 Alert, length = 2</p>
  
  <p>main, RECV TLSv1 ALERT:  fatal, handshake_failure</p>
  
  <p>main, called closeSocket()</p>
  
  <p>main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: 
  handshake_failure</p>
  
  <p>I am not understanding why <strong>Cert Authorities:</strong> is empty?</p>