【问题标题】:keytool: import certificate chain from several .cer fileskeytool:从多个 .cer 文件导入证书链
【发布时间】:2014-06-05 13:08:43
【问题描述】:

我们的 IT 部门给了我 4 个 .cer 文件,它们构成了证书链:thawte_root.cer->intermediate1_pem.cer->intermediate2_pem.cer->our_company.cer。

我需要使用 our_company.cer 签署一些代码(通过 jarsigner)。

因此,我必须创建一个密钥库,其中包含 our_company.cer 和 chain-to-the-root。

我尝试使用记事本将这 4 个文件简单地连接成一个文件,然后导入生成的文件,但密钥库只导入第一个文件,当我尝试启动 jarsigner 时,我得到了

"jarsigner: Certificate chain not found for: our_company. our_company must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain."

当我仅导入 our_company.cer 或逐个导入每个证书时,我会收到相同的消息。

所以问题是:如何将 4 个证书作为一个链导入?

提前致谢。维塔利。

【问题讨论】:

    标签: java ssl certificate keytool


    【解决方案1】:
    1. 将所有证书链接到一个文件中(顺序为根目录)
      cat intermediate2_pem.cer intermediate1_pem.cer thawte_root.cer > chain.cer
    2. 运行这个 openssl 命令
      openssl pkcs12 -export -in our_company.cer -inkey private.key -out company.p12 -name company -CAfile chain.pem -caname sub2 -caname sub1 -caname root -chain
    3. 创建密钥库
      keytool -importkeystore -destkeystore company.keystore -srckeystore company.p12 -srcstoretype PKCS12 -alias company

    您的密钥库将准备就绪(选择一个密码并在所有情况下输入)。您还需要准备好private.key

    有关更多详细信息,请参阅this link

    【讨论】:

    • 能否请您编辑您的答案以反映步骤 1 输出 chain.cer 是否步骤 2 搜索 chain.pem。大概,第一步中的所有证书都应该是pem格式的,否则在第二步中会出现“无法加载证书”的错误(这里是解释:robertwray.co.uk/blog/…
    【解决方案2】:

    您可能知道,代码签名使用public-key encryption 工作。要签署代码,您需要有一个私钥,并且想要使用您的代码的客户必须信任相应的公钥。

    您拥有的 CER 文件是与公钥对应的证书文件。当您使用keytool -importcert 导入它们而没有相应的私钥时,它们将作为受信任的证书导入。 (有关详细信息,请参阅the documentation。根据您的系统设置,您可能不需要全部导入它们 - 例如,您可能已经信任 Thawte 证书。)

    由于您想以 YourCompany 的身份对代码进行签名,因此您需要对应于 our_company.cer 的私钥 - 我想您的 IT 部门可以提供此密钥,因为它将用于生成发送给 Thawte 的证书签名请求。如果他们不愿意将其传递给您,您将需要使用 keytool -genkeypair 生成您自己的私钥/公钥对,使用 keytool -certreq 生成 CSR 并将其发送给您的 IT 部门,然后他们可以为您颁发证书。在这种情况下,最终的信任链是 thawte_root.cer->intermediate1_pem.cer->intermediate2_pem.cer->our_company.cer->your_department.cer

    【讨论】:

      猜你喜欢
      • 2021-11-26
      • 2013-01-17
      • 1970-01-01
      • 2013-03-28
      • 2012-10-31
      • 2017-08-07
      • 2014-03-01
      • 2018-04-18
      • 2013-03-26
      相关资源
      最近更新 更多