我有两个非常相似的自签名证书,通过两种不同的方法生成。
为了测试它们,我有:
openssl s_client -connect local.mydomain.com -CAfile /path/to/the/ca/cert.pem
一个证书失败:
CONNECTED(00000003)
depth=0 CN = local.mydomain.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 CN = local.mydomain.com
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
0 s:/CN=local.mydomain.com
i:/CN=local.mydomain.com
---
一个证书成功:
CONNECTED(00000003)
depth=0 CN = local.mydomain.com
verify return:1
---
Certificate chain
0 s:/CN = local.mydomain.com
i:/CN = local.mydomain.com
---
我将证书的详细信息与openssl x509 -in /path/to/the/ca/cert.pem -text -noout
失败的证书:
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
47:dc:02:c7:11:fc:8e:96:45:22:aa:6b:23:79:32:ca
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=local.mydomain.com
Validity
Not Before: Nov 18 11:55:31 2016 GMT
Not After : Nov 18 12:15:31 2017 GMT
Subject: CN=local.mydomain.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
<stuff>
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Key Usage: critical
Digital Signature, Key Encipherment
X509v3 Extended Key Usage:
TLS Web Client Authentication, TLS Web Server Authentication
X509v3 Subject Alternative Name:
DNS:local.mydomain.com
X509v3 Subject Key Identifier:
6D:4F:AF:E4:60:23:72:E5:83:27:91:7D:1D:5F:E9:7C:D9:B6:00:2A
Signature Algorithm: sha256WithRSAEncryption
<stuff>
工作证书:
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
9b:6b:3d:a3:b9:a3:a4:b4
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=local.mydomain.com
Validity
Not Before: Nov 19 13:27:30 2016 GMT
Not After : Nov 19 13:27:30 2017 GMT
Subject: CN=local.mydomain.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
<stuff>
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
03:E7:DA:AA:2E:CC:23:ED:C5:07:3D:E1:33:86:F5:22:D4:76:EB:CB
X509v3 Authority Key Identifier:
keyid:03:E7:DA:AA:2E:CC:23:ED:C5:07:3D:E1:33:86:F5:22:D4:76:EB:CB
X509v3 Basic Constraints:
CA:TRUE
Signature Algorithm: sha256WithRSAEncryption
57<stuff>
考虑到这一点,最明显的区别是工作证书在CA:TRUE
下有X509v3 Basic Constraints
。但是,通过阅读网络,我认为自签名证书不是CA,特别是这表示他们通常不会:
https://security.stackexchange.com/questions/44340/basic-self-signed-certificate-questions
那里的答案是说自我签名没有CA参与。但也许openssl需要自签名证书才能拥有该设置?
答案 0 :(得分:1)
根据我自己的实验,我可以确认你所看到的。我对该行为的解释是,即使发行人的证书是证书本身,自签名证书仍然是由发行人签署的证书。但只有CA证书可用于签署证书,即确切地说是CA:true允许的约束。这意味着自签名证书也必须是具有约束CA:true的CA证书。
答案 1 :(得分:0)
RFC5280说:
The CA boolean indicates whether the certified public key may be used to verify certificate signatures.
因此,如果您的证书没有CA:TRUE
标志,则此证书不得用于验证任何证书(包括其自身)上的签名。 OpenSSL正确遵循RFC。
认为证书属于两种类型之一是错误的,&#34; CA证书&#34;或者&#34;终端实体证书&#34;。具有CA:TRUE
的证书可用于验证实体。这正是您使用自签名证书进行身份验证时所执行的操作。它也可以是CA:TRUE
的证书,由其他人签名。