【问题标题】:How to change Java Keystore(JKS) keystore and alias password so that they work如何更改 Java Keystore(JKS) 密钥库和别名密码以使其正常工作
【发布时间】:2019-11-01 11:28:07
【问题描述】:

我创建了一个以“changeme”作为密钥库密码的全局 JKS。我使用 Keystore Explorer 创建了 JKS。

使用全局 JKS 背后的想法是应用程序可以从 S3 中拉下 JKS,然后使用自己的字符串密码重置 JKS。我们做了很多 SpringBoot API,我们使用 JKS 来保护容器中的 Tomcat,以便我们可以连接 HTTPS。

但这是我遇到的问题,当我更改 JKS 密钥库密码时,我开始收到 java.security.UnrecoverableKeyException: Cannot recover key 错误。

在 Keystore Explorer 中,我没有为别名指定密码。当我进入 Keystore Explorer 更改别名密码时,它接受“changeme”作为密码。因此,我假设 Keystore Explorer 自动使用 changeme 作为密码,因为我提供了它作为 JKS 密钥库密码。

诚然,我不是使用 JKS 和理解复杂的安全性的专家,但这个让我很难过。

我还尝试使用以下命令使用 Keytool 更改密钥库密码:

keytool -storepasswd -keystore myJKS.jks

keytool -keypasswd -alias myalias -keystore myJKS.jks

但是当我尝试更改别名时,我得到:

keytool error: java.io.IOException: Keystore was tampered, or password is wrong

我做错了什么?

谢谢

【问题讨论】:

    标签: java spring-boot keystore explorer jks


    【解决方案1】:

    您看到的错误是因为您可能在命令中提供了错误的keystore-password

    基本了解JKS 是如何以及是什么。 JKS(Java KeyStore)基本上是一个保护密钥(对称密钥)、密钥对(非对称密钥)和证书的文件。它保护它们的方式是通过密码,这个密码称为keystore-password。 JKS 文件中的密钥也可以单独保护,这意味着它们可以有自己的密码,称为key-password

    修改keystore-password的方法:

    keytool -storepasswd -keystore [KEYSTORE] -storepass [OLD_KEYSTORE_PASSWORD] -new [NEW_KEYSTORE_PASSWORD]

    修改key-password的方法:

    keytool -keypasswd -keystore [KEYSTORE] -storepass [KEYSTORE_PASSWORD] -alias [ALIAS] -keypass [OLD_KEY_PASSWORD] -new [NEW_KEY_PASSWORD]

    这些是与保护 spring-boot 应用程序相关的属性。您必须在这些属性中定义 keystore-password 和 key-password。

    server.ssl.ciphers= # Supported SSL ciphers.
    server.ssl.client-auth= # Client authentication mode.
    server.ssl.enabled=true # Whether to enable SSL support.
    server.ssl.enabled-protocols= # Enabled SSL protocols.
    server.ssl.key-alias= # Alias that identifies the key in the key store.
    server.ssl.key-password= # Password used to access the key in the key store.
    server.ssl.key-store= # Path to the key store that holds the SSL certificate (typically a jks file).
    server.ssl.key-store-password= # Password used to access the key store.
    server.ssl.key-store-provider= # Provider for the key store.
    server.ssl.key-store-type= # Type of the key store.
    server.ssl.protocol=TLS # SSL protocol to use.
    server.ssl.trust-store= # Trust store that holds SSL certificates.
    server.ssl.trust-store-password= # Password used to access the trust store.
    server.ssl.trust-store-provider= # Provider for the trust store.
    server.ssl.trust-store-type= # Type of the trust store.
    

    您可以在文档here 中找到所有 spring-boot 属性。

    如果查看属性,有server.ssl.key-store-passwordserver.ssl.key-password。您可以要求用户在更改全局 JKS 密码后设置这两个值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2019-10-21
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多