在PHP中生成SAN CSR [英] Generating a SAN CSR in PHP

查看:86
本文介绍了在PHP中生成SAN CSR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写脚本,以通过Web界面生成CSR,然后提交以生成证书.我当前的问题是我想生成SAN证书,但是找不到有关如何将subjectAlternateName添加到生成的证书请求中的任何信息.

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.

我当前的代码是:

$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 );

稍后在解析时,向$domain_data数组中添加subjectAlternateName似乎不会向CSR中添加任何内容.

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

是否可以直接在PHP中执行此操作?

Is it possible to do this directly in PHP?

推荐答案

我设法通过生成openssl.cnf文件的临时副本并插入subjectAltName行来解决此问题.然后可以通过设置$config_args['config'] = $temporaryfilepath

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

这篇关于在PHP中生成SAN CSR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