Generating Push Certificate with a passphrase

Hello,


I have a production provisioning profile with that supports push notifications. I have generated the push notification PEM file, which contains both the cert and the key. I have done this using a number of different methods that I found on the web.


The resulting PEM file works fine, with 1 caveat. I cannot seem to incorporate a passphrase the the PEM file.


Here is how I have tested this:


On my LOCAL machine that I created the PEM file, I tested a push notification by using a Python-based push notification client (PyAPNS) and sent a push notification to an App that I have installed on my iPhone via TestFlight (using a production/distribution provisioning profile). This works.


On a remote server (where the actual service that sends the push notification to Apple), I have installed this PEM file, pointed the PHP-based server at it, and sent a push notification to my device. This works.


On my LOCAL machine, I create a PEM file with the combined cert and key from above; however, this time, I use a passphrase to generate the PEM file. I upload this new PEM file to the remote server running PHP, point the server at this new certificate, add the logic to incorporate the passphrase, and then everything breaks. It isn't that I am NOT receiving the push notification (which, I am not), but the push notification call returns an error, and I am pretty sure fails to send. Here is the PHP code snipet:


$apns_cert= 'apple_push_certificate_location/mycert.pem';

$ctx = stream_context_create();

stream_context_set_option($ctx, 'ssl', 'passphrase', 'mypassphrase');

stream_context_set_option($ctx, 'ssl', 'local_cert', $apns_cert);

$fp = stream_socket_client(

'ssl://gateway.push.apple.com:2195', $err,

$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)

exit("Failed to connect: $err $errstr" . PHP_EOL);


// End snipet


The err is a 0 and the errstr is blank. I know that this code snippet works, because it works when the PEM does not have a passphrase, and I have seen this code snipet all over the web.


Big question: Do I need to generate the PEM file with the passphrase on the machine that is serving up the push notification request? Like I said, I am generating the PEM with the passphrase on my local machine, and then uploading the result to the server.


Oh, also, I did use the openssl s_client with both the passphrase and not passphrase, and the output of both gave me the certificates back and the Master-Key in the results. The PEM without the passphrase also gave me output for the TLS session ticket, but the PEM with the passphrase did not.


Any help would be appreciated.

Replies

An update. I have resolved my issue. There are a number of Push Notification Certificate/Key generation instructions out on the web. For me, the only method that worked in the case where the resulting Key had a passphrase associated with it was the following:


1. Export Both the Certificate and Key together as 1 p12 file. When it asks for a password, leave this blank. Name the file YourCertAndKeyPair.p12

2. Run command: openssl pkcs12 -out YourCertAndKeyPair.pem -in YourCertAndKeyPair.p12

3. It will ask for an Import Password -- just hit enter

4. It will ask for a PEM pass phrase -- put the password you want and hit enter. It will ask you to verify. Enter same password.

5. It will ask for a PEM pass phrase AGAIN -- put the same password in as you did for #4. It will ask you to verify. Enter the same password.

6. Done.


I have found that with a PHP server, you have to put the Cert and Key in the same physical file; however, if you want to also use a passphrase, then each portion of the PEM file must be passphrased -- with the same passphrase.


I am sure there are other ways to accomplish this. I am not a Cert/Key expert. But, this worked for me, and given the trouble I had testing it, I thought I'd pass it along to others. Good luck!