嗨,
经过大量的反复试验后读取证书数据以显示信息。我的用例是google.nl以读取带有链的证书。
我当前的问题是Google域名对不同subjectAltNames的不同方案之间的区别。我不想修复的代码是读取与浏览器在我请求的每个网站上显示的证书信息详细信息相同的证书信息。
我当前的测试代码:
<?php
$url = "https://www.google.nl";
$orignal_parse = parse_url($url, PHP_URL_HOST);
$get = stream_context_create([
"ssl" => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => true,
'disable_compression' => true
]
]);
$read = stream_socket_client("ssl://".$orignal_parse.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
echo '<pre>';
print_r($certinfo);
上面代码中subjectAltNames的结果是;
[subjectAltName] => DNS: .google.com,DNS: .android.com,DNS: .appengine.google.com,DNS: .cloud。 google.com,DNS: .db833953.google.cn,DNS: .g.co,DNS: .gcp.gvt2.com,DNS: .ggpht.cn, DNS: .google-analytics.com,DNS: .google.ca,DNS: .google.cl,DNS: .google.co.in,DNS: .google.co.jp,DNS: .google.co.uk,DNS: .google.com.ar,DNS: .google.com.au,DNS: .google.com.br,DNS: .google.com.co,DNS: .google.com.mx,DNS: .google.com.tr,DNS: .google.com.vn,DNS: .google.de,DNS: .google.es,DNS: .google.fr,DNS: .google.hu, DNS: .google.it,DNS: .google.nl,DNS: .google.pl,DNS: .google.pt,DNS: .googleadapis .com,DNS: .googleapis.cn,DNS: .googlecommerce.com,DNS: .googlevideo.com,DNS: .gstatic.cn,DNS: .gstatic.com,DNS: .gstaticcnapps.cn,DNS: .gvt1.com,DNS: .gvt2.com,DNS: .metric.gstatic.com,DNS : .urchin.com,DNS: .url.google.com,DNS: .you tube-nocookie.com,DNS: .youtube.com,DNS: .youtubeeducation.com,DNS: .yt.be,DNS: .ytimg.com,DNS: android.clients.google.com,DNS:android.com,DNS:developer.android.google.cn,DNS:developers.android.google.cn,DNS:g.co,DNS:ggpht.cn,DNS:goo。 gl,DNS:google-analytics.com,DNS:google.com,DNS:googlecommerce.com,DNS:source.android.google.cn,DNS:urchin.com,DNS:www.goo.gl,DNS:youtu。 be,DNS:youtube.com,DNS:youtubeeducation.com,DNS:yt.be
如果将$ url更改为https://google.nl,则subjectAltNames的结果将更改为;
[subjectAltName] => DNS:*。google.nl,DNS:google.nl
我想得到的正确结果与单击证书信息详细信息时显示的浏览器信息相同。
在Safari浏览器中的OSX上,您会看到第一个结果的列表。
谢谢!