Apple recently added a new authentication method to APNS ( Apple Push Notification Authentication Key (Sandbox & Production)).
The downloaded key is a .p8
file with a private key:
$ cat APNSAuthKey_3HHEB343FX.p8
-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBH...Already.Revoked...lHEjCX1v51W
-----END PRIVATE KEY-----
I am using APNs messages using the old method – adding them to keychain, asking for a certificate and using OpenSSL to send messages to gateway.production.push.apple.com:2195
.
How do I send push notifications using standard CLI Linux tools (OpenSSL, Python etc.) using the new format?
Best Answer
If you have curl with HTTP/2 support and openssl with ECDSA support installed on your machine, you can use the following script to test push notifications using an APNs Auth Key:
NOTE: I use a slight variation of this script for testing on macOS with homebrew versions of curl and openssl: http://thrysoee.dk/apns/
Apple now have documentation for this method to Send a Push Notification Using a Token.