Created
June 21, 2023 07:17
-
-
Save md-riaz/19a07b285fd9a991d43bf41b54f6a389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_sans_from_csr($csr) { | |
$tempFile = tempnam(sys_get_temp_dir(), 'csr'); | |
file_put_contents($tempFile, $csr); | |
$opensslCsrOutput = shell_exec("openssl req -noout -text -in " . escapeshellarg($tempFile)); | |
unlink($tempFile); | |
if ($opensslCsrOutput !== null) { | |
$matches = []; | |
preg_match('/Subject Alternative Name:\s*(.*)/', $opensslCsrOutput, $matches); | |
if (!empty($matches[1])) { | |
$sans = []; | |
$sanValues = explode(', ', $matches[1]); | |
foreach ($sanValues as $value) { | |
$san = trim(str_replace(['DNS:', 'IP:'], '', $value)); | |
$sans[] = $san; | |
} | |
return $sans; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment