mwkirk / javapns

Test import of svn javapns repo from Google Code
3 stars 0 forks source link

Having problems initiating the SSL connection to the APNS #126

Closed mwkirk closed 11 years ago

mwkirk commented 11 years ago

Original author: ch...@kipsu.com (June 09, 2012 23:07:08)

What steps will reproduce the problem?

I am getting the error attached below that there is a HANDSHAKE_FAILURE. I assume that this is a problem setting up the SSL connection with Apple's server?

Here is the code that I am using: import javapns.; import javapns.notification.; import javapns.communication.exceptions.CommunicationException; import javapns.communication.exceptions.KeystoreException;

try {

List<PushedNotification> notifications = Push.alert("Hello World!", "/usr/bin/push/etc/cert.p12", "password/1", false, "5501c288b64b28eadc87a2b83659863d85b0030abd572b470ffeb4dcdaf0001a");

for (PushedNotification notification : notifications) {
    if (notification.isSuccessful()) {

        /* Apple accepted the notification and should deliver it */
        if (log.isLoggable(Level.FINEST)) {
            log.log(Level.FINEST,
                "Push notification sent successfully to: " +
                notification.getDevice().getToken());
        }
        /* Still need to query the Feedback Service regularly */  
    } else {
        String invalidToken = notification.getDevice().getToken();
        /* Add code here to remove invalidToken from your database */  

        /* Find out more about what the problem was */  
        Exception theProblem = notification.getException();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        theProblem.printStackTrace(pw);
        if (log.isLoggable(Level.FINEST)) {
            log.log(Level.FINEST, sw.toString().toUpperCase());
        }

        /* If the problem was an error-response packet returned by Apple, get it */  
        ResponsePacket theErrorResponse = notification.getResponse();
        if (theErrorResponse != null) {
            if (log.isLoggable(Level.FINEST)) {
                log.log(Level.FINEST,
                theErrorResponse.getMessage());
            }
        }
    }
}

} catch (KeystoreException e) { /* A critical problem occurred while trying to use your keystore */
e.printStackTrace();

} catch (CommunicationException e) { /* A critical communication error occurred while trying to contact Apple servers */
e.printStackTrace(); }

I noticed that there was a prior issue that was posted that was similar (http://code.google.com/p/javapns/issues/detail?id=67) but I tried reinstalling the keys and have had no success. How can I debug the problem more specifically. Is there a way to manually try the SSL connection with the cert?

What is the expected output? What do you see instead?

2012-06-05 19:10:14 PushNotificationPlugin.process() FINEST: 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:1806) AT COM.SUN.NET.SSL.INTERNAL.SSL.SSLSOCKETIMPL.READRECORD(SSLSOCKETIMPL.JAVA:986) AT COM.SUN.NET.SSL.INTERNAL.SSL.SSLSOCKETIMPL.PERFORMINITIALHANDSHAKE(SSLSOCKETIMPL.JAVA:1170) AT COM.SUN.NET.SSL.INTERNAL.SSL.SSLSOCKETIMPL.WRITERECORD(SSLSOCKETIMPL.JAVA:637) AT COM.SUN.NET.SSL.INTERNAL.SSL.APPOUTPUTSTREAM.WRITE(APPOUTPUTSTREAM.JAVA:89) AT JAVA.IO.OUTPUTSTREAM.WRITE(OUTPUTSTREAM.JAVA:58) AT JAVAPNS.NOTIFICATION.PUSHNOTIFICATIONMANAGER.SENDNOTIFICATION(PUSHNOTIFICATIONMANAGER.JAVA:402) AT JAVAPNS.NOTIFICATION.PUSHNOTIFICATIONMANAGER.SENDNOTIFICATION(PUSHNOTIFICATIONMANAGER.JAVA:350) AT JAVAPNS.NOTIFICATION.PUSHNOTIFICATIONMANAGER.SENDNOTIFICATION(PUSHNOTIFICATIONMANAGER.JAVA:320) AT JAVAPNS.PUSH.SENDPAYLOAD(PUSH.JAVA:177) AT JAVAPNS.PUSH.ALERT(PUSH.JAVA:47) AT TIGASE.XMPP.IMPL.PUSHNOTIFICATIONPLUGIN.PROCESS(PUSHNOTIFICATIONPLUGIN.JAVA:130) AT TIGASE.SERVER.XMPPSESSION.SESSIONMANAGER$PROCESSORWORKERTHREAD.PROCESS(SESSIONMANAGER.JAVA:2135) AT TIGASE.UTIL.WORKERTHREAD.RUN(WORKERTHREAD.JAVA:132)

