I'm currently using the following code to generate CSRs with subjectAltName
for additional domains.
$domains = ["example.com", "www.example.com"];
$san = implode(",", array_map(function ($dns) {
return "DNS:" . $dns;
}, $domains));
$csr = openssl_csr_new([
"CN" => reset($domains),
"ST" => "Germany",
"C" => "DE",
"O" => "Unknown",
"subjectAltName" => $san,
], $privateKey, [
"digest_alg" => "sha256",
"req_extensions" => "v3_req",
]);
But when I use openssl req -text -noout -verify -in csr.pem
to verify the generated CSR, the subjectAltName
is not listed under the Requested Extensions
section. Instead, subjectAltName
is added to the subject.
subjectAltName
is recognized in the first array, other arbitrary values result in an error. But how can I create a CSR in PHP with OpenSSL that really includes the subjectAltName
as requested extension?
This question is specifically about the bundled openssl_*
functions, not any third party library like phpseclib
.