Requests_SSL::verify_certificate()
最后更新于:2021-11-26 04:05:46
Requests_SSL::verify_certificate( string$host, array$cert)Verify the certificate against common name and subject alternative names
参数
- $host
-
(string) (Required) Host name to verify against
- $cert
-
(array) (Required) Certificate data from openssl_x509_parse()
响应
(bool)
源文件
文件: gc-includes/Requests/SSL.php
public static function verify_certificate($host, $cert) {
$has_dns_alt = false;
// Check the subjectAltName
if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) {
$altnames = explode(',', $cert['extensions']['subjectAltName']);
foreach ($altnames as $altname) {
$altname = trim($altname);
if (strpos($altname, 'DNS:') !== 0) {
continue;
}
$has_dns_alt = true;
// Strip the 'DNS:' prefix and trim whitespace
$altname = trim(substr($altname, 4));
// Check for a match
if (self::match_domain($host, $altname) === true) {
return true;
}
}
}
// Fall back to checking the common name if we didn't get any dNSName
// alt names, as per RFC2818
if (!$has_dns_alt && !empty($cert['subject']['CN'])) {
// Check for a match
if (self::match_domain($host, $cert['subject']['CN']) === true) {
return true;
}
}
return false;
}