Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195' #29

Closed
aramboyajyan opened this issue May 21, 2013 · 7 comments
Closed
Labels

Comments

@aramboyajyan
Copy link

Issue

The following error is thrown when trying to push notifications from a server:

ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
ApnsPHP[23975]: INFO: Retry to connect (1/3)...
ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
ApnsPHP[23975]: INFO: Retry to connect (2/3)...
ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
ApnsPHP[23975]: INFO: Retry to connect (3/3)...
ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
<br />
<b>Fatal error</b>:  Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)' in /var/www/website/public_html/apn/ApnsPHP/Abstract.php:396
Stack trace:
#0 /var/www/website/public_html/apn/ApnsPHP/Abstract.php(334): ApnsPHP_Abstract-&gt;_connect()
#1 /var/www/website/public_html/apn/push.php(40): ApnsPHP_Abstract-&gt;connect()
#2 {main}
  thrown in <b>/var/www/website/public_html/apn/ApnsPHP/Abstract.php</b> on line <b>396</b><br />

The issue occurs with the default test scripts coming with the library - e.g. sample_push_custom.php.

The same code and certificates are working properly when testing in local environment (OSX 10.8.3). This way all notifications are delivered properly.

Temporary solution

Uncommenting the following code in ApnsPHP/Abstract.php, line 382, makes error disappear and notifications being delivered properly:

'verify_peer' => isset($this->_sRootCertificationAuthorityFile),

Server setup

Ubuntu 12.10, PHP 5.4.6, OpenSSL installed and enabled.
Local machines: OSX 10.8.3 + MAMP, PHP 5.4.10.

Note:

Same issue dating from 2011 has been reported at SO as well:
http://stackoverflow.com/a/6913825/1520477


Let me know if you need any additional details about the server setup.

Thanks!

@ghost
Copy link

ghost commented May 21, 2013

Did you see this issue? #24

@nickmcelligott
Copy link

Had this same issue on a bitnami LAMP stack. Thanks for the fix.

@theoboldt
Copy link

Did you made shure that your pem file contained both a

-----BEGIN CERTIFICATE----- 
...
-----END CERTIFICATE-----

and a

-----BEGIN PRIVATE KEY----- 
...
-----END PRIVATE KEY-----

area?
This fixed the issue for me without skipping peer verification. You should also try to remove the quieting @ from line 392 to get more information about the real problem.

@aramboyajyan
Copy link
Author

Sorry for late response; haven't had time to check this further. The APNs work properly with the fix I posted, so I did not investigate it further.

@theoboldt yes, it does contain starting/closing tags.

@hshhhhh I haven't seen it prior to posting; if you believe the issues are identical, feel free to close this issue.

Thanks!

@ayonliu
Copy link

ayonliu commented Jul 7, 2014

I got the same error.
The error is throw out on line 391~397 in file ApnsPHP/Abstract.php

$this->_hSocket = @stream_socket_client($sURL, $nError, $sError,
            $this->_nConnectTimeout, STREAM_CLIENT_CONNECT, $streamContext);

After i remove the "@" before function stream_socket_client(), i got another error:

stream_socket_client(): Unable to set private key file `.../dev.pem'  

I google a lot and follow every step of this guide, make sure my pem file is generated rightly:
https://code.google.com/p/apns-php/wiki/CertificateCreation

then i run below command to check is the secure link to apns right or not:

 openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-cert.pem -key apns-dev-key.pem -CApath /etc/ssl/certs/Entrust_Root_Certification_Authority.pem 

Press enter and i got this prompt :

Enter pass phrase for apns-dev-key.pem:

then i realize that i forgot set passphrase for cert(it is dev.pem in my case)

// Instantiate a new ApnsPHP_Push object
$this->push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'dev.pem'
);
// Set the Provider Certificate passphrase
$this->push->setProviderCertificatePassphrase($passphrase);
// Set the Root Certificate Autority to verify the Apple remote peer
$this->push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$this->push->connect();
// Instantiate a new Message with a single recipient
$this->message = new ApnsPHP_Message($deviceToken);

set the right passphrase for the apns pem, problem solved.

@triple7
Copy link

triple7 commented Nov 5, 2017

I have this problem as well. I've tried every recommendation.

using
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert VlackCerts.pem -debug -showcerts -CAfile GeoTrust_Global_CA.pem

Provides an ok response.

My 2195 outgoing port is opened on the server. Checked using telnet response is ok.

My php script calls setProviderCertificatePassphrase without a problem

I'm not sure where to look for this anymore. My error log sends me to line 334 on Abstract.php which is:

			$bConnected = $this->_connect();

Which is part of the connect function where:

	$streamContext = stream_context_create(array('ssl' => array(
		'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
		'cafile' => $this->_sRootCertificationAuthorityFile,
		'local_cert' => $this->_sProviderCertificateFile
	)));

Some help greatly appreciated

@ghost
Copy link

ghost commented Nov 5, 2017

Have you tried to comment two lines as it was recomended? #24 (comment)

$streamContext = stream_context_create(array('ssl' => array(
//          'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
//          'cafile' => $this->_sRootCertificationAuthorityFile,
            'local_cert' => $this->_sProviderCertificateFile
        )));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants