16

i tried to run using local mac machine but go the following errors

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

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

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

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/apns/apns.php on line 9

Warning: socket_close() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 11

Warning: fclose() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 12

I got PEM certificated generated from other machine,

So I am totally confused what I have to do now.

Please let me know what I need to do to run it in localhost

cetver
  • 11,279
  • 5
  • 36
  • 56
Kamal Challa
  • 305
  • 1
  • 4
  • 12
  • i am having the same proble , i am able to run in my local XAMPP Server. But it is not running in my external server. – Biranchi Nov 23 '09 at 09:40
  • Hi Biranchi, Just check with your Hosting provider for whitelisting the ports That will solve your issue – Kamal Challa Nov 28 '09 at 11:55

1 Answers1

59

I think that you may have exported the certificate, but not the private key from the .cer file that apple supplies.

These instructions from markbates might help out:

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 covert the p12 file to a pem file:

$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts
jessecurry
  • 22,068
  • 8
  • 52
  • 44
  • hi jessecurry Thanks a lot for your suggestion Its working great, except one warning Warning: socket_close(): supplied resource is not a valid Socket resource. Could you please tell me what might be the problem ? – Kamal Challa Sep 29 '09 at 06:22
  • That sounds like a php error. What version of php are you using? And what are you passing to socket_close()? – jessecurry Sep 29 '09 at 13:09
  • 1
    iam using pHP version 5 $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext); socket_close($apns); – Kamal Challa Sep 30 '09 at 11:53
  • I'm not really a PHP guy, but I think that you might use fclose() when you create with stream_socket_client. I *think* that socket_close() works with socket_create(), don't take it too seriously though, I may be wrong. – jessecurry Sep 30 '09 at 13:27
  • Thank you! I was using a slightly different method of converting the certificate and key separately and although in the past it had worked it no longer did when I needed to renew. This method worked perfectly and was easier. – Adam S. Nov 30 '10 at 17:39
  • @KamalChalla I have the same issue about the stream_socket_client(): SSL: Connection reset by peer , stream_socket_client(): Failed to enable crypto Did you solve that ? – Samah Ahmed Aug 14 '16 at 20:49