Unable to Connect to ssl - php

I have configured the openssl with wamp (Apache server). But while I using gdata api I'm getting following error.
( ! ) Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message ' in C:\Zend_1_11_11\library\Zend\Http\Client\Adapter\Socket.php on line 234
( ! ) Zend_Http_Client_Adapter_Exception: Unable to Connect to ssl://accounts.google.com:443. Error #10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Zend_1_11_11\library\Zend\Http\Client\Adapter\Socket.php on line 234
Somebody help me on this...

Solution only for Windows users:
Check the SSL module is enabled in php.ini:
extension=php_openssl.dll

Answer from Mikhail does not work for me as I run it in Alpine Linux and .dll is only windows extension. Do not use it outside of Windows, it only adds warnings.
Solved my problem:
I had a self-signed certificate that was unable to establish connection.
To check that it is problem you can make a request:
wget way:
// not working:
wget https://accounts.google.com:443
// working:
wget https://accounts.google.com:443 --no-check-certificate
or curl way:
// not working:
curl https://accounts.google.com:443
// working:
curl https://accounts.google.com:443 -k
To temporary solve it in my dev docker container, I have added use of curl adapter and no check for certificate to the code:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false]
);
$client = new Zend_Http_Client('https://example.com', $config);

You are behind proxy, so you can not connect directly.Try to use Zend/Http/Client/Adapter/Proxy.php instead of Zend\Http\Client\Adapter\Socket.php

If you on Ubuntu try add in your php.ini
openssl.capath=/etc/ssl/certs
For more info read this issue

Related

Curl failed: NSS: client certificate not found (nickname not specified) - On Centos 7

I know this has been asked on SO before but I think my situation is a little bit different:
When I'm trying to use curl inside PHP I receive the following error when trying to interact with apples push notification service (https://api.push.apple.com/3/device/)
Curl failed: NSS: client certificate not found (nickname not specified)
This is due to the fact that on centos, php is build with curl that uses NSS instead OpenSSL.
What I tried so far:
Recompiling curl (worked! Binary is able to perform the call, but php is not)
Recompiling php (didnt work, as it requires curl-devel to be installed, which might link to NSS again)
So my next approach is to fix this NSS problem, but it turns out NSS is a very bad piece of software as just a simple rename of an imported lets-ecnrypt certificate doesnt work.. ..
Could someone please explain me how I could fix this? I already tried importing a lets encrypt certificate into the NSS database stored in /etc/pki/nssdb, that worked - but unfortunately the certificate is not recognized in PHP, even if I provide its nickname in CURLOPT_SSLCERT => 'nickname'.
Maybe this is because it has special characters inside its nickname which i cannot change as NSS fails to rename (lol).
When I directly try to provide certificates in php using
CURLOPT_SSLCERT => $certFile,
CURLOPT_SSLKEY => $keyFile,
CURLOPT_CAINFO => $caCertFile
I get:
Curl failed: Peer's Certificate issuer is not recognized.
I also turned of peer verification by
CURLOPT_SSL_VERIFYPEER => FALSE
ending in
Curl failed: security library failure
Is there anybody out there who could teach me how to fix it or how to build php on centos with builting curl using openssl?
BR,
Finally I got this working, here is what I did:
Recompiled curl with openssl and put the libcurl.so.4 in a new folder /home/mylibs/
Copied all libs from /usr/lib to /home/mylibs/ while not replacing my libcurl.so.4
Located the system's php-cgi binary, renamed it to php-cgi-real
Created a blank file php-cgi
#! /bin/bash
export LD_PRELOAD=/home/mylibs/libcurl.so.4
exec php-cgi-real "$#"
Restarted the service
Done!

SoapServer::SoapServer(): SSL operation failed with code 1

