php / php/php-src

check_cert() insists on all provided certificates to validate against system CA store

未关闭
#8,371 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Extension: openssl Feature
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

The following code:

php -r  "var_dump(openssl_x509_checkpurpose(file_get_contents('v_crt.pem'), X509_PURPOSE_SSL_SERVER, array('v_ca.pem')));"

Resulted in this output:

bool(false)

But I expected this output instead:

bool(true)

where v_cert.pem contains any letsencrypt issued certificate, v_ca.pem contains two intermediate certs (it's default chain from letsencrypt):
a)
Issuer: C = US, O = Internet Security Research Group, CN = ISRG Root X1
Subject: C = US, O = Let's Encrypt, CN = R3
b)
Issuer: O = Digital Signature Trust Co., CN = DST Root CA X3
Subject: C = US, O = Internet Security Research Group, CN = ISRG Root X1

b) is issued by "DST Root CA X3" which is already expired certificate [1] that (this is important) no longer exists in local (system wide) ca-certificates store (verify that on your ca-certificates store).

openssl_x509_checkpurpose() uses check_cert() which calls X509_verify_cert().

Behaviour of this is all intermediate certs need to validate agains system ca store otherwise check fails. It will fail EVEN if we have one chain path that validates agains our ca system store.

Impact of this is that perfectly valid certificate chains are considered to be not ok for any purpose.

There is a flag that changes this bahaviour to say "ok" when at least single validated chain is found - X509_V_FLAG_PARTIAL_CHAIN. It makes logic sense for what openssl_x509_checkpurpose() is trying to do.

Some other users of this flag:
https://github.com/curl/curl/pull/4655
https://github.com/curl/curl/pull/4655/commits/146ccff7a7c9cdc5bfc9d4f2076a9e57a03c1eb8
https://github.com/noxxi/p5-io-socket-ssl/blob/master/lib/IO/Socket/SSL.pm#L2475

  1. https://community.letsencrypt.org/t/production-chain-changes/150739/3
PHP Version

PHP 8.1.4

Operating System

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

复现 issue 中的 PHP 命令,然后跟踪 openssl_x509_checkpurpose() 经过 check_cert() 到 X509_verify_cert()。将当前的验证行为与 X509_V_FLAG_PARTIAL_CHAIN 进行比较,并确认有效的备用链在不包含过期证书的情况下能够成功;在验证结果之前,为此证书链场景添加或更新覆盖测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, php
领域
cryptography, security
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。