Arun Mohan
Arun Mohan

Reputation: 744

IOS push notification failed due to handshake_failure

iOS push notification failed due to handshake_failure, but it is working fine in my local machine and it gives error when deployed on server.

I am using apns-0.1.5.jar

Code :

    static
    {
       service = APNS.newService()
            .withCert(ClassLoader.class.getResourceAsStream("cert.p12"), "pwd")
            .withSandboxDestination()
            .build();
    }


    public static void pushMSG(String msg,String deviceToken)
    {

      String payload = APNS.newPayload().alertBody(msg).build();

      AppLog.info("Message : "+msg+", deviceToken "+deviceToken);

      service.push(deviceToken, payload);

    }

ERROR LOG

    com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
com.notnoop.apns.internal.Utilities.wrapAndThrowAsRuntimeException(Utilities.java:268)
com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:173)
com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
com.gcash.notification.APNSManager.pushMSG(APNSManager.java:35)
com.gcash.TestServlet.doGet(TestServlet.java:58)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause

    javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1720)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:632)

Upvotes: 3

Views: 5409

Answers (1)

MattZ
MattZ

Reputation: 381

I had the same problem and I fixed it by the following steps.

  1. Check your .p12 file and .cer file. Make sure they are corresponding to each other.
  2. Did you export .p12 file and use it directly in your code? If so, please refer to this answer. "we should generate a p12 from your private key and the cert download from Apple."

Hope it works.

Upvotes: 1

Related Questions