Tomcat因UnrecoverableKeyException而失败:无法恢复密钥

时间:2017-07-14 15:51:44

标签: java tomcat

我在服务器上运行Apache Tomcat / 7.0.68,并且我试图为它自动更新证书。

证书和私钥是通过Java的keytool从PKCS#12文件导入的(摘自Powershell脚本):

& $keytool -importkeystore -srckeystore $certfile -srcstoretype PKCS12 -srcstorepass $srcpassword -srcalias tomcat -keystore $keystore -deststorepass $dstpassword -destalias teamcity -destkeypass $dstpassword -noprompt

当我重新启动Tomcat时,它会吐出以下日志行:

INFO: Initializing ProtocolHandler ["http-nio-443"]
jul. 14, 2017 5:03:31 PM org.apache.coyote.AbstractProtocol init
SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-nio-443"]
java.security.UnrecoverableKeyException: Cannot recover key
  at sun.security.provider.KeyProtector.recover(KeyProtector.java:328)
  at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:146)
  at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java:56)
  at sun.security.provider.KeyStoreDelegator.engineGetKey(KeyStoreDelegator.java:96)
  at sun.security.provider.JavaKeyStore$DualFormatJKS.engineGetKey(JavaKeyStore.java:70)
  at java.security.KeyStore.getKey(KeyStore.java:1023)
  at sun.security.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyManagerImpl.java:133)
  at sun.security.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:70)
  at javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:256)
  at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:608)
  at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:537)
  at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:495)
  at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:650)
  at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
  at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
  at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
  at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
  at org.apache.catalina.core.StandardService.initInternal(StandardService.java:560)
  at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
  at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:820)
  at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
  at org.apache.catalina.startup.Catalina.load(Catalina.java:642)
  at org.apache.catalina.startup.Catalina.load(Catalina.java:667)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:253)
  at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:427)

但是当我尝试通过keytool更改密码时,它可以正常读取条目并更改密码。

PS:我确保该条目的密码与商店的密码相同,因为至少某些版本的Tomcat需要这个。

1 个答案:

答案 0 :(得分:3)

终于解决了。事实证明,在密钥库中使用与密钥库不同的密码中的完全不相关的密钥会破坏Tomcat,如this ancient bug report中所述!