function TlsHelper::certNameMatcher
Convert certificate name into matching function.
Parameters
string $certName CN/SAN:
1 call to TlsHelper::certNameMatcher()
- TlsHelper::checkCertificateHost in vendor/
composer/ composer/ src/ Composer/ Util/ TlsHelper.php - Match hostname against a certificate.
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ TlsHelper.php, line 172
Class
- TlsHelper
- @author Chris Smith <chris@cs278.org>
Namespace
Composer\UtilCode
private static function certNameMatcher(string $certName) : ?callable {
$wildcards = substr_count($certName, '*');
if (0 === $wildcards) {
// Literal match.
return static function ($hostname) use ($certName) : bool {
return $hostname === $certName;
};
}
if (1 === $wildcards) {
$components = explode('.', $certName);
if (3 > count($components)) {
// Must have 3+ components
return null;
}
$firstComponent = $components[0];
// Wildcard must be the last character.
if ('*' !== $firstComponent[strlen($firstComponent) - 1]) {
return null;
}
$wildcardRegex = preg_quote($certName);
$wildcardRegex = str_replace('\\*', '[a-z0-9-]+', $wildcardRegex);
$wildcardRegex = "{^{$wildcardRegex}\$}";
return static function ($hostname) use ($wildcardRegex) : bool {
return Preg::isMatch($wildcardRegex, $hostname);
};
}
return null;
}