I am implementing passbook funcationality for my iOS app. I am using php as server side language to generate pass and distribute to devices. Passes are being successfully installed on the device and I am also able to update pass manually using pull to referesh. When I try to update pass automatically from server side I get the response status 8-invalid-token with message "Identifier is the rowID(index) in the database that caused the problem. Apple will disconnect you.....". I don't get why it is happening. Devices is being registered correctly and other end points are also working fine. If pass was not correct in the first place it should not get installed on the device. I signed the pass using the same pass type id certificate which I am using to send push notification. I also checked my certificates using this command listed here.
$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile server-ca-cert.pem
I treid it for both sandbox and production and it doesn't show any error. I am using production url for sending push notification to update pass; Here is my code for sending push;
$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = base_path().'/path/to/ptypeidcert.pem';//converted using ssl from passtypeid.p12 certificated
$push_token = $token;
$passIdentify = 'pass.myidentifier.coupon';
$payload = '{}';
$msg = chr(0) . pack('n', 32) . pack('H*', $push_token) . pack('n', strlen($payload)) . $payload . pack('n', strlen($passIdentify)) . $passIdentify;
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'cafile', base_path().'/path/to/entrust_2048_ca.cer');
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', 'export_password');
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
fwrite($apns, $msg);
PushNotifications::checkAppleErrorResponse($apns);// Just created a class to read response from apn server
@socket_close($apns);
fclose($apns);
Any help to further debug would be really appriciated. Something to debug my certificates? Note: My API end points are served on http protocole just for test purpose, will update them to https protocole. I've enabled HTTP services on device to install pass on passbook.
============ UPDATE ============= Here are the steps to generate my certificates.
- First I downloaded my Pass Type Id certificate(.cer) using CSR request with my key.
- Then exported that certificated using keychain access on Mac, to a
.p12
extension required for signing the coupon on creation time. That coupon is being successfully installed on device. Then I converted that
.p12
to.pem
used in above code for connecting push server. Using command;openssl pkcs12 -in path.p12 -out newfile.pem
If anything wrong with my certificate generation please point out.