realstyleMobile / javapns

Automatically exported from code.google.com/p/javapns
0 stars 0 forks source link

Having problems initiating the SSL connection to the APNS #126

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by ch...@kipsu.com on 9 Jun 2012 at 11:07

GoogleCodeExporter commented 9 years ago
We are also facing the same problem - 
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure.

Any solution will be helpful.

Thank You.

Original comment by isenages...@gmail.com on 28 Jun 2012 at 5:46

GoogleCodeExporter commented 9 years ago
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.

Original comment by sype...@gmail.com on 2 Jul 2012 at 9:16

GoogleCodeExporter commented 9 years ago

Original comment by sype...@gmail.com on 2 Jul 2012 at 10:33

GoogleCodeExporter commented 9 years ago
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. 

Original comment by jdsamuel...@gmail.com on 3 Jul 2012 at 2:41

GoogleCodeExporter commented 9 years ago
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("<filename>.p12", "<password>", 
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).

Original comment by darshwit...@gmail.com on 17 Jul 2012 at 9:07

GoogleCodeExporter commented 9 years ago
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... 

Original comment by darshwit...@gmail.com on 17 Jul 2012 at 1:32

GoogleCodeExporter commented 9 years ago
Closing for lack of feedback from original poster, and because other posters 
confirmed having resolved their issues.

Original comment by sype...@gmail.com on 17 Jul 2012 at 6:25

GoogleCodeExporter commented 9 years ago
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.

Original comment by fongyat...@gmail.com on 30 Sep 2012 at 7:32

GoogleCodeExporter commented 9 years ago
I had the same issue as described in this post and I tested the solution 
described in #8 and it worked! Thank you! 

Original comment by martinli...@gmail.com on 19 Mar 2013 at 11:24