kaylavanhaverbeck / javapns

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

Is FeedbackServiceManager working ? #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

My question is simple, is FeedbackServiceManager class working ?

I use PushNotificationManager class to send my notifications and it works 
great, but if i try to 
read data from the apple feedback server, the server send me back :

Exception in thread "main" javax.net.ssl.SSLHandshakeException: 
sun.security.validator.ValidatorException: No trusted certificate found

The cercificate seems to be good because i can send my notifications with it...

Here is a snippet of the code :

LinkedList<Device> liste = 
FeedbackServiceManager.getInstance().getDevices("feedback.sandbox.push.apple.com
", 2196, 
"PushCertificats.p12", "myPassword", SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);

        for(int i=0; i<liste.size(); i++) {
            System.out.println(liste.get(i).getToken()+" "+liste.get(i).getLastRegister());
        }

Original issue reported on code.google.com by julien.r...@gmail.com on 14 Aug 2009 at 2:16

GoogleCodeExporter commented 8 years ago
Hi,

I had the same issue.
The problem is apparently not your client certificate, but that you can't 
validate
Apple's server certificate.
I got it to work by modifying the way the SSLSocket is created in
SSLConnectionHelper.getSSLSocket().
When initializing the SSLContext, a trustmanager needs to be provided that 
contains
Apple's server certificate. Note that this trustmanager can only be set when 
using
the feedback service, using it when pushing notifications will result in an 
error.
Note that I have no idea if this is the best way of doing this, but hey, it 
works.

First, you need to get a hold of either Apple's server certificate or the 
certificate
of its Certification Authority:
This second option is the easiest, just download it from
http://aia.entrust.net/2048-l1b.cer

Then, use keytool (comes with your Java JDK) to create a keystore and add the
certificate to it. I used the same password as for my client certificate, that 
will
make it easier later on.

Finally, modify SSLConnectionHelper.getSSLSocket():
 * add a parameter to the method signature:
public SSLSocket getSSLSocket(boolean loadServerCertificate) throws ...

 * Where this method is called in FeedbackServiceManager.getDevices() pass 'true', on
the other 2 invocations pass 'false'

 * add the following code just above where the SSLContext is created in
SSLConnectionHelper.getSSLSocket() (replace the path to your keystore)
    TrustManager[] trustManagers = null;
    if (loadServerCertificate) {
        KeyStore ks2 = KeyStore.getInstance("JKS");
        ks2.load(new FileInputStream(new File("/path/to/my/server/certificate/keystore")),
this.keyStorePass.toCharArray());

        TrustManagerFactory tmf = TrustManagerFactory.getInstance(ALGORITHM);
        tmf.init(ks2);
        trustManagers = tmf.getTrustManagers();
    }

 * Finally, add the trustmanager as a parameter to the SSLContext initialization:
sslc.init(kmf.getKeyManagers(), trustManagers, null);

This worked for me, let me know how it goes.

Original comment by Iwi...@gmail.com on 15 Aug 2009 at 4:03

GoogleCodeExporter commented 8 years ago
Hello,

Can you provide a sample project of what you've done ? It will be very helpfull

Thanks for your help anyway

Original comment by julien.r...@gmail.com on 9 Sep 2009 at 7:40

GoogleCodeExporter commented 8 years ago
Ok don't read my previous message, this is working like a charm.

Original comment by julien.r...@gmail.com on 10 Sep 2009 at 2:03

GoogleCodeExporter commented 8 years ago
I've tried the changes, and am looking to integrate them into the code... but 
I'm getting no data.

How long does it take for the feedback service (apple) to start working? Does 
it only work once the iPhone App is 
published?

Bill

Original comment by idbill.p...@gmail.com on 24 Sep 2009 at 12:06

GoogleCodeExporter commented 8 years ago
I am facing the same issue as Bill. 
Could you please confirm how long does it takes until the feedback service 
generates
data?

thaks

Original comment by fernando...@gmail.com on 20 Oct 2009 at 10:19

GoogleCodeExporter commented 8 years ago
Hello

It's instantaneous.

I talk to the feedback service each time after sending notifications to my 
customer and 
iPhone who don't receive the notification appear in the list immediately.

Note that feedback service seems not to work in test environnement.

Original comment by julien.r...@gmail.com on 20 Oct 2009 at 11:17

GoogleCodeExporter commented 8 years ago
Hello Julien,

Thanks for your feedback. You are right. It doesnt work in the test environment 
and I
was doing my tests there.

Original comment by fernando...@gmail.com on 26 Oct 2009 at 2:51

GoogleCodeExporter commented 8 years ago
Big thanks to IwijnX for posting his solution

Worked fine for me, once I worked out how to do the keytool thing :)

Original comment by mattkr...@gmail.com on 3 Dec 2009 at 5:39

GoogleCodeExporter commented 8 years ago
Can someone explain more clearly the solution

Original comment by kalashni...@gmail.com on 14 Dec 2009 at 4:14

GoogleCodeExporter commented 8 years ago
The source code has been updated with my Feedback Service changes. You might 
also notice that the ssl cert 
thing is much more transparent now.

Original comment by idbill.p...@gmail.com on 19 Feb 2010 at 9:28