java-apns icon indicating copy to clipboard operation
java-apns copied to clipboard

not able to send push notifications because javax.net.ssl.SSLHandshakeException

Open dpurnik opened this issue 9 years ago • 9 comments

I am using maven dependency to include this library <groupId>com.notnoop.apns</groupId> <artifactId>apns</artifactId> 1.0.0.Beta6

Java version: J2SE-1.5

Code is pretty basic:

   public static void main( String[] args )
   {
          ApnsService service =
            APNS.newService()
            .withCert("absolute-path-to-file.p12"
                    , "password")
            .withSandboxDestination()
            .build();
    String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build();
    String token = "some token"; 

    service.start();
    service.push(token, payload);
    service.stop();
}

I am getting following stacktrace:

Exception in thread "main" com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at com.notnoop.apns.internal.Utilities.wrapAndThrowAsRuntimeException(Utilities.java:284) at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:342) at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:312) at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46) at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:56) at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36) at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:45) at Apple.ApplePushNeetloopsAPNS.App.main(App.java:25) Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:953) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:709) at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122) at java.io.OutputStream.write(OutputStream.java:75) at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:328) ... 6 more Caused by: java.io.EOFException: SSL peer shut down incorrectly at sun.security.ssl.InputRecord.read(InputRecord.java:482) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934) ... 11 more

dpurnik avatar Sep 07 '15 06:09 dpurnik

looks like an error w/ the .p12 file ?

https://github.com/notnoop/java-apns/issues/227

matzew avatar Sep 07 '15 09:09 matzew

I am trying to test it with some other prebuilt tool and update here. Thanks for response.

dpurnik avatar Sep 07 '15 09:09 dpurnik

I tried a mac appliction called Pusher to send notification with same p12 file and it is working fine.

dpurnik avatar Sep 07 '15 09:09 dpurnik

i was also getting the same error and i tried Pusher which correctly sent the notification but then i figured out what is the issue.

The method i used to generate .p12 from my production certificate was wrong. i was selecting both Certificate and Key and then right click to export 2 files to generate .p12 file. Which infact was wrong and increasing file size. i regenerated .p12 file by right clicking only the production certificate and Voila!!! it worked.

On the other hand why pusher was working was due to the fact that pusher was using the certificate directly and not the generated .p12 file.

Hope this helps

shows19 avatar Sep 25 '15 11:09 shows19

Thanks @shows19 . You made my day! ;-)

GeBeater avatar Feb 03 '16 17:02 GeBeater

I had a similar issue and what worked for me was following the instructions at NWPusher to generate my .p12 file.

abc2mit avatar Mar 27 '16 15:03 abc2mit

works like a charm, thank you @shows19

biglasbig avatar May 06 '16 09:05 biglasbig

My code was working fine with certificate and suddenly it stooped working with handshake failure. We tried many thing

  1. first test with apns_test if this will send test notification then you have problem with security configuration

Finally put certificate with in the war file. if you are testing out side folder then you might face this problem.

This work with me when I put certificate with in the war file.

muazzammughal avatar Jun 16 '16 14:06 muazzammughal

I have tried this, but it is still the same error.. NWPusher works though. Did you right click on the certificate or the private key? I remembered trying all 3 combinations, export the certificate, the private key, both cert and private key..

The complete error is always: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

JiboStore avatar Jan 25 '17 15:01 JiboStore