匯入新的 SSL 憑證時,Keytool 錯誤「憑證回覆不包含公用金鑰」或「回覆中的公鑰和金鑰存放區不相符」
Summary: 如果金鑰存放區 (根和從屬 CA) 中缺少受信任的全鏈結憑證,或憑證並非從最後一個 CSR 簽署,則在匯入新的 SSL 憑證時,Keytool 會引發錯誤「憑證回復不包含公鑰」或「回復中的公鑰和金鑰存放區不相符」。
This article applies to
This article does not apply to
This article is not tied to any specific product.
Not all product versions are identified in this article.
Symptoms
# keytool -importcert -alias my-alias -keystore my-keystore.jks -trustcacerts -file my-signed-cert.pem
使用 Keytool 匯入憑證會產生下列其中一個錯誤:
keytool error: java.lang.Exception: Certificate reply does not contain public key for my-alias
keytool error: java.lang.Exception: Public keys in reply and keystore don't matchCause
這些錯誤可能有多種原因,但主要與以下原因有關:
- 使用錯誤的金鑰存放區檔案
- 對於外部簽署的憑證,缺少完整鏈信任憑證 (根和任何從屬 CA)
- 憑證尚未從上次產生的簽署要求 (CSR) 簽署
Resolution
檢查模組 (值必須相同),確定已簽署的憑證、CSR 來自正確的金鑰存放區 (私密金鑰):
# openssl pkcs12 -in my-keystore.jks -nodes -nocerts | openssl rsa -modulus -noout | openssl sha256
...
(stdin)= c46656d2c830cddba552198aa186ba4b13b0623d10d08768442fef28b9a4be4d
# openssl req -noout -modulus -in certreq.txt | openssl sha256
(stdin)= c46656d2c830cddba552198aa186ba4b13b0623d10d08768442fef28b9a4be4d
# openssl x509 -noout -modulus -in signed-cert.pem | openssl sha256
(stdin)= c46656d2c830cddba552198aa186ba4b13b0623d10d08768442fef28b9a4be4d
確認金鑰存放區中有根 CA 和從屬憑證:
# keytool -list -keystore my-keystore.jks
Your keystore contains 3 entries
my-alias, Sep 28, 2022, PrivateKeyEntry, ...
rootCA, Sep 28, 2022, trustedCertEntry, ...
intermediateCA, Sep 28, 2022, trustedCertEntry, ...
若要匯入外部簽署憑證,主要步驟包括:
1/ 在單獨的金鑰存放區檔案中產生私密金鑰:
# keytool -genkey -alias my-alias -keyalg RSA -keystore my-keystore.jks -storetype pkcs12
2/ 產生簽署要求:
# keytool -certreq -keyalg RSA -alias my-alias -file my-sign-request.csr -keystore my-keystore.jks
3/ 取得由外部 CA 簽署的 CSR。
您還需要信任所有證書:根和從屬 CA。必須位於單獨的檔中(使用 PEM 格式)。
4/ 匯入受信任的根 CA 憑證:
# keytool -import -alias rootCA -keystore my-keystore.jks -trustcacerts -file root-CA.pem
5/ 匯入中間憑證:
# keytool -import -alias intermediateCA -keystore my-keystore.jks -trustcacerts -file intermediate-CA.pem
(對簽名鏈中的所有從屬 CA 重複此操作,使用唯一的別名)
6/ 匯入已簽署的憑證 (使用與 CSR 中相同的別名):
6/ 匯入已簽署的憑證 (使用與 CSR 中相同的別名):
# keytool -import -alias my-alias -keystore my-keystore.jks -trustcacerts -file my-signed-cert.pem
本 KB 著重於如何使用 Java keytool 公用程式,正確建立具有外部簽署 SSL 憑證的金鑰存放區。
請參閱 PowerFlex 實作詳細資料的說明文件:
- 安全性組態指南:PowerFlex Gateway
憑證管理自訂和設定 PowerFlex:安全性
Affected Products
PowerFlex rack, PowerFlex Appliance, PowerFlex custom node, ScaleIO, PowerFlex SoftwareArticle Properties
Article Number: 000206194
Article Type: Solution
Last Modified: 11 Apr 2025
Version: 3
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.