What version of the product are you using? On what operating system? JavaPNS 2.2, Mac OS X 10.7.4

Original issue: http://code.google.com/p/javapns/issues/detail?id=126

mwkirk commented 11 years ago

From isenages...@gmail.com on June 28, 2012 05:46:06 We are also facing the same problem - javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure.

Any solution will be helpful.

Thank You.

mwkirk commented 11 years ago

From sype...@gmail.com on July 02, 2012 21:16:39 That exception is typical of an invalid keystore or certificates. If you are absolutely sure that you did ALL steps required for producing your keystore, WITHOUT cutting corners or assuming something that was not written, please provide the precise list of steps you followed so that more investigation can be done. Thank you.

mwkirk commented 11 years ago

From jdsamuel...@gmail.com on July 03, 2012 14:41:34 We had an issue with the certificate. We're still a little unsure of what the issue was, but after switching to another certificate that appears to be the same everything works. Also, make sure to check the permissions on the certificate. We had issues with the permissions not transferring correctly in addition to what permissions java pns is being running with.

mwkirk commented 11 years ago

From darshwit...@gmail.com on July 17, 2012 09:07:20 Hi All,

I am facing the same issue, and i have followed following steps to produce my certificate and key,

http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

Now the thing is that, in above link they provided a PHP sample which works perfectly and i can get the Notification on my Device, but when i try to implement it through JavaPNs (the simple one) it throws above mentioned error.

One more thing, when i call - verifyKeystore(".p12", "", true); - it throws, "javapns.communication.exceptions.KeystoreException: Keystore does not contain any valid certificate" Which is quite surprising as the same certificate works perfectly with PHP sample.

I am using JavaPNs 2.2, in Win 7 machine with JDK jdk1.6.0_05.

Can anyone please help me or guide me what to do in this case? I am struggling with this from last 3 days. Also do i have to Import the certificates with "keytool"? (Its not specified anywhere in JavaPNS).

mwkirk commented 11 years ago

From darshwit...@gmail.com on July 17, 2012 13:32:53 Sorry to All,

I found the problem. Its my certificate. Actually from Keychain Access in Apple, there are 2 certificates installed with the same url, and because that the confusion occurred. I have remove the one not used anymore and created a .p12 from the one which the application is using, and Bingo it starts working. :-).

Thanks for this wonderful Library and Tutorials...

mwkirk commented 11 years ago

From sype...@gmail.com on July 17, 2012 18:25:45 Closing for lack of feedback from original poster, and because other posters confirmed having resolved their issues.

mwkirk commented 11 years ago

From fongyat...@gmail.com on September 30, 2012 07:32:15 I am a new iOS developer and have the same issue before.

I finally find the problem is due to the p12 certificate. We should not use the private key p12 file, instead we should generate a p12 from your private key and the cert download from Apple.

Please execute the following OpenSSL command to get the correct p12 file: developer_identity.cer <= download from Apple mykey.p12 <= Your private key

openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem openssl pkcs12 -export -inkey mykey.pem -in developer_identity.pem -out iphone_dev.p12

After that, you should use iphone_dev.p12 to communicate with apple server.

Julioacarrettoni commented 11 years ago

@mwkirk I don't know why, BUT THIS WORKED OUT FLAWLESLY! thank you! :) :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: