OpenSSL:如何使用交互式请求的主题替代名称(SAN)生成CSR?

我希望configurationOpenSSL,以便在运行openssl req -new生成新的证书签名请求时,系统会提示我在CSR上包含任何可选主题名称。

我已经将这行添加到了我的openssl.cnf[req_attributes]部分:

 subjectAltName = Alternative subject names 

这产生了所需的效果,现在我在生成CSR时提示您使用SAN:

 $ openssl req -new -out test.csr -key ./test.key <<< You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [US]: State or Province Name (full name) [New York]: Locality Name (eg, city) []: Organization Name (eg, company) [Example Co]: Organizational Unit Name (eg, section) []: Common Name (eg server FQDN or YOUR name) []:test.example.com Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Alternative subject names []:DNS:alt1.example.com 

在上面的例子中,当提示inputSAN时,我input了DNS:alt1.example.com

问题是由此产生的企业社会责任似乎没有很好的格式:

 $ openssl req -text -in ./test.csr Certificate Request: Data: Version: 0 (0x0) Subject: C=US, ST=New York, O=The Banes, CN=test.thebanes.org Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (2048 bit) Modulus: [...] Exponent: 65537 (0x10001) Attributes: X509v3 Subject Alternative Name:unable to print attribute 

OpenSSL抱怨无法打印“主题备用名称”属性的值。 从网上的例子(人们将SAN硬编码到openssl.cnf中,而不是像我想要的那样交互式地提示它们),我希望看到这个:

  Attributes: X509v3 Subject Alternative Name: DNS:alt1.example.com 

那么,如何通过交互式提示的SAN产生一个格式良好的CSR呢?

我已经与这个小块头自己… …什么是皮塔!

我的解决scheme:我把所有的openssl.cnf文件移动到一个模板工具包文件,只留下了无片作为替代件,然后包裹一个perl脚本。

perl脚本提示inputSAN条目,然后将它们插入到模板中,将模板保存到临时文件,然后使用指向临时文件的-config选项调用openssl req。 CSR生成后,放弃临时文件。

你也可以看看: http : //www.openssl.org/docs/apps/config.html

还有其他人在执行之前覆盖$ ENV,并将调用openssl req包装在perl或shell中,并以稍微高效的方式完成相同的操作: http : //blog.loftninjas.org/2008/11/11/configuration-SSL-请求与-的SubjectAltName与- OpenSSL的/

这个“subjectAltName”不应该在这个部分:attributes = req_attributes。 但是在req_extensions =的部分(可以任意调用它)。

并不需要所有的BS像

 subjectAltName = Alternative subject names subjectAltName_default = DNS:www.g00gle.com 

只要input你想要的,你想要多less:

 subjectAltName = DNS:*.g00gle.com, DNS:g00gle.com, DNS:192.168.1.2 

(最后一个内部访问像“ https://192.168.1.2 ”没有警告)

所以像这样:

 [ req ] req_extensions = my_extensions [my_extensions] subjectAltName = DNS:*.g00gle.com, DNS:g00gle.com, DNS:192.168.1.2 

干杯!