当我在生成 PFX 文件时不包含 .cert 文件的所有层次结构时会发生什么

What Happens when i don't included all hierarchy of .cert files while PFX file generation

Ì 我正在尝试 a) 从可用的证书文件和私有文件中导出 PFX 文件,当我使用如下所有可用的证书层次结构导出时 - 我收到以下错误

pkcs12 -export -out C:\Users\YSW\SCI\prp\preproduction-abc.com.pfx -inkey C:\Users\YSW\PCI\prp\pk.preproduction-abc.com.txt -in C:\Users\YSW\SCI\prp\pk.preproduction-abc.com.txt -in C:\Users\YSW\PCI\prp\TrustedSecureCertificateAuthority5.crt -in C:\Users\YSW\PCI\prp\USERTrustRSAAddTrustCA.crt -in C:\Users\YSW\PCI\prp\AddTrustExternalCARoot.crt

错误 ""没有证书匹配私钥, pkcs12 错误""

b) 当我删除层次结构中的证书并只保留主证书时,如下所示,它对我来说效果很好,没有任何错误

pkcs12 -export -out C:\Users\YSW\SCI\prp\preproduction-abc.com.pfx -inkey C:\Users\YSW\PCI\prp\pk.preproduction-abc.com.txt -in C:\Users\YSW\SCI\prp\pk.preproduction-abc.com.txt

在我将此 PFX 文件上传到服务器之前,我想确保在生成 PFX 文件时排除层次结构中的其他证书是否可以

请注意,我已经按照我在证书中看到的层次结构给出了证书,层次结构最低的在前,层次结构最高的在最后

""-在 C:\Users\YSW\SCI\prp\pk.preproduction-abc.com.txt -在 C:\Users\YSW\PCI\prp\TrustedSecureCertificateAuthority5.crt -在 C:\Users\YSW\PCI\prp\USERTrustRSAAddTrustCA.crt -在 C:\Users\YSW\PCI\prp\AddTrustExternalCARoot.crt""

我想知道如果我继续使用从主证书导出的 PFX 会发生什么,或者让我知道如何解决 No certificate matches the Private Key 错误的问题

openssl pkcs12 command 只允许“-in”参数有 1 个参数。因此多次指定它,它只会采用最后一个参数,这就是您收到错误消息的原因。

通常如果只想添加一个中间证书,您还可以指定“-certfile”参数以在PFX 文件中添加一个证书。由于您想添加多个额外的证书,因此最好的方法是将所有证书合并到一个文件中。

所有这些文件都应该是文本文件,所以我会将所有这些文件合并到一个文件中,并将它们作为一个“-in”参数全部传递。

例如(对于 windows)

copy pk.preproduction-abc.com.txt+TrustedSecureCertificateAuthority5.crt+USERTrustRSAAddTrustCA.crt+AddTrustExternalCARoot.crt allcertificates.pem

(对于 linux)

cat pk.preproduction-abc.com.txt TrustedSecureCertificateAuthority5.crt USERTrustRSAAddTrustCA.crt AddTrustExternalCARoot.crt > allcertificates.pem

然后将allcertificates.pem转换为pfx:

openssl pkcs12 -export -in allcertificates.pem -out preproduction-abc.com.pfx