11

I have an IPhone application in which i am implementing push notifications.For that i created a csrfile,p12 file,and production cer.Enabled push notification for the app id.And provision file downloaded.And when i run on the device i got a registering notification came also.But when i combined the pem file from certificate and pem file from p12 key,and generated another pem file and put in my server.The push notifications are not coming in to my phone.I have used this commands on the terminals to create files.`

openssl x509 -in aps_production.cer -inform der -out phoneapp.pem 

openssl pkcs12 -nocerts -out phoneappKey.pem -in veapp.p12

cat phoneapp.pem phoneappKey.pem > applicationwebservice.pem

`can anybody help me to get the pem file correctly?

hacker
  • 8,919
  • 12
  • 62
  • 108

3 Answers3

37

After getting the p12 file, it needs to be converted to the PEM format by executing this command from the terminal:

openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12

If you wish to remove the passphrase, either do not set one when exporting/converting or execute:

openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

Finally, you need to combine the key and cert files into a apns-dev.pem file we will use when connecting to APNS:

cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem

This is the way to get the pem file, for more details refer my blog

Charan
  • 4,940
  • 3
  • 26
  • 43
11

Try with these commands below :

openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12

openssl pkcs12 -nocerts -out key.pem -in key.p12

openssl rsa -in key.pem -out key.unencrypted.pem

cat cert.pem key.unencrypted.pem > ck.pem
Armance
  • 5,350
  • 14
  • 57
  • 80
waheeda
  • 1,097
  • 1
  • 9
  • 18
2

For creation of .pem file you need to follow the below simple steps.

Here you go.

Step 1 : Login to your Developer account go to Provisioning Portal, click "Certificates". Then, click '+' button.

Step 2 : Select Apple Push Notification service SSL (Production) option under Distribution section, then click "Continue".

Step 3 : Select the App ID you want to use for your BYO app (How to Create An App ID), then click "Continue" to go to next step.

Step 4 : Follow the steps "About Creating a Certificate Signing Request (CSR)" for create a Certificate Signing Request.

Step 5 : Upload the ".CSR" file which is generated in Step 4, then click "Generate".

Step 6 : Click "Done" to finish the registration, the iOS Provisioning Portal Page will be change the UI.

Step 7 : Now go to "Keychain", look for the certificate you have just installed. If unsure which certificate is the correct one, it should start with "Apple Production IOS Push Services:" followed by your app's bundle ID.

Step 8 : Expand the certificate, you should see the private key with either your name or your company name. Select both items by using the "Select" key on your keyboard, right click (or cmd-click if you use a single button mouse), choose "Export 2 items". Then save the p12 file with name "yourselectedname.p12" to your Desktop - now you will be prompted to enter a password to protect it, you can either click Enter to skip the password or enter a password you desire.

Step 9 : Now open "Terminal" on your Mac, and run the following commands:
cd
cd Desktop
openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts

** DONE you have successfully created an Apple Push Notification Certificate (.pem file)!**

Maulik Pandya
  • 2,200
  • 17
  • 26