0

I followed this question for consuming APNS Feedback Service. Here is my code for requesting feedback servers;

function send_feedback_request() {
    //connect to the APNS feedback servers
    //make sure you're using the right dev/production server & cert combo!
    $stream_context = stream_context_create();
    stream_context_set_option($stream_context, 'ssl', 'local_cert', 'my_production_cerficate.pem');
    $apns = stream_socket_client('ssl://feedback.push.apple.com:2196', $errcode, $errstr, 60, STREAM_CLIENT_CONNECT, $stream_context);
    if(!$apns) {
        die("ERROR $errcode: $errstr\n");
    }


    $feedback_tokens = array();
    //and read the data on the connection:
    while(!feof($apns)) {
        $data = fread($apns, 38);
        if(strlen($data)) {
            $feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
        }
    }
    fclose($apns);
    return $feedback_tokens;
}

When I use this function, it reports following errors;

Warning: stream_socket_client() [function.stream-socket-client]: Unable to set private key file /my_directories/my_production_cerficate.pem in /my_directories/apnsfeedback.php on line 7

Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle in /my_directories/apnsfeedback.php on line 7

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /my_directories/apnsfeedback.php on line 7

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://feedback.push.apple.com:2196 (Unknown error) in /my_directories/apnsfeedback.php on line 7

I am using my production certificate (.pem) which I use for sending push notification messages, and it's valid + working. So an invalid certificate is not the issue here. What am I doing wrong here?

Community
  • 1
  • 1
Bartu
  • 2,189
  • 2
  • 26
  • 50
  • Do you have the cert + key combined in that file? Are your permissions such that the web server can read the file? Is the key protected by a passphrase? Etc, etc. – Colin M Apr 08 '13 at 13:54
  • i am sending push notifications via that cerficate, in the same directory with a push.php script. So yes, it has cert+key. A regular pem file used for push messages. It is key protected but I cannot set the key as it rises another error saying passphrase cannot be set... Should I be using a different certificate than my regular push notification certificate? – Bartu Apr 08 '13 at 13:55

1 Answers1

0

After much annoyance I finally figured out what this issue was for me. Our cert was perfectly fine for sending messages, but I had to create a cert without encryption or passphrase for it to work with feedback

openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

Was the step we did not use on our pem for the pushes being sent. After using it the feedback seems to be OK, but it is only returning 3 tokens although I feel we should have more.

naphier
  • 256
  • 2
  • 13
  • This service report removed devices only once. Which is a bit dangerous since if you don't process feedback on the moment it arrives, you missed it for good. I really wish apple had a second feedback api which returns all removed devices. – Bartu Feb 25 '14 at 09:04
  • That or at least a dry-run like GCM. Fortunately we plan to push to our users on a somewhat frequent basis to let them know of news items. This will allow us to poll which tokens are bad too. I have to say the APNS setup is very unfriendly. – naphier Mar 04 '14 at 04:38