1

I'm getting the following error when trying to send 'Push Notifications' connecting APNS using PHP:

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 

Warning: stream_socket_client(): Failed to enable crypto

Warning: stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error) 

Here is my code:

$payload = '{"aps":{"alert":"' . $message . '","sound":"default"}}';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'Certificate.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',      $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);

$msg = chr(0) . pack('n', 32) . pack('H*', $item) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
 fclose($fp);
Vimal Saifudin
  • 1,815
  • 1
  • 21
  • 28
  • get us your php code :P – Blueblazer172 Nov 13 '16 at 11:09
  • Yes, please share your code. – George Whitaker Nov 13 '16 at 11:12
  • It sounds like you lack (1) TLS 1.0 and above, (2) Server Name Indication, and (3) possibly the *Entrust.net Certification Authority (2048)* root. Also see [“verify error:num=20” when connecting to gateway.sandbox.push.apple.com](http://stackoverflow.com/a/23351633/608639) – jww Nov 13 '16 at 19:16
  • @jww Thank you. Missing Entrust.net Certification Authority (2048) was the problem. Added this line after downloading the Entrust Root Certifcate `stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');`. Notifications works fine now – Vimal Saifudin Nov 14 '16 at 05:42

2 Answers2

3

Root certificate and adding the following line fixed the issue

`stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');`
Vimal Saifudin
  • 1,815
  • 1
  • 21
  • 28
0

Ask you Server admin to open port 2195 or 2196 for outgoing connections. It will solve you issue.

Kenil
  • 11
  • 3