PHP secure connection with WSDL service breaks after server renewed certificate

北城以北 提交于 2019-12-25 09:17:01

问题


The new certificate is "Symantec Class 3 EV SSL CA - G3". The client has CentOS. There is no control over the server, it is third party. When the WDSL https address is loaded in Firefox and Chrome, both browsers show "Secure connection", no problem.

The WSDL address is https://palena.sii.cl/DTEWS/CrSeed.jws?WSDL

Test code:

$success = false;
$attempts = 0;

while (($success === false) && ($attempts < 10)) {
    $attempts ++;
    echo 'Attempt ' . $attempts . '<br>';

    try {
        $wsdl = 'https://palena.sii.cl/DTEWS/CrSeed.jws?WSDL';
        $entity_loader_status_old = libxml_disable_entity_loader(false);
        $SoapClient = new SoapClient($wsdl);
        $seed = $SoapClient -> getSeed();
        libxml_disable_entity_loader($entity_loader_status_old);
        $success = true;
    } catch (Exception $Exception) {
        echo $Exception -> getMessage() . '<br>';
    }
}

if ($success === true) {
    echo 'SUCCESS';
} else {
    echo 'ERROR';
}

The connection is secure by default, because the PHP version is 5.6.22 (more than 5.5.x).


回答1:


Possible duplicate: OpenSSL: unable to verify the first certificate for Experian URL

To solve create a cafile.pem and concatenate the required Symantec certificates (primary intermediate and root) as shown in the possible duplicate question link above (see spuder's answer).

The cafile.pem to create as quoted from spuder:

-----BEGIN CERTIFICATE----- 
(Your Primary SSL certificate: your_domain_name.crt) 
-----END CERTIFICATE----- 
-----BEGIN CERTIFICATE----- 
(Your Intermediate certificate: DigiCertCA.crt) 
-----END CERTIFICATE----- 
-----BEGIN CERTIFICATE----- 
(Your Root certificate: TrustedRoot.crt) 
-----END CERTIFICATE-----

Then in PHP use the next $options for creating the SoapClient object:

$options = [
    'stream_context' => stream_context_create([
        'ssl' => [
            'cafile' => __DIR__ . '/cafile.pem',
        ],
    ]),
];

$SoapClient = new SoapClient($wsdl, $options);


来源:https://stackoverflow.com/questions/41175867/php-secure-connection-with-wsdl-service-breaks-after-server-renewed-certificate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!