Tomcat 7和无效的密钥库格式

时间:2015-10-18 10:04:21

标签: java tomcat ssl keystore

我试图通过远程服务器上的https连接到Tomcat;我找到了很多答案,但没有人为我工作过;我在Ubuntu Server 14.04上使用Apache,Tomcat 7。

首先,我创建了证书密钥库写作:

keytool -genkey -alias tomcat -keyalg RSA
在我'之后已编辑" /etc/tomcat7/server.xml"在端口8443上使用ssl:

<Connector port="8443" SSLEnabled="true"
                protocol="org.apache.coyote.http11.Http11Protocol"
                keystoreType="JKS"
               maxThreads="150" scheme="https" secure="true"
                keystoreFile="/usr/lib/jvm/java-7-openjdk-amd64/bin/keytool"
                keystorePass="***********" keyAlias="tomcat"
               clientAuth="false" sslProtocol="TLS"/>

其中**********是密码;通过以下方式重新启动Tomcat:

sudo service tomcat7 restart

我在文件&#34; /var/log/tomcat7/catalina.out"中收到以下错误:

SEVERE: Failed to initialize connector [Connector[HTTP/1.1-8443]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-8443]]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:813)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:980)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    ... 12 more
Caused by: 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:1214)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getStore(JSSESocketFactory.java:392)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeystore(JSSESocketFactory.java:291)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:549)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:489)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.init(JSSESocketFactory.java:434)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.createSocket(JSSESocketFactory.java:181)
    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:397)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:640)
    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)
    ... 13 more

密钥库类型是JKS,我已通过以下命令对其进行了验证:

$JAVA_HOME/bin/keytool -list
已退回的

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

tomcat, 17-Oct-2015, PrivateKeyEntry,
Certificate fingerprint (SHA1): 33:14:32:DD:DA:20:BF:CF:70:32:F5:0E:E9:F1:C1:5B:4E:C3:DB:AB

其中$ JAVA_HOME是&#34; / usr / lib / jvm / java-7-openjdk-amd64&#34 ;;

所以,当我尝试连接到&#34; https://myServerIp:8443/&#34;或者#34; https://myDomainName:8443/&#34;我得到了#34;无法连接&#34;错误。

2 个答案:

答案 0 :(得分:1)

enter image description here

为了像我这样的初学者进一步支持这个答案。在Windows操作系统

  1. 首先转到 C:\ Program Files \ Java \ jdk1.8 ,  按Shift + right-click打开命令pront:写下此keytool.exe -genkey -alias tomcat -keyalg RSA -keystore /{user.name}/.keystore,  然后会出现一系列问题,您将看到在指定路径生成的新 .keytore

  2. 现在您需要转到server.xml并使用适当的一个修改这两个keystoreFile="${user.home}/.keystore" keystorePass="changeit"

答案 1 :(得分:0)

现在它正常工作,简而言之:

  • 指定了.keystore 文件的路径
  • 将Tomcat配置为使用此文件

感谢@Titus我已经明白了问题所在:当我运行命令时

keytool -genkey -alias tomcat -keyalg RSA

或命令

$JAVA_HOME/bin/keytool -genkey -keyalg RSA -alias tomcat

程序keytool在服务器的文件夹中创建文件.keystore;目录/usr/lib/jvm/java-7-openjdk-amd64/jre/bin包含一个名为keystore的文件,但是这个文件设置tomcat不正确,或者由于某些原因它在我的情况下不起作用。 要指定文件.keystore的路径,我们可以运行命令

keytool -genkey -alias tomcat -keyalg RSA -keystore /path/.keystore

之后我将Tomcat配置为使用刚刚创建的文件编辑文件/etc/tomcat7/server.xml

<Connector port="8443" SSLEnabled="true"
                protocol="org.apache.coyote.http11.Http11Protocol"
                keystoreType="JKS"
               maxThreads="150" scheme="https" secure="true"
                keystoreFile="/path/.keystore"
                keystorePass="************" keyAlias="tomcat"
               clientAuth="false" sslProtocol="TLS"/>