PHP SoapClient SSL: Failed to load external entity (certificate not loaded)

11,423

Try converting your certificate from .p12 to .pem using

openssl pkcs12 -in certfile.p12 -out certfile.pem -nodes -clcerts
Share:
11,423
BonifatiusK
Author by

BonifatiusK

Updated on June 05, 2022

Comments

  • BonifatiusK
    BonifatiusK almost 2 years

    I am connecting to a WSDL which needs a SSL file. I created this php script to connect to the SOAP API:

    $url = "https://www.testsoap.nl/api/soap?wsdl";
    
    $soapArr = array(
        "soap_version"=>SOAP_1_1,
        "trace"=>true,
        "exceptions"=>true,
        "local_cert"=>"certfile.p12",
        "passphrase"=>"passwordhere"
    );
    
    $client = new SoapClient($url, $soapArr);
    

    Now when I try to connect to I will see this error in my error log: [Fri Jan 10 11:08:21 2014] [error] [client 172.21.1.131] PHP Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://www.testsoap.nl/api/soap?wsdl' : failed to load external entity "https://www.testsoap.nl/api/soap?wsdl"\n in /var/www/index.php:39\nStack trace:\n#0 /var/www/index.php(39): SoapClient->SoapClient('https://www.tes...', Array)\n#1 {main}\n thrown in /var/www/index.php on line 39

    Line 39 = $client = new SoapClient($url, $soapArr);

    I also tried these array options, they did not change anything however:

    $soapArr = array(
        "style"=>SOAP_DOCUMENT,
        "use"=>SOAP_LITERAL,
        "soap_version"=>SOAP_1_1,
        "trace"=>true,
        "authentication"=>SOAP_AUTHENTICATION_DIGEST,
        "exceptions"=>true,
        "local_cert"=>"certfile.p12",
        "passphrase"=>"passwordhere",
        "ssl_method"=>SOAP_SSL_METHOD_TLS
    );
    

    Some things to consider:

    • I can install this SSL cert file in my browser and connect to the API without any problem.

    • When using soapUI (with this the password and the certificate) I can also connect to the API

    • openssl is installed on my debian server

    • the debianserver can connect to the internet

    • php-soap is installed on the debian server

    I did some more testing and found out that I get the same errors when I do not use any certificate like this:

    $client = new SoapClient($url);
    

    So I must assume the certificate is not loaded like I would expect.

    I found this bug: https://bugs.php.net/bug.php?id=27777 And here: http://www.php.net/manual/en/soapclient.soapclient.php#83474 Somebody says this also counts for the SSL certificates.

    However, reading this information and the possible solution, I am still not any further...

    Any help would be much appreciated. Thanks in advance!