首页 > 解决方案 > 即使提供了匹配的证书,PHP SoapClient 也无法验证_peer

问题描述

我有一个php:8.0.7-apache码头集装箱。

我正在尝试通过verify_peer以下设置为我的 SoapClient 使用 ssl 流上下文中的选项:

$stream = stream_context_create([
    'ssl' => [
        'verify_peer' => true,
        'cafile' => '/var/www/html/path/to/certificate.pem.crt',
        'verify_peer_name' => false,
        'verify_host' => false,
        'allow_self_signed' => true
    ]
]);

$options = [
    'trace' => true,
    'cache_wsdl' => WSDL_CACHE_NONE,
    'exceptions' => true,
    'location' => 'https://server.com/endpoint',
    'classmap' => $this->getClassMap(),
    'stream_context' => $stream,
    'features' => SOAP_SINGLE_ELEMENT_ARRAYS
];

我已经通过该选项查看了端点正在使用的证书,并确保它与 SHA256 与我在此命令输出'capture_peer_cert' => true的选项中放入的证书文件相匹配:cafile

openssl x509 -noout -fingerporint -sha256 -inform pem -in certificate.pem.crt

/usr/local/share/ca-certificates/我已尝试根据此问题将“cafile”添加到 docker

我尝试添加一个符号链接'cafile'/etc/ssl/certs/[FILE_HASH].0哪里[FILE_HASH]是输出,openssl x509 -hash -noout -in certificate.pem.crt然后使用'capath'选项设置为/etc/ssl/certs

我也尝试将证书安装/导入到 Windows。

openssl 在我的 php 环境中启用(extension_loaded('openssl')输出true

然而,每当'verify_peer' => true我得到以下 SoapFault 时:

  +"faultstring": "Could not connect to host"
  +"faultcode": "HTTP"

但是当我有以下流上下文时,它可以正常工作:

$stream = stream_context_create([
    'ssl' => [
        'verify_peer' => false
    ]
]);
HTTP/1.0 200 OK
X-Backside-Transport: OK OK
Date: Mon, 30 Aug 2021 02:00:00 GMT
X-Powered-By: Servlet/3.0
Set-Cookie: JSESSIONID=*************************************; Path=/; HttpOnly
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"
Content-Type: text/xml
Content-Language: en-US
Connection: Keep-Alive
Content-Length: ****

我不知道还能尝试什么:(

标签: phpdockerhttpsssl-certificatesoap-client

解决方案


推荐阅读