Validate an APNS Certificate From Your Terminal

This is a quick tip for everyone out there setting up an APNS certificate: you can verify the validity of your APNS certificate locally in your terminal before uploading them to platforms like Amazon SNS or Iterable. Sharing this because I tend to forget this little trick that makes setting up APNS certificates painless. The following tip assumes you have already exported a .p12 file and just need to validate everything is working as a sanity check. If you have not done that yet, follow the steps outlined in this StackOverflow answer: http://stackoverflow.com/a/21253261. Otherwise, follow the steps below and let me know if you run into any snafus:
 

First: Convert your APNS .p12 file to .pem

openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts

 

Second: Obtain an APNS token

You can go to Amazon SNS or wherever you are storing them to get your APNS token. APNS tokens are registered in your “AppDelegate.m” implementation file in the following method:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

 

Third: use the following script to test your .pem key

(Credit to the following article: https://support.pubnub.com/support/solutions/articles/14000043600-how-do-i-test-my-pem-key-)

Export the python script that is shown at the link above as “apns_debug.py” to the same directory as your .pem file on your computer. Once done, run the following command:

python apns_debug.py pushcert.pem "your_APNS_token"