【问题标题】:PHP 7.3 SoapClient stream_context (verify_peer) IgnoredPHP 7.3 SoapClient stream_context (verify_peer) 被忽略
【发布时间】:2019-11-26 18:11:35
【问题描述】:

我正在从 PHP 5.6 升级到 PHP 7.3,似乎 PHP 7.3 中的 SoapClient 忽略了 ssl verify_peer 选项。

在 PHP 5.6 中,以下代码按原样执行:

$opts = [
    'ssl' => [
        'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT,
        'verify_peer' => false,
    ],
];
$stream_context = stream_context_create($opts);
$options = [
    'stream_context' => $stream_context,
];
$client = new SoapClient("https://...?wsdl", $options);
$client->SomeMethod();

在 PHP 7.3 中执行相同的代码会导致 PHP Fatal Error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://...?wsdl' : failed to load external entity "https://...?wsdl"

我尝试在$opts 中包含verify_peer_name => falseallow_self_signed => true(尽管证书不是自签名的——只是没有由运行代码的机器上的任何受信任的证书签名)。我还尝试将cafile(.pem 格式)用于签署远程证书的根 CA,以及整个证书链(.pem 格式)。此外,我尝试包含 capath 选项,指向我保存根 CA 以及证书链的目录。

如果我尝试通过提供 urilocation 来绕过下载 wsdl,我会收到错误 PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in...

到目前为止,我还没有发现 5.6 和 7.3 之间的差异可以解释我所看到的行为差异。

【问题讨论】:

    标签: php ssl soap soap-client php-7.3


    【解决方案1】:

    在这方面花费了太多时间之后,看起来 PHP 7 确实尊重了 stream_context verify_peer 选项。问题的根源在于,协商连接时使用的“默认”密码在 PHP 5.6 和 PHP 7.3 之间发生了变化。显式调用要使用的密码允许 SoapClient 在 PHP 7.3.7 中进行通信。

    $opts = [
        'ssl' => [
            'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT,
            'verify_peer' => false,
            'ciphers' => 'RC4-SHA',
        ],
    ];
    $stream_context = stream_context_create($opts);
    $options = [
        'stream_context' => $stream_context,
    ];
    $client = new SoapClient("https://...?wsdl", $options);
    $client->SomeMethod();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 2011-12-28
      • 2023-03-18
      相关资源
      最近更新 更多