Tomcat 8:密钥库格式无效

时间:2015-10-25 22:47:58

标签: java spring tomcat keystore keytool

我尝试将SSL配置到我的新项目中。我是第一次这样做,我遇到了一些问题。

项目的一些项目:

我的server.xml的一部分:

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
            maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
            keystoreFile="/PATHTO/src/main/resources/keystore.p12"
            keystorePass="STOREPASS" clientAuth="false" sslProtocol="TLS" />

我的application.properties的一部分:

spring.profiles.active=https
server.port=8443
server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store-password=STOREPASS
server.ssl.keyStoreType=PKCS12
server.ssl.keyAlias=tomcat

我用来生成密钥库的命令:

keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650

并且keystore.p12与application.properties位于同一文件夹中。

控制台的错误:

java.io.IOException: Invalid keystore format
    at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:650)
    at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getStore(JSSESocketFactory.java:437)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeystore(JSSESocketFactory.java:336)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:594)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:534)
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:363)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:732)
    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:457)
    at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:120)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:567)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:851)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:576)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:599)
    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:310)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)

有人有想法吗?

感谢。 欢呼声。

2 个答案:

答案 0 :(得分:1)

您需要指定var block = dispatch_block_create(...) var queue = dispatch_queue_create(...) var source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue) dispatch_set_timer(source,STARTTIME,INTERVAL,0) dispatch_source_set_event_handler(source,block) dispatch_resume(source) ,因为格式为PKCS12,而不是JKS。

答案 1 :(得分:1)

详细说明EJP对Mick Mnemonic的回答和细节,这不完全正确。

OP没有在server.xml中设置,而是在application.properties

中设置
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
        maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
        keystoreFile="/PATHTO/src/main/resources/keystore.p12"
        keystorePass="STOREPASS" clientAuth="false" sslProtocol="TLS"
        keystoreType="PKCS12" />

您将注意到,在“Connector”元素的最后一行,我添加了keystoreType =“PKCS12”,以允许连接器正确加载文件。

你的筹码追踪就是这个遗迹。