title: notnoop APNS 0.2.3 failing to send message
body: <p>I am using notnoop APNS 0.2.3, was struggling with the certs, and now I am struggling with SSL.</p>
  
  <p>There is no documentation on how to prepare a p12 file for the library, so I found <a href="http://faq.appaloosa-store.com/knowledgebase/articles/61785-how-to-generate-apple-push-notification-p12-file-" rel="nofollow">this article</a> to guide me.</p>
  
  <pre><code>service = APNS.newService() 
              .withCert(mycertPath, myP12password)
              .withSandboxDestination()
              .build();        
  service.start();
  service.testConnection();
  service.push(listOfTokens,payload);
  </code></pre>
  
  <p>The start method fails with the following dump</p>
  
  <pre><code>09:46:16,657 INFO  ~ Failed to send message Message(Token=00; Payload=)... trying again after delay
  javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
  at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
  at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1822)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1004)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:654)
  at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:100)
  at java.io.OutputStream.write(OutputStream.java:58)
  at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:240)
  at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:230)
  at com.notnoop.apns.internal.ApnsConnectionImpl.testConnection(ApnsConnectionImpl.java:294)
  at com.notnoop.apns.internal.ApnsServiceImpl.testConnection(ApnsServiceImpl.java:57)
  </code></pre>
  
  <p>Did I screw up the p12 file? Is there something else I am missing here?</p>
  
  <p>[UPDATE 1]
  I am trying the following script to create and test the p12 file command line, and am also getting a connection error, so there is something I likely messed up in the certificates.</p>
  
  <p>[UPDATE 2]
  I altered the script to create p12 files... incase others can benefit from this.</p>
  
  <pre><code>#!/bin/sh
  bold=`tput bold`
  normal=`tput sgr0`
  
  # CONVERT CERT TO PEM
  echo "${bold}CONVERTING${normal} APNS..."
  openssl x509 -in aps_development.cer -inform der -out aps_development.pem
  openssl x509 -in aps_production.cer -inform der -out aps_production.pem
  
  # CONVERT PRIVATE KEY P12 INTO PEM
  echo "${bold}CONVERTING ${normal} private key..."
  openssl pkcs12 -nocerts -out my_private.pem -in my_private.p12
  
  # COMBINE CERTS INTO SINGLE P12
  echo "${bold}COMBINING ${normal} development..."
  #cat aps_development.pem my_private.pem &gt; my_development.pem
  openssl pkcs12 -export -in aps_development.pem -inkey my_private.pem -out my_development.p12
  
  # COMBINE CERTS INTO SINGLE P12
  echo "${bold}COMBINING ${normal} production..."
  #cat aps_production.pem my_private.pem &gt; my_production.pem
  openssl pkcs12 -export -in aps_production.pem -inkey my_private.pem -out my_production.p12
  
  echo "${bold}TESTING${normal}..."
  
  # TEST IT
  openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert aps_development.pem -key my_private.pem
  </code></pre>