PHP 和 SSL:如何检索远程站点证书的“详细”验证结果


PHP and SSL: How can I retrieve "detailed" validation results for remote site's certificate?

我正在尝试验证远程站点的SSL证书。 curl 可以给出通用的成功或失败指示,但没有详细信息。我的客户需要有关证书失败原因的详细信息:错误的域、吊销或过期的证书、不受信任的 CA 等。

curl_error($ch) 在证书上的主机名错误时返回正确的错误。 但是,如果证书已过期或吊销,它不会返回任何信息,而是返回不正确"Peer certificate cannot be authenticated with known CA certificates"

如何使用 PHP 获取远程站点证书无效/不受信任的确切原因?

看起来 Curl 不能做到这一点。

为了获得有效期,我使用了这个答案

并补充说:

    $cert_info = openssl_x509_parse($cont["options"]["ssl"]["peer_certificate"]);
    if($cert_info['validFrom_time_t'] < time() < $cert_info['validTo_time_t']) {
        //Certificate is CURRENT!
    } else {
        //Certificate is Expired or not yet valid
    }