21

unable to get this getting these errors when running PHP in terminal as php simplepush.php

Warning: stream_socket_client(): Unable to set private key file `/users/accenture/Desktop/newAPNS/ck.pem' in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Warning: stream_socket_client(): failed to create an SSL handle in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Warning: stream_socket_client(): Failed to enable crypto in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Failed to connect: 0 

I created all certificates and pem file by using raywenderlich article, http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1#comments

Muhammad Bilal
  • 2,106
  • 1
  • 15
  • 24
kumar
  • 894
  • 1
  • 6
  • 15
  • Can you show us the chmod of: ```/users/accenture/Desktop/newAPNS/```? – ChoiZ Nov 12 '14 at 15:26
  • accenture:newAPNS accenture:$ php simplepush.php – kumar Nov 12 '14 at 15:49
  • usage: chmod [-fhv] [-R [-H | -L | -P]] [-a | +a | =a [i][# [ n]]] mode|entry file ... chmod [-fhv] [-R [-H | -L | -P]] [-E | -C | -N | -i | -I] file ... – kumar Nov 12 '14 at 16:19
  • now i successfully run the php and i'm getting notification, main problem is creating p12 file, i used to create p12 file using http://stackoverflow.com/questions/1481443/apple-push-notification-service. this is working – kumar Nov 13 '14 at 07:01

3 Answers3

66

Problem is pem file wasn't correct, I created pem file using http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 . Creation of p12 file and with p12 creating pem file are not working for me. Correct process to create p12 and with p12 creating pem file as bellow

Once you have the certificate from Apple for your application, export your key and the apple certificate as p12 files. Here is a quick walkthrough on how to do this:

  1. Click the disclosure arrow next to your certificate in Keychain Access and select the certificate and the key.
  2. Right click and choose Export 2 items….
  3. Choose the p12 format from the drop down and name it cert.p12.

Now convert the p12 file to a pem file:

$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts

This is working for me, now I am getting a push notification.

pableiros
  • 14,932
  • 12
  • 99
  • 105
kumar
  • 894
  • 1
  • 6
  • 15
9

Converting the key file to pem recommend in http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 was causing problems for me.

Running

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

instead of the

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

solved my issues.

Starchand
  • 684
  • 1
  • 9
  • 23
0

I have followed a youtube tutorial which is nearly same as raywenderlich article. I've just forgot to add PEM pass phrase. After adding it, as described here, it worked:

stream_context_set_option($ctx, 'ssl', 'passphrase', 'MyPassPhrase');
Rashid
  • 1,515
  • 16
  • 16