check_cert() and php_openssl_store_errors do not pick up validation errors
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
var_dump(openssl_x509_checkpurpose(file_get_contents('a.pem'), X509_PURPOSE_SSL_SERVER));
while ($msg = openssl_error_string())
echo $msg . "<br />\n";"
where a.pem is
wget https://raw.githubusercontent.com/fuzyll/defcon-vm/master/extras/hfd/server.pem -O a.pem
(or any other single certificate file that won't validate; without intermediates etc)
Resulted in this output:
$ php x.php
bool(false)
But I expected this output instead:
$ php x.php
bool(false)
error: certificate chain too long (depth 0)
(or similar error message).
Why this doesn't work currently? Because X509_verify_cert() in check_cert() validation errors need to be picked up by
error = X509_STORE_CTX_get_error(csc)
X509_verify_cert_error_string(error)
X509_STORE_CTX_get_error_depth(csc)
which is not done in php ext/openssl internals.
PHP Version
PHP 8.1.4
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the ext/openssl internals around check_cert() and php_openssl_store_errors(), then trace the X509_verify_cert() error path described in the issue. Run the supplied PHP reproduction with a.pem; the work is done when validation errors are exposed through openssl_error_string() alongside the false result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100