function TlsHelper::checkCertificateHost
Match hostname against a certificate.
Parameters
mixed $certificate X.509 certificate:
string $hostname Hostname in the URL:
string $cn Set to the common name of the certificate iff match found:
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ TlsHelper.php, line 31
Class
- TlsHelper
- @author Chris Smith <chris@cs278.org>
Namespace
Composer\UtilCode
public static function checkCertificateHost($certificate, string $hostname, ?string &$cn = null) : bool {
$names = self::getCertificateNames($certificate);
if (empty($names)) {
return false;
}
$combinedNames = array_merge($names['san'], [
$names['cn'],
]);
$hostname = strtolower($hostname);
foreach ($combinedNames as $certName) {
$matcher = self::certNameMatcher($certName);
if ($matcher && $matcher($hostname)) {
$cn = $names['cn'];
return true;
}
}
return false;
}