A
A
asscarnival2016-11-25 16:52:22
PHP
asscarnival, 2016-11-25 16:52:22

What certificate is used to send web push messages via APNS?

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certDir);

A pem certificate is needed to establish a connection, but what exactly is it made of? For subscriptions, I have a cer and a p12 WebPush certificate made from it, which Apple calls website aps production. I thought that one of these certificates needed to be converted to pem. I tried .p12 in pem, I also tried to sign cer with a private key from .p12, both of these certificates are being verified
openssl s_client -connect gateway.push.apple.com:2195 -cert cert.pem

but pushes never come. I think that the problem is in the certificate, I am attaching the code below
$certDir = 'cert.pem';

    $address =  'gateway.push.apple.com:2195';
    $deviceToken = 'D1BF307920AEA35AA1E2C3F4B38863FC801F08EEC9BA00FABDDBCFF3C517DAB6';

    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', $certDir);
    stream_context_set_option($ctx, 'ssl', 'passphrase', '***');

    $socketClient = stream_socket_client(
      $address,
      $errno,
      $errstr,
      60,
      STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT,
      $ctx
    );
    var_dump($errstr);
    $payload = array(
      'aps'    => array(
        'alert'    => array(
          'title'    => 'Foo',
          'body'   => 'bar',
          'action' => 'view',
        ),
      )
    );

    $encodedPayload = json_encode($payload);

//		$binaryMessage = chr(0).
//			chr(0).
//			chr(32).
//			pack('H*', $deviceToken).
//			chr(0).chr(strlen($encodedPayload)).
//			$encodedPayload;

    $binaryMessage =  chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($encodedPayload)) .$encodedPayload;

    $result = fwrite($socketClient,  $binaryMessage, strlen($binaryMessage));

    var_dump($result);

    while(!feof($socketClient)) {
      var_dump(fgets($socketClient,64));
    }

    fclose($socketClient);

$errstr = string(0) ""
$result = int(119)
var_dump(fgets($socketClient,64)) = bool(false)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Doniy, 2016-11-25
@doniys_a

https://habrahabr.ru/post/231727/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question