x509 - 如何通过命令行将 CSR 回复导入回我的 key 对?

标签 x509 keytool csr

我使用 keytool -genkeypair 命令创建了一个带有初始 key 对的 keystore ,然后使用 keytool -certreg 命令生成了 CSR,然后由我们的CA现在我收到了 CSR 回复 myCSRreply.cer,如何将 CSR 回复与我的原始 key 对结合起来?

我试过使用 keytool -import 命令简单地将 CSR 回复导入我的 keystore ,但这并没有改变我原来的 key 对。它只是将 CSR 回复添加为另一个条目。我希望它能更改我的原始 key 对的颁发者和指纹。

我可以通过 KeyStore 资源管理器实现我想实现的目标,如下面的屏幕截图所示,但我需要知道如何在命令行中执行此操作。

enter image description here

如果我尝试导入指定 CSR 回复文件和原始 key 对别名的位置,我会收到以下错误。

keytool error: java.lang.Exception: Failed to establish chain from 
reply

我用来将 CSR 导入回生成该错误的 key 对的命令:

keytool -keystore myKeyStore.pfx -importcert -file myCSRreply.cer -alias mykeypair

问题

  1. 如何通过命令行将 CSR 回复 导入回我的 key 对,以便它将指纹和 CSR 回复 的颁发者作为我的原始 key 对的新属性? (我只是假设这是预期的结果,因为当我使用带有指纹的私钥生成 JWT 时,身份验证失败)
  2. CSR 回复 是否真的要更改生成 CSR 的 key 对的指纹和颁发者属性?

最佳答案

您正在执行的命令没有问题。您没有新证书的完整证书链。

当您生成 mykeypair key 对时,keytool 将 mykeypair 的公钥包装在自签名证书中。 (这就是为什么您必须在生成过程中提供其到期日期和其他详细信息的原因。)因此,它自己形成了一个完整的证书链;这是一个根证书。 keytool 总是希望每个证书都有一个完整的证书链。

当您尝试导入 CSR 回复时,您正在导入一个新证书。这时keytool会尝试为它建立证书链。 keytool 将搜索 keystore 和信任库,直到找到受信任的根证书。如果它不能这样做,导入将失败。

阅读以下文档:

Import a Certificate for the CA

You now need to replace the self-signed certificate with a certificate chain, where each certificate in the chain authenticates the public key of the signer of the previous certificate in the chain, up to a root CA.

Before you import the certificate reply from a CA, you need one or more trusted certificates in your keystore or in the cacerts keystore file. See -importcert in Commands.

If the certificate reply is a certificate chain, then you need the top certificate of the chain. The root CA certificate that authenticates the public key of the CA.

If the certificate reply is a single certificate, then you need a certificate for the issuing CA (the one that signed it). If that certificate is not self-signed, then you need a certificate for its signer, and so on, up to a self-signed root CA certificate.

...

You import a certificate for two reasons: To add it to the list of trusted certificates, and to import a certificate reply received from a certificate authority (CA) as the result of submitting a Certificate Signing Request to that CA (see the -certreq option in Commands).

keytool Documentation

关于x509 - 如何通过命令行将 CSR 回复导入回我的 key 对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68570121/

相关文章:

java - 将私钥导入 keystore

javascript - 我们如何使用 Regex 验证 CSR 的格式

ssl - 为什么我必须从私钥创建证书请求 (CSR)?

c++ - MITM 代理,TLS 1.2 证书验证失败

c++ - 读取和验证证书

android - Java key 对 - 私有(private)和公共(public) - 我只有私有(private)

android - 获取MD5指纹cmd提示错误

ssl - 使用 openssl 创建 SSL 证书

c - 使用 Openssl API 从 C 文件夹中读取所有 X509 证书

pdf - 如何使用 OpenSSL 对文件进行可信签名