我正在尝试了解如何使用中间 CA 证书来唱歌。我已经开发了一个相当简单的示例(使用https://gist.github.com/jadbaz/9350f4df4e4ef4c5d256889aa3d5a5ed作为基础,尽管我删除了配置文件并相应地调整了一些命令)...我希望最终证书可以使用我在执行期间创建的 2 个 CA 中的任何一个进行验证,但验证失败....我遗漏了什么:
# root ca
openssl genrsa -out rootca.key 4096
openssl req -sha256 -new -x509 -days 3650 -key rootca.key -out rootca.crt -subj /CN=rootca
# intermediate ca
openssl genrsa -out interca1.key 4096
openssl req -sha256 -new -key interca1.key -out interca1.csr -subj /CN=intermediateca -addext "basicConstraints=critical,CA:true" -addext "keyUsage=critical,keyCertSign,cRLSign"
openssl x509 -copy_extensions copyall -req -days 365 -in interca1.csr -CA rootca.crt -CAkey rootca.key -CAcreateserial -out interca1.crt
# verify chain so far
openssl verify -CAfile rootca.crt rootca.crt interca1.crt # both certificates are ok
# generating an example certificate
openssl genrsa -out example1.key 2048
openssl req -new -sha256 -key example1.key -out example1.csr -subj /CN=example1
openssl x509 -copy_extensions copyall -req -days 365 -in example1.csr -CA interca1.crt -CAkey interca1.key -CAcreateserial -out example1.crt
# verify results
openssl verify -CAfile rootca.crt rootca.crt interca1.crt example1.crt
openssl verify -CAfile interca1.crt interca1.crt example1.crt
这是最后一次验证运行的输出:
# openssl verify -CAfile rootca.crt rootca.crt interca1.crt example1.crt
rootca.crt: OK
interca1.crt: OK
CN=example1
error 20 at 0 depth lookup: unable to get local issuer certificate
error example1.crt: verification failed
# openssl verify -CAfile interca1.crt interca1.crt example1.crt
CN=intermediateca
error 20 at 0 depth lookup: unable to get local issuer certificate
error interca1.crt: verification failed
CN=intermediateca
error 2 at 1 depth lookup: unable to get issuer certificate
error example1.crt: verification failed
我错过了什么?
而且,为什么不能用interca1
同样的方式验证自己rootca
呢?
我正在使用 openssl 3.2.2。
更新
在接受的答案中没有对此进行解释,但让我添加一个命令,如果您想尝试的话,该命令应该可以工作:
$ openssl verify -CAfile <( cat rootca.crt interca1.crt ) rootca.crt interca1.crt example1.crt
rootca.crt: OK
interca1.crt: OK
example1.crt: OK