如何为使用 OpenSSL 生成的证书提供多行证书名称 (CN)
Posted
技术标签:
【中文标题】如何为使用 OpenSSL 生成的证书提供多行证书名称 (CN)【英文标题】:How to give a multiline certificate name (CN) for a certificate generated using OpenSSL 【发布时间】:2014-06-24 18:20:33 【问题描述】:我正在按照Create PKCS#12 file with self-signed certificate via OpenSSL in Windows for my android App 此处的步骤使用 OpenSSL 生成自签名证书。
openssl req -x509 -days 365 -subj "/CN=这里需要多行" -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
这里的主题由 cmd 的提示填充,例如 Country、State 等。我希望为 CN 属性提供多行值。如何在命令行中执行此操作?
【问题讨论】:
"...CN 属性的多行值..." - 你在这里是什么意思?你真的想要公用名中的CRLF
吗?或者您想要多个 DNS 名称(example.com
、www.example.com
等)在通用名称中?还是您想要多个通用名称(2 或 3 而不是 1)?
另外,通用名应该是一个“友好”的名字,比如Example, LLC
;并且不是像 example.com
这样的 DNS 名称。 IETF 和 CA/Browser 论坛均不赞成在 Common Name 字段中使用 DNS 名称。将您的 DNS 名称放在主题替代名称 (SAN) 中。可以有多个 SAN。
我已经编辑了问题@jww 所以,CN 应该是:CN = GOOGLE (ENTER) INC
在这种情况下,可能不是在一个命令中使用 OpenSSL。您可以分三步完成:(1) 生成 CSR,(2) 使用 Hex Editor 编辑,以及 (3) 签署 CSR。这是一个奇怪的要求。您是否试图破坏提供证书的浏览器和其他软件?
@jww 如果我想要多个域名怎么办?比如 www.google.com 和 www.yahoo.com
【参考方案1】:
...当我想要多个域名时怎么办?喜欢www.google.com 和www.yahoo.com?
以下是向证书添加多个 DNS 名称的方法。您必须通过Subject Alternate Names
(SAN) 添加它们。
在您的情况下,在alternate_names
部分下添加www.google.com
和www.yahoo.com
。
(我不确定这是答案还是评论。我仍然不清楚您是否想要通过将 CRLF
添加到 @987654328 来尝试破坏 PKI 东西@;或者如果您只想将多个 DNS 名称添加到证书中)。
第一
$ touch example-com.conf
第二
将以下内容添加到配置文件中。调整它以适合您的口味。
[ req ]
default_bits = 2048
default_keyfile = server-key.pem
distinguished_name = req_distinguished_name
req_extensions = extensions
x509_extensions = extensions
string_mask = utf8only
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = US
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = NY
localityName = Locality Name (eg, city)
localityName_default = New York
organizationName = Organization Name (eg, company)
organizationName_default = Example, LLC
commonName = Common Name (e.g. server FQDN or YOUR name)
commonName_default = Example, LLC
emailAddress = Email Address
emailAddress_default = test@example.com
[ extensions ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alternate_names
nsComment = "OpenSSL Generated Certificate"
[ alternate_names ]
DNS.1 = example.com
DNS.2 = www.example.com
DNS.3 = mail.example.com
DNS.4 = ftp.example.com
第三
使用以下内容生成证书。它为每个请求生成一个新密钥。调整它以适合您的口味。例如,如果您省略 -x509
,您将获得 CSR 而不是证书。
$ openssl req -config example-com.conf -new -x509 -newkey rsa:2048 -nodes \
-keyout example-com.key.pem -days 365 -out example-com.cert.pem
第四个
使用以下内容检查证书。
$ openssl x509 -in example-com.cert.pem -text -noout
您将在 SAN 中看到多个 DNS 名称。
$ openssl x509 -in example-com.cert.pem -text -noout
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 15695764655789201623 (0xd9d28ecb727258d7)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=US, ST=NY, L=New York, CN=Example, LLC/emailAddress=test@example.com
Validity
Not Before: May 10 22:34:14 2014 GMT
Not After : May 10 22:34:14 2015 GMT
Subject: C=US, ST=NY, L=New York, CN=Example, LLC/emailAddress=test@example.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:9a:a4:93:67:26:79:6f:dd:9a:25:0a:11:66:f6:
5a:04:36:66:5f:46:fd:b3:ee:08:ac:e4:92:88:12:
92:ea:ec:9b:62:6c:5d:ec:8c:4f:c6:0c:e9:99:c4:
77:70:3e:52:fc:25:9d:74:56:2d:49:08:9c:8f:b3:
82:ea:9e:b2:60:52:69:59:7f:c8:14:15:74:ef:f6:
80:6c:7f:1d:b4:b8:55:89:7f:d7:e4:0a:94:9e:3f:
fe:b6:64:fa:7a:9a:f6:43:46:53:f2:e3:b0:8f:92:
ca:83:6d:00:1d:57:9a:73:b9:f9:14:11:2b:fc:2d:
36:b5:ed:95:73:c3:28:7d:4b:86:97:88:85:cd:d6:
32:b7:e3:db:ea:3b:9a:7c:5a:c9:b0:6b:38:ac:e4:
44:e6:95:57:6a:f0:05:7a:5c:86:e0:46:4a:83:b2:
78:59:38:42:9c:84:c6:8b:ee:04:cc:8b:e5:29:3a:
45:6f:0e:8c:cd:6e:35:e9:f8:f7:fb:f2:a5:8a:e2:
53:77:b2:59:33:64:9a:1d:98:d6:4e:2d:e6:73:cb:
18:fc:86:4f:e7:bf:3b:14:79:92:32:e0:63:40:d3:
16:b6:33:f6:42:fc:59:6c:a4:8c:ed:86:68:3e:14:
64:da:16:66:85:42:ef:73:8a:c1:f9:6f:a2:b0:92:
d0:fb
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
B5:CE:04:1D:D9:10:85:FF:2E:FD:AA:AA:CB:36:7A:1E:14:66:69:EA
X509v3 Authority Key Identifier:
keyid:B5:CE:04:1D:D9:10:85:FF:2E:FD:AA:AA:CB:36:7A:1E:14:66:69:EA
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
Digital Signature, Non Repudiation, Key Encipherment
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 Subject Alternative Name:
DNS:example.com, DNS:www.example.com, DNS:mail.example.com, DNS:ftp.example.com
Netscape Comment:
OpenSSL Generated Certificate
Signature Algorithm: sha1WithRSAEncryption
32:a0:28:21:8b:a8:46:d5:89:5e:10:b7:b6:35:cb:a8:2e:4a:
a4:10:3d:4c:1d:3f:8a:b2:7d:2e:53:e5:4f:b5:c7:9c:14:84:
ad:11:51:01:f2:41:80:6e:23:10:ed:d6:cc:38:48:15:ff:d8:
17:6c:09:b0:1e:b7:ed:c0:1a:6d:41:74:48:63:05:46:85:61:
bd:ac:ab:36:0e:70:a1:e5:2b:1d:3b:02:0b:00:31:74:d3:5e:
0c:88:9b:ac:e8:c7:3d:22:22:90:01:c3:c0:f0:1e:e5:0a:4c:
b1:0f:ab:6b:39:5c:af:fc:34:53:ef:fd:38:35:9b:15:63:57:
f9:89:f0:f6:b8:5a:c7:e1:a6:ab:03:b0:b5:5a:c9:f1:b6:02:
41:ba:f8:5b:58:f4:ed:4c:57:df:69:3f:55:25:57:4d:39:da:
94:8a:36:27:f1:a8:db:59:c3:47:65:9d:db:7c:5d:0f:39:4a:
6a:a8:b6:12:7b:2e:41:16:b5:ed:b9:33:aa:a0:74:d3:1c:3f:
a4:4a:c8:0b:e3:37:13:f0:97:38:c5:4d:6c:62:d5:16:31:c3:
c9:d9:48:91:d1:e6:3f:33:0e:24:0d:96:80:a3:80:b4:09:32:
30:4c:e2:c2:d8:d3:3d:76:98:f0:5e:70:e0:ec:4a:ba:2e:97:
44:4a:75:f2
【讨论】:
以上是关于如何为使用 OpenSSL 生成的证书提供多行证书名称 (CN)的主要内容,如果未能解决你的问题,请参考以下文章