mrDoctorWho / ejabberd_mod_apns

An ejabberd module to send PUSH messages to iOS devices through APNS
MIT License
33 stars 19 forks source link

HTTP/2 API support #23

Open karunreddy30 opened 6 years ago

karunreddy30 commented 6 years ago

Hi,

Thank you for writing this module. I've been trying to use it in my app and have been getting this failure in ssl:send - wondering if you could give some suggestions on how to debug this? Appreciate your respone.

2017-12-21 00:39:23.829 [error] <0.23221.2>@ejabberd_hooks:safe_apply:383 Hook offline_message_hook crashed when running mod_apns:message/1:
** Reason = {error,{badmatch,ok},[{mod_apns,send_payload,[{file,"src/mod_apns.erl"},{line,76}],3},{mod_apns,message,[{file,"src/mod_apns.erl"},{line,132}],1},{ejabberd_hooks,safe_apply,[{file,"src/ejabberd_hooks.erl"},{line,380}],4},{ejabberd_hooks,run_fold1,[{file,"src/ejabberd_hooks.erl"},{line,364}],4},{ejabberd_sm,route,[{file,"src/ejabberd_sm.erl"},{line,145}],1},{ejabberd_local,route,[{file,"src/ejabberd_local.erl"},{line,101}],1},{ejabberd_router,do_route,[{file,"src/ejabberd_router.erl"},{line,372}],1},{ejabberd_router,route,[{file,"src/ejabberd_router.erl"},{line,93}],1}]}
mrDoctorWho commented 6 years ago

Hello @karunreddy30,

Could you please tell me what ejabberd version are you on? And mod_apns's git branch name.

karunreddy30 commented 6 years ago

Thanks for getting back. Am on ejabberd 17.11.31 and using 'origin/master'.

  1. The line numbers might be different because I added another function to mod_apns.erl - which I did not invoke when I shared the result.
  2. The error I gave might not be an error afterall because am capturing the result from ssl:send into a variable and just printing that variable. And that seems to be the reason for {error,{badmatch,ok}. The "ok" here seems to suggest ssl:send did indeed succeed.
  3. But apns doesn't invoke the notification if I assume ssl:send succeeded.
  4. I verified my cert and key files with apns like this: openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert ~/Downloads/OpensslApns/voip-dev-cert.pem -key ~/Downloads/OpensslApns/voip-dev-key-noenc.pem
mrDoctorWho commented 6 years ago

Please run an unmodified version so I could trace errors to their lines.

karunreddy30 commented 6 years ago

I ran with the unmodified version and here is the log. The FORMAT_ERROR might be because I changed DEBUG to INFO_MSG.

2017-12-21 01:54:59.970 [info] <0.29373.2>@mod_apns:send_payload:35 FORMAT ERROR: "Trying to send payload with these parameters: Address: ~s Port: ~s Cert: ~s Keyfile: ~s Password ~s" ["gateway.sandbox.push.apple.com",2195,<<"/home/karunreddy30/voip-dev/voip-dev-cert.pem">>,<<"/home/karunreddy30/voip-dev/voip-dev-key-noenc.pem">>,undefined]
2017-12-21 01:55:00.067 [info] <0.29373.2>@mod_apns:send_payload:58 Successfully sent payload to the APNS server
2017-12-21 01:55:01.210 [info] <0.29373.2>@mod_apns:message:84 Offline message
karunreddy30 commented 6 years ago

Just an FYI - I've verified the notifications through curl command and they seem to work. The only thing extra I sent as part of curl is the "apns-topic". Wondering if there is a way to include that as part of ssl:send?

Here is the curl command I used: curl -v -d '{"aps":{"alert":"Test Push","sound":"default"}}' --cert ~/Downloads/OpensslApns/voip-dev.pem -H "apns-topic: com.***.***.voip" --http2 https://api.development.push.apple.com/3/device/<device-token-with-no-spaces> The cert used here is the concatenation of the cert and key file list before.

mrDoctorWho commented 6 years ago

I'm not an Apple user/developer. Was there a change to the APIs?

The API mod_apns uses is seem to be pretty old and you're using a different one.

Unfortunately, I can't really understand why this happens with your configuration. I've had several complaints just like yours, but all of them got resolved with configuration change. For example, you might try using non-sandbox version of the APNS gateway.

I also have a customer who complained about APNS with correct configuration, I configured it myself. But their priority not the APNS, so they don't really care and I don't change anything.

I'm afraid I'll have to check out if the module works for me.

karunreddy30 commented 6 years ago

Thank you for the follow up. The issue was due to the message size I was sending. Once I started sending smaller payloads, I was able to get the notifications.

Also, the gateway push seems to be a legacy thing now: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/BinaryProviderAPI.html#//apple_ref/doc/uid/TP40008194-CH13-SW1

mrDoctorWho commented 6 years ago

Well, it seems I need to update the module to support modern APIs.