views:

434

answers:

2

Hi All,

I am getting this error in my php script , while sending payload data.

Warning: stream_socket_client() [function.stream-socket-client]:
Unable to set private key file `/Applications/XAMPP/xamppfiles/htdocs/test/apn/apns-dev.pem'
in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42

Warning: stream_socket_client() [function.stream-socket-client]:
failed to create an SSL handle
in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42

Warning: stream_socket_client() [function.stream-socket-client]:
Failed to enable crypto
in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42

Warning: stream_socket_client() [function.stream-socket-client]:
unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)
in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42

What is the reason ? Do I need to change any settings? I have also installed the .pem file in the server.

Thanks

+1  A: 

Can you post the PHP code (push.php) you're using to connect to APN?

Some shots in the dark:
- Are both the certificate and private key in that one .pem file?
- Did you remove the password from the private key file, or are you setting it properly in your PHP code?
- Does the user running your script have the proper unix permissions to access/read the cert/key file?
- Can you access Apple's server from your machine? You can test by running telnet.

telnet gateway.sandbox.push.apple.com 2195
Sangraal
A: 

I had this problem and the key generation process was the issue, there are two different openssl commands for certificate and key file whereas I was using the same for both. Here's how I generate certificate and remove password from private key file (assuming you have exported .p12 files) :

openssl pkcs12 -clcerts -nokeys -out aps-dev-cert.pem -in aps-dev-cert.p12
openssl pkcs12 -nocerts -out aps-dev-key.pem -in aps-dev-key.p12
openssl rsa -in aps-dev-key.pem -out aps-dev-key.unencrypted.pem
cat aps-dev-cert.pem aps-dev-key.unencrypted.pem > aps-dev.pem

Note the difference in the first two openssl commands.

Ali Nadalizadeh