Generating a SAN CSR in PHP

余生长醉 提交于 2019-12-14 04:19:43

问题


I am currently writing a script to generate CSRs through a web interface for submission to generate a certificate. My current issue is that I want to generate a SAN certificate but I can't find any information on how to add the subjectAlternateName into the generated certificate request.

My current code is:

$private_key = openssl_pkey_new( array( 'private_key_bits' => 2048 ) );
$domain_data = [
    "countryName"            => 'GB',
    "stateOrProvinceName"    => 'Countyname',
    "localityName"           => 'townname',
    "organizationName"       => 'Company ltd.',
    "organizationalUnitName" => "IT",
    "emailAddress"           => 'IT@example.com',
    "commonName"             => 'example.com',
];
$config_args = ['private_key_bits' => 2048];
$attributes = [];

$csr = openssl_csr_new( $domain_data, $private_key, $config_args, $attributes );

openssl_csr_export( $csr, $csr_out );

Adding subjectAlternateName into the $domain_data array doesn't appear to add anything into the CSR when I parse it later.

Is it possible to do this directly in PHP?


回答1:


I have managed to solve this by generating a temporary copy of my openssl.cnf file with the subjectAltName line injected into it. This config can then be loaded by setting $config_args['config'] = $temporaryfilepath



来源:https://stackoverflow.com/questions/33755758/generating-a-san-csr-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!