Skip to content

Commit

Permalink
Merge pull request #204 from Icinga/fix-split-sans
Browse files Browse the repository at this point in the history
CertificateUtils: Split also unknow cert alt names correctly
  • Loading branch information
yhabteab authored Sep 4, 2023
2 parents c2cce53 + a1148f3 commit fa4f719
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions library/X509/CertificateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,16 @@ public static function splitSANs(?string $sanStr): array
{
$sans = [];
foreach (Str::trimSplit($sanStr) as $altName) {
[$k, $v] = Str::trimSplit($altName, ':');
if (strpos($altName, ':') === false) {
[$k, $v] = Str::trimSplit($altName, '=', 2);
} else {
[$k, $v] = Str::trimSplit($altName, ':', 2);
}

$sans[$k][] = $v;
}

$order = array_flip(['DNS', 'URI', 'IP Address', 'email']);
$order = array_flip(['DNS', 'URI', 'IP Address', 'email', 'DirName']);
uksort($sans, function ($a, $b) use ($order) {
return ($order[$a] ?? PHP_INT_MAX) <=> ($order[$b] ?? PHP_INT_MAX);
});
Expand Down

0 comments on commit fa4f719

Please sign in to comment.