gpt4 book ai didi

php - 如何在 PHP 中将受信任的证书颁发机构列表设置为套接字客户端?

转载 作者:可可西里 更新时间:2023-10-31 22:53:53 25 4
gpt4 key购买 nike

在 IHE Con​​nectathon 的上下文中,我想制作一个响应 ATNA 配置文件的原始套接字服务器,这需要具有两端证书的 TLS 套接字。

如果在此消息中总结我的问题: https://groups.google.com/d/msg/eu_connectathon/O-VGI_3cltw/ARsElA65ZkkJ

编辑:抱歉,Google 网上论坛不公开,消息如下:

Hi Florian,

What exactly does the error message "Server asked for a certificate, but list of issuers doesn't contain valid certificate authority." mean and did the implementation of the TLS Tools Client change during the last years, or am I using the wrong certificates?

该消息表示服务器已发送 CertificateRequest 在 certificate_authorities 中没有值的情况下发送给 clienmt 的消息 字段。

我去年遇到过这个问题并与开发人员讨论过 TLS 工具。他声称如果服务器不包含这个 现场,客户不知道什么样的证书 返回,假设您将连接前多个 亲和域,每个域都有自己的 CA。

看来您可以通过以下方式指示 OpenSSL 返回此值 调用 SSL_CTX_set_client_CA_list,例如在 DcmTLSTransportLayer::addTrustedCertificateFile。我没有测试过这个 还没有使用 TLS 工具,但我希望在 连接马拉松开始。

但我的 PHP 实现与他们的不同。看起来 PHP 缺少“SSL CTX 设置客户端 CA 列表”的可能性,以告诉客户端它应该使用哪个证书颁发机构。

$context = stream_context_create();

if ($certificate) {
// Server certificate + private key
stream_context_set_option($context, 'ssl', 'local_cert', "/path/to/server.pem");
stream_context_set_option($context, 'ssl', 'passphrase', $passphrase);

// Client public certificates
stream_context_set_option($context, 'ssl', 'cafile', "/path/to/ca.pem");

stream_context_set_option($context, 'ssl', 'allow_self_signed', false);
stream_context_set_option($context, 'ssl', 'verify_peer', true);
stream_context_set_option($context, 'ssl', 'peer_name', "TlsTools2");
stream_context_set_option($context, 'ssl', 'capture_peer_cert', true);
stream_context_set_option($context, 'ssl', 'capture_peer_cert_chain', true);
}

$this->__socket = @stream_socket_server("tcp://$address:$port", $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);

IHE Gazelle TLS 客户端告诉我“服务器请求证书,但颁发者列表不包含有效的证书颁发机构。”

客户端和服务器之间的消息通过,但测试不成功,如消息所述“不够安全”。

您看到问题了吗?PHP 是否有更多我没有看到的选项?

感谢您的帮助。

编辑:正如@rdlowrey 建议的那样,我刚刚创建了一个错误报告:https://bugs.php.net/bug.php?id=69215

最佳答案

正如我在最初的评论中提到的:

PHP's stream server implementation has never actually used SSL_CTX_set_client_CA_list() for encrypted streams.

这已在相关错误报告中引用的上游得到更正:

https://bugs.php.net/bug.php?id=69215

此更改将在 PHP 5.6.8 二进制文件发布后反射(reflect)出来(或者您可以在该版本发布之前针对当前源手动构建 PHP)。

实现

使用更新的二进制文件,OP 的示例代码无需修改即可按预期工作。在服务器中使用的加密上下文的一个简单示例:

<?php
$serverCtx = stream_context_create(['ssl' => [
'local_cert' => '/path/to/my-server-cert.pem',
'passphrase' => 'elephpant',
'cafile' => '/path/to/my-ca-certs.pem',
'verify_peer' => true
]]);

在上面的示例中,当作为 TLS 握手的一部分发送客户端 CA 列表时,PHP 自动使用在上面引用的 my-ca-certs.pem 文件中找到的证书的名称。

注意事项

当通过 "verify_peer"=> true 在加密服务器流中启用对等验证时,PHP 不会自动启用对等名称验证。除非您只希望允许单个证书持有者(具有特定的已知名称)访问您的服务器,否则这正是您想要的。此默认行为支持更常见的用例,即允许其证书由受信任的 CA 签名的任何客户端建立与您的服务器的连接。但是,如果您希望在加密服务器中强制执行名称验证,请修改上面的上下文示例,如下所示:

<?php
$serverCtx = stream_context_create(['ssl' => [
'local_cert' => '/path/to/my-server-cert.pem',
'passphrase' => 'elephpant',
'cafile' => '/path/to/my-ca-certs.pem',
'verify_peer' => true,
'verify_peer_name' => true, // verify the name on the cert
'peer_name' => 'zanzibar' // ensure the cert's name matches this
]]);

关于php - 如何在 PHP 中将受信任的证书颁发机构列表设置为套接字客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28696886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com