i have exposed a couple of web services through Yii. After upgrading to PHP 5.6.33 from PHP 5.5.x, i face the following error
SoapServer::SoapServer(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
the error occurs on line 166 on framework/web/services/CWebService.php (1.1.19) so far i haven't found any work around, the options property is protected and don't know how to bypass this issue, but still http://php.net/manual/en/soapserver.soapserver.php doesn't seem to support same options as SoapClient
$options["stream_context"] = stream_context_create([
"ssl" => [
// set some SSL/TLS specific options
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
]]);
We ended up that it was a server configuration issue. The production servers didn't faced this issue since the certificate was signed from a known authority however in the private servers, we needed to edit the php.ini file
openssl.cafile = "/etc/path/to/pem/file.pem"
I got the error too on Linux (Ubuntu) with PHP7.2 when I tried to create SoapServer in my development environment.
If you do not want to set the PHP openssl.cafile globally, just copy your Root CA into the correct folder and update certificates:
sudo cp my_root_ca.pem /usr/share/ca-certificates/my_root_ca.crt
sudo dpkg-reconfigure ca-certificates
sudo update-ca-certificates
While reconfigure ca-certificates you need to select your own certificate and activate it.
(If you do not need your Root CA anymore in your develop environment just reconfigure certificates again, unselect your CA from the list and finally update certificates.)

PHP AWS HTTP error: Unable to open using mode r+ fopen

I have been transferring my PHP server files from windows to ubuntu 14.04 and my script broke...
I'm getting the error when downloading from S3.
$result = $s3->getObject(array(
'Bucket' => AWS_S3_BUCKET,
'Key' => $imgName,
'SaveAs' => $targetPath
)); //the exception is thrown!
The exception message:
Error executing GetObject on http://s3.amazonaws.com/bucket/file AWS
HTTP error: Unable to open ../../downloads/file using mode r+:
fopen(../../downloads/file).
sudo chmod -R 777 wwwfolder didn't work
Any ideas?
** Update **
Found a Hax/Workaround.... adding touch($targetPath) before $s3->getObject method fixes the problem... but why? I tried on different ubuntu server (same version) and there it works (without touch; and i don't know how it was configured..).
What about now? Any ideas?

PHP Error Class 'SoapClient' not found

I was trying to install Wordpress on our server to test, but in order to do that I had to upgrade our current PHP version to 5.3. I upgraded our PHP and I am now finding that our Purolator shipping module is no longer working. According to our host support the "purolator.php" file is missing data that the new version of PHP requires. Unfortunately, I can't revert our PHP version back and our programmer is away.
This is the error message I was able to get from our website host support team:
tail /var/www/vhosts/phantomcables.com/statistics/logs/error_log -f
[Thu Jul 19 08:34:28 2012] [error] [client 70.51.168.201] PHP Fatal
error: Class 'SoapClient' not found in
/var/www/vhosts/phantomcables.com/httpdocs/shippings/purolator.php on line
49, referer: https://phantomcables.com/index.php?dispatch=checkout.cart
These are lines 40 to 72:
function createPWSSOAPClient()
{
/** Purpose : Creates a SOAP Client in Non-WSDL mode with the appropriate authentication and
* header information
**/
//Set the parameters for the Non-WSDL mode SOAP communication with your Development/Production credentials
//echo DIR_SHIPPING_FILES."estimatingservice.wsdl";
$url = "https://webservices.purolator.com/PWS/V1/Estimating/EstimatingService.asmx";
$client = new SoapClient( DIR_SHIPPING_FILES."estimatingservice.wsdl",
array (
'trace' => true,
'location' => $url,
'uri' => "http://purolator.com/pws/datatypes/v1",
'login' => PRODUCTION_KEY,
'password' => PRODUCTION_PASS
)
);
//Define the SOAP Envelope Headers
$headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1', 'RequestContext',
array (
'Version' => '1.0',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Rating Example'
)
);
//Apply the SOAP Header to your client
$client->__setSoapHeaders($headers);
return $client;
}
Any help would be greatly appreciated.
It seems like you did not have installed the php-soap package on your server.
Type
phpinfo();
in your code and check if 'Soap Client' is 'enabled'.
If not, I don't know your distribution and package manager, but here is the code for Fedora I use:
$ yum install php-soap
I suggest to do it with your programmer back or a sys admin by your sides, you never know what could happen. A backup is also useful before any installation!
You will need to add (or remove any comment characters before)
extension=soap.so
to your php.ini file, and then restart the web server.
If you are having trouble finding your php.ini file, create a page with the following:
<?php phpinfo();
and load that file in your browser.
On some systems, this setting may not actually live in php.ini. For example, if you are using Zend Server, the setting would live in /usr/local/zend/etc/conf.d/soap.ini.
So we reverted back to an older version of PHP, and re-enabled SOAP. apparently that was the issue, not sure why that didn't work with the newer version of PHP.
Again thank you for all of your help. This is a great community.
It is already posted here
Do the following:
Locate php.ini in your apache bin folder, I.e Apache/bin/php.ini
Remove the ; from the beginning of extension=php_soap.dll
Restart your Apache server
Look up your phpinfo(); again and check if you see a similar picture to the one above
If you do, problem solved!
Enable the SOAP extension, require it in your composer.json like so:
{
"require": {
"ext-soap": "*"
}
}

Access SoapClient and file_get_contents from local LAMP

I'm working under ubuntu 12.04.
I have a classic localhost set up . apache + mysql + php
file_get_contents fail on external url but works well with local file or 'localhost'
file_get_contents('http://google.com');
PHP Warning: file_get_contents(http://google.com): failed to open stream: HTTP request failed!
soapClient fail on external url but works well with local file or 'localhost'
$wsdl = "http://test.webservices.delijn.be/wsrise/services/travel/WEB-INF/wsdl/RiseWebservices.wsdl";
$client = new SoapClient($wsdl,
array(
'trace' => true,
'exceptions' => true,
'soap_version' => SOAP_1_1,
'connection_timeout' => 600,
'compression' => SOAP_COMPRESSION_ACCEPT ,
'encoding'=> 'UTF-8', //ISO-8859-1',
//'cache_wsdl' => WSDL_CACHE_BOTH,
//'host' => "localhost",
//'proxy_host' => "localhost",
//'proxy_port' => 8080,
));
SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://test.webservices.delijn.be/wsrise/services/travel/WEB-INF/wsdl/RiseWebservices.wsdl' : failed to load external entity "http://test.webservices.delijn.be/wsrise/services/travel/WEB-INF/wsdl/RiseWebservices.wsdl"
allow_url_fopen and allow_include_url are on in phpinfo() (set in /etc/php5/apache2/php.ini)
firewall is disabled
apparmor is disabled
suhosin patch is installed and i set suhosin.simulation to true in the php.ini
the code is working well on my production and staging servers
I 'm out of ideas and don't find intresting log or command that can inspect the problem :'(
Thanks for your help !
Ok ! I found a way to make it work.
install de suhosin-php package in order to be able to use the Module suhosin.
set the suhosin.simulation directive to on in /etc/php5/con.d/suhosin.conf
sudo service apache2 restart
Soap calls are still extremely slow, but are working now
Thanks for your help !

Categories