将证书导入为PrivateKeyEntry

bht*_*oan 14 ssl keystore keytool

我在Tomcat服务器上安装SSL,并遵循发行人https://knowledge.rapidssl.com/support/ssl-certificate-support/index?page=content&actp=CROSSLINK&id=SO16181的这些说明,并声明:

Verify the following information:

The SSL certificate is imported into the alias with the "Entry Type" of 
PrivateKeyEntry or KeyEntry.  If not, please import the certificate into 
the Private Key alias.
Run Code Online (Sandbox Code Playgroud)

当我导入证书(tomcat)时我正在使用:

keytool -import -trustcacerts -alias your_alias_name -keystore your_keystore_filename
-file your_certificate_filename
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时它导入为trustCertEntry

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 3 entries

primaryca, Jul 26, 2014, trustedCertEntry,
Certificate fingerprint (SHA1): <snip>
tomcat, Jul 26, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):  <snip>
secondaryca, Jul 26, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):  <snip>
Run Code Online (Sandbox Code Playgroud)

如何将别名tomcat导入为PrivateKeyEntry?

Eit*_*mon 12

您尝试添加证书并期望它是私钥 - 它混淆了两个不同的事物。

通常,当您创建密钥库 (.jks) 时,它会在其中包含私钥。如果它是空的(已删除),您应该从您的密钥和证书生成包(.p12 文件)。

为了创建新的免费密钥和证书,您可以使用 openSSl https://zerossl.com 的这个实现。

然后,您有一个密钥和证书,您应该从中生成 (.p12) 捆绑文件:(在 linux 机器上)

openssl pkcs12 -export -in [filename-certificate] -inkey [filename-key] -name [host] -out [filename-new-PKCS-12.p12]
Run Code Online (Sandbox Code Playgroud)

现在,只需通过执行以下命令将捆绑文件(.p12 文件)添加到密钥库 (.jks):

keytool -importkeystore -deststorepass [password] -destkeystore [filename-new-keystore.jks] -srckeystore [filename-new-PKCS-12.p12] -srcstoretype PKCS12
Run Code Online (Sandbox Code Playgroud)


use*_*421 7

摆脱-trustcacerts选择.它不是CA证书.这是你的证书.并使用私钥已经拥有的相同别名.

  • 离开它对我没有任何影响。这不一定是唯一的问题。 (5认同)

Bru*_*uno 5

这些 CA 指南有点误导。@EJP 正确地说你不应该使用-trustcacerts你的证书。

此外,本 CA 文档建议在单独的操作中导入主 CA 证书和中间 CA 证书,这应该会给您这样的结果:

primaryca, Jul 26, 2014, trustedCertEntry,
Certificate fingerprint (SHA1): <snip>
secondaryca, Jul 26, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):  <snip>
tomcat, Jul 26, 2014, PrivateKeyEntry,
Certificate fingerprint (SHA1):  <snip>
Run Code Online (Sandbox Code Playgroud)

不幸的是,像这样在您的密钥库中导入 CA 证书毫无意义。(它在truststore 中很有用,但您使用的 CA 可能已经在默认 truststore 中。)

密钥库中为您的证书提供 CA 证书确实很有用,以便在需要中间证书时提供完整的证书链。然而,密钥管理器(除非可能是自定义实现)不会为您构建链,即使它在您的终端实体证书(在 PrivateKeyEntry 中)旁边找到合适的 CA 证书。

您需要将这些证书一起导入,作为一个链,针对您的私钥所在的条目。为此,请将证书连接到一个文本文件(PEM 编码)中,首先是您的服务器证书,然后是用于颁发它的证书,依此类推。然后,使用该私钥别名将该文件导入您的密钥库。(这与此问题中的问题完全相同,但使用服务器证书。)

(我不确定您的 CA 是否已经将您的证书文件作为一个链提供给您,但通常,您至少只能在一个文件中获得您的证书,而在另一个文件中获得中间 CA 证书。您链接到的文档似乎具有误导性,因为它们没有提及 之间的多个块--BEGIN/END CERT--,但不知何故,他们的示例屏幕截图针对该单个别名的证书长度为 4。)

正如@jww 在对您的问题的评论中指出的那样,您不需要此链中的“根”CA 证书(自签名的证书),因为您的客户已经信任它,或者没有理由信任它发送时请相信它。将它放在您的链中并没有错,但它毫无意义,并且可能会增加一些网络开销。