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


11

我希望配置OpenSSL,以便在运行openssl req -new以生成新的证书签名请求时,系统提示我输入要包含在CSR中的任何其他主题名称。

我已将此行添加到[req_attributes]我的部分openssl.cnf

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 (e.g. 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

在上面的示例中,我DNS:alt1.example.com在提示您输入SAN时输入。

问题在于生成的CSR似乎格式不正确:

$ 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?


不幸的是,我认为没有办法用“ pure”来做到这一点openssl-您将需要一个脚本来处理其配置文件。:( PS一种以非交互方式完成此任务的可靠解决方案在这里:stackoverflow.com/a/9158662/2693875
Greg Dubicki 2016年

Answers:


4

我本人一直在与这个小金块作斗争……真是皮塔饼!

我的解决方案:我将所有openssl.cnf文件移至Template Toolkit文件中,仅保留sans部分作为替换部分,然后将perl脚本包裹在其周围。

perl脚本会提示您输入SAN条目,然后将其插入模板,将模板保存到临时文件,然后使用指向临时文件的-config选项调用openssl req。生成CSR后,丢弃临时文件。

您可能还需要查看:http : //www.openssl.org/docs/apps/config.html

还有其他一些人在执行之前重写$ ENV并将对openssl req的调用包装在perl或shell中,并以稍微更有效的方式完成相同的操作:http : //blog.loftninjas.org/2008/11/11/配置带有主题名称的SSL请求与openssl /


$ ENV解决方案对我不起作用。:(
Greg Dubicki '16

2

我也在寻找解决方案。这就是您想要的:

[req]
default_bits      = 2048
default_key_file  = private.key.pem
...
...
attributes        = req_attributes

[req_attributes]
subjectAltName = Alternative DNS names, Email adresses or IPs (comma seperated list)
#optional default value
subjectAltName_default = DNS:myhost.com.au,IP:127.0.0.1,EMAIL:my@here.org

您可以通过提示输入其他主题名称来获得此信息:)

#openssl req -in mytest1/temp.csr.pem -noout -text
    Certificate Request:
    Data:
        Version: 0 (0x0)
        Subject: C=DE, ST=Sachsen, L=Heidenau, O=IT Rab\xC3\xB6se, OU=ssl
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (1024 bit)
                Modulus (1024 bit):
                    00:d8:cd:14:ca:d0:06:6c:8c:11:e9:52:bc:46:39:
                    c1:cf:5a:6e:dd:3b:a8:85:15:6b:13:82:82:4a:48:
                    cb:53:ea:70:ea:f4:02:b2:ef:b1:41:b2:d7:11:c7:
                    11:ba:07:1b:be:8c:30:bc:60:d2:82:83:a1:e1:19:
                    75:3b:69:03:01:3c:2b:7b:85:f4:2e:a9:58:68:8f:
                    0e:f4:5e:50:e1:3f:9e:cf:46:a0:eb:69:aa:1e:cb:
                    3a:99:cb:1d:93:60:d0:3b:38:96:87:45:19:51:f4:
                    40:72:e5:a7:5e:62:37:41:44:48:64:47:95:14:97:
                    4f:27:d0:0c:e7:6f:c1:e1:37
                Exponent: 65537 (0x10001)
        Attributes:
            X509v3 Subject Alternative Name:DNS:www.google.de,EMAIL:im@you.org
    Signature Algorithm: sha1WithRSAEncryption
        9d:2b:e4:eb:1b:c0:b6:0b:b4:62:a7:4d:01:68:98:68:36:98:
        1e:e9:bc:59:24:0f:1b:32:7b:da:9d:39:a4:0f:2c:70:3e:aa:
        f7:07:e7:6b:9b:3b:00:b3:71:e0:54:07:78:c7:6e:57:e3:89:
        07:e1:93:f1:77:e7:cc:0e:d0:ed:c5:d0:a3:5d:1a:cd:bb:d8:
        5f:64:25:81:1b:a8:2f:ef:c7:84:7a:f6:b8:52:4e:4c:1c:8d:
        83:b7:9b:02:8e:b2:39:68:a1:fe:f1:59:8b:e0:c4:91:f1:a9:
        c7:b3:82:a3:d2:92:2b:e5:79:9f:29:b6:63:e7:cf:9d:17:98:
        fe:70

当查看CSR时,此方法有效,但是当我创建证书时,它不会保留SAN。
杰西(Jess)

SAN的格式是否正确?逗号分隔列表。仅使用SAN前缀DNS进行检查,如果不支持IP,EMAIL,则进行检查。例如:INPUT >>DNS:my.dns.com, DNS:my.otherdns.org
raiserle

好。这是openssl wtf的正常功能!您还必须将SAN提供给CA-command -extensions <string>-extfile <file>mta.openssl.org/pipermail/openssl-users/2016-January/...
raiserle

1

此“ subjectAltName”不应在此部分中:attributes = req_attributes。但是在req_extensions =的一节中(随便您怎么称呼它)。

而且不需要像所有的BS

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

只需输入您想要的,您想要多少:

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

干杯!


1
这不是OP要求的-他想要一个交互式的解决方案。
格雷格·杜比奇

1
是否不应该使用“ IP:192.168.1.2”而不是DNS格式的记录来记录IP?我注意到了从2013年开始的有关使用DNS或IP将IP地址存储为SAN时浏览器之间的错误的讨论-michaelm.info/blog/?p=1281-但现在应该消除该错误。
克里斯·伍兹
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.