Creating .pem file for APNS?

后端 未结 11 2150
野的像风
野的像风 2020-11-27 08:59

How do I create a .pem file to be stored in the hosting server for APN payload data?

相关标签:
11条回答
  • 2020-11-27 09:13

    NOTE: You must have the Team Agent or Admin role in App Store Connect to perform any of these tasks. If you are not part of a Team in App Store Connect this probably does not affect you.

    Sending push notifications to an iOS application requires creating encyption keys. In the past this was a cumbersome process that used SSL keys and certificates. Each SSL certificate was specific to a single iOS application. In 2016 Apple introduced a new authentication key mechanism that is more reliable and easier to use. The new authentication keys are more flexible, simple to maintain and apply to more than on iOS app.

    Even though it has been years since authentication keys were introduced not every service supports them. FireBase and Amazon Pinpoint support authentication keys. Amazon SNS, Urban Airship, Twilio, and LeanPlum do not. Many open source software packages do not yet support authentication keys.

    To create the required SSL certificate and export it as PEM file containing public and private keys:

    1. Navigate to Certificates, Identifiers & Profiles
    2. Create or Edit Your App ID.
    3. Enable Push Notifications for the App ID
    4. Add an SSL Certificate to the App ID
    5. Convert the certificate to PEM format

    If you already have the SSL certificate set up for the app in the Apple Developer Center website you can skip ahead to Convert the certificate to PEM format. Keep in mind that you will run into problems if you do not also have the private key that was generated on the Mac that created the signing request that was uploaded to Apple.

    Read on to see how to avoid losing track of that private key.

    Navigate to Certificates, Identifiers & Profiles

    Xcode does not control certificates or keys for push notifications. To create keys and enable push notifications for an app you must go to the Apple Developer Center website. The Certificates, Identifiers & Profiles section of your account controls App IDs and certificates.

    To access certificates and profiles you must either have a paid Apple Developer Program membership or be part of a Team that does.

    1. Log into the Apple Developer website
    2. Go to Account, then Certificates, Identifiers & Profiles

    Create an App ID

    Apps that use push notifications can not use wildcard App IDs or provisioning profiles. Each app requires you to set up an App ID record in the Apple Developer Center portal to enable push notifications.

    1. Go to App IDs under Identifiers
    2. Search for your app using the bundle identifier. It may already exist.
    3. If there is no existing App ID for the app click the (+) button to create it.
    4. Select Explicit App ID in the App ID Suffix section.
    5. Enter the bundle identifier for the app.
    6. Scroll to the bottom and enable Push Notifications.
    7. Click Continue.
    8. On the next screen click Register to complete creating the App ID.

    Enable Push Notifications for the App ID

    1. Go to App IDs under Identifiers
    2. Click on the App ID to see details and scroll to the bottom.
    3. Click Edit
    4. In the App ID Settings screen scroll down to Push Notifications
    5. Select the checkbox to enable push notifications.

    Creating SSL certificates for push notifications is a process of several tasks. Each task has several steps. All of these are necessary to export the keys in P12 or PEM format. Review the steps before proceeding.

    Add an SSL Certificate to the App ID

    1. Under Development SSL Certificate click Create Certificate. You will need to do this later for production as well.
    2. Apple will ask you to create a Certificate Signing Request

    To create a certificate you will need to make a Certificate Signing Request (CSR) on a Mac and upload it to Apple.

    Later if you need to export this certificate as a pkcs12 (aka p12) file you will need to use the keychain from the same Mac. When the signing request is created Keychain Access generates a set of keys in the default keychain. These keys are necessary for working with the certificate Apple will create from the signing request.

    It is a good practice to have a separate keychain specifically for credentials used for development. If you do this make sure this keychain is set to be the default before using Certificate Assistant.

    Create a Keychain for Development Credentials

    1. Open Keychain Access on your Mac
    2. In the File menu select New Keychain...
    3. Give your keychain a descriptive name, like "Shared Development" or the name of your application

    Create a Certificate Signing Request (CSR)

    When creating the Certificate Signing Request the Certificate Assistant generates two encryption keys in the default keychain. It is important to make the development keychain the default so the keys are in the right keychain.

    1. Open Keychain Access on your Mac.
    2. Control-click on the development keychain in the list of keychains
    3. Select Make keychain "Shared Development" Default
    4. From the Keychain Access menu select Certificate Assistant, then Request a Certificate From a Certificate Authority... from the sub menu.
    5. When the Certificate Assistant appears check Saved To Disk.
    6. Enter the email address associated with your Apple Developer Program membership in the User Email Address field.
    7. Enter a name for the key in the Common Name field. It is a good idea to use the bundle ID of the app as part of the common name. This makes it easy to tell what certificates and keys belong to which app.
    8. Click continue. Certificate Assistant will prompt to save the signing request to a file.
    9. In Keychain Access make the "login" keychain the default again.

    Creating the signing request generated a pair of keys. Before the signing request is uploaded verify that the development keychain has the keys. Their names will be the same as the Common Name used in the signing request.

    Upload the Certificate Signing Request (CSR)

    Once the Certicate Signing Request is created upload it to the Apple Developer Center. Apple will create the push notification certificate from the signing request.

    1. Upload the Certificate Signing Request
    2. Download the certificate Apple has created from the Certificate Signing Request
    3. In Keychain Access select the development keychain from the list of keychains
    4. From the File menu select Import Items...
    5. Import the certificate file downloaded from Apple

    Your development keychain should now show the push certificate with a private key under My Certificates in Keychain Access:

    At this point the development keychain should be backed up. Many teams keep their push certificates on secure USB drives, commit to internal version control or use a backup solution like Time Machine. The development keychain can be shared between different team members because it does not contain any personal code signing credentials.

    Keychain files are located in ~/Library/Keychains.

    Some third party push services require certificates in Privacy Enhanced Mail (PEM) format, while others require Public-Key Cryptography Standards #12 (PKCS12 or P12). The certificate downloaded from Apple can be used to export certificates in these formats - but only if you have kept the private key.

    Convert the certificate to PEM format

    1. In Keychain Access select the development keychain created earlier.
    2. Select the push certificate in My Certificates. There should be a private key with it. ![Download CER push certificate](keychain/import complete.png)
    3. From the File menu select Export Items...
    4. In the save panel that opens, select Privacy Enhanced Mail (.pem) as the file format.
    5. Save the file
    0 讨论(0)
  • 2020-11-27 09:16

    There is a easiest way to create .Pem file if you have already apns p12 file in your key chain access.

    Open terminal and enter the below command:

    For Devlopment openssl pkcs12 -in apns-div-cert.p12 -out apns-div-cert.pem -nodes -clcerts

    For Production openssl pkcs12 -in apns-dist-cert.p12 -out apns-dist-cert.pem -nodes -clcerts

    Rename your P12 file with this name : apns-div-cert.p12 otherwise instead of this you need to enter your filename. Thanks!!

    0 讨论(0)
  • 2020-11-27 09:17

    This is how I did it on Windows 7, after installing OpenSSL (link goes to the Win32 installer, choose the latest version and not the light version).

    With this method you only need the .cer file downloaded from Apple.

    c:\OpenSSL-Win32\bin\openssl.exe x509 -in aps_development.cer -inform DER -out developer_identity.pem -outform PEM
    

    this will create a file which you will then need to add your private key too.

    -----BEGIN PRIVATE KEY-----
    MIIEuwIBADANBgkqhk....etc
    MIIEuwIBADANBgkqhk....etc
    MIIEuwIBADANBgkqhk....etc
    MIIEuwIBADANBgkqhk....etc
    -----END PRIVATE KEY-----
    -----BEGIN CERTIFICATE-----
    AwIBAgwIBADAwIBADA....etc
    AwIBAgwIBADAwIBADA....etc
    AwIBAgwIBADAwIBADA....etc
    -----END CERTIFICATE-----

    That's it.

    0 讨论(0)
  • 2020-11-27 09:19

    I would suggest a much more simple solution. Just use Certifire.
    Certifire is a macOS application that generates Apple Push Notification Certificates with just one click in a couple of seconds.

    Here are the steps:
    1. Download the app.
    2. Log in using your Apple Developer Account credentials.
    3. Choose the App-ID
    4. Click "Generate" button
    5. You're done!

    You will get APN certificates in .pem format as well as in .p12 format. Even more, you will get also combined .pem and .p12 too (key+cert)!
    Much more, you will get no-passphrase versions of all these certificates also!

    0 讨论(0)
  • 2020-11-27 09:20

    You can have a look here. I have the detailed process described with images, right from creating the certificate, to app key to provisioning profile, to eventually the pem. http://docs.moengage.com/docs/apns-certificate-pem-file

    0 讨论(0)
  • 2020-11-27 09:31

    Launch the Terminal application and enter the following command after the prompt

      openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes
    
    0 讨论(0)
提交回复
热议问题