2011-06-10 125 views
22

我使用Tomcat 7並啓用SSL連接器。 實際工作中,我有編輯本解決server.xml文件:Tomcat 7 SSL失敗

<Connector 
    clientAuth="true" port="8443" minSpareThreads="5" maxSpareThreads="75" 
    enableLookups="true" disableUploadTimeout="true" 
    acceptCount="100" maxThreads="200" 
    scheme="https" secure="true" SSLEnabled="true" 
    keystoreFile="${catalina.home}/conf/server.jks" 
    keystoreType="JKS" keystorePass="password" 
    truststoreFile="${catalina.home}/conf/server.jks" 
    truststoreType="JKS" truststorePass="password" 
    SSLVerifyClient="require" SSLEngine="on" SSLVerifyDepth="2" sslProtocol="TLS" 
/> 

但我通過在啓動服務器獲取此異常。

連接器屬性了SSLCertificateFile 必須使用SSL與 APR時來限定。 無法初始化連接器 [接頭[HTTP/1.1-8443]]

我使用創建密鑰庫的自。 有沒有人有一個好的和簡單的教程或一個好主意?

謝謝

P.S.我發佈我的執行server.xml

<?xml version='1.0' encoding='utf-8'?> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one or more 
    contributor license agreements. See the NOTICE file distributed with 
    this work for additional information regarding copyright ownership. 
    The ASF licenses this file to You under the Apache License, Version 2.0 
    (the "License"); you may not use this file except in compliance with 
    the License. You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, software 
    distributed under the License is distributed on an "AS IS" BASIS, 
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    See the License for the specific language governing permissions and 
    limitations under the License. 
--> 
<!-- Note: A "Server" is not itself a "Container", so you may not 
    define subcomponents such as "Valves" at this level. 
    Documentation at /docs/config/server.html 
--> 
<Server port="8005" shutdown="SHUTDOWN"> 
    <!-- Security listener. Documentation at /docs/config/listeners.html 
    <Listener className="org.apache.catalina.security.SecurityListener" /> 
    --> 
    <!--APR library loader. Documentation at /docs/apr.html --> 
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
    <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 
    <Listener className="org.apache.catalina.core.JasperListener" /> 
    <!-- Prevent memory leaks due to use of particular java/javax APIs--> 
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 

    <!-- Global JNDI resources 
     Documentation at /docs/jndi-resources-howto.html 
    --> 
    <GlobalNamingResources> 
    <!-- Editable user database that can also be used by 
     UserDatabaseRealm to authenticate users 
    --> 
    <Resource name="UserDatabase" auth="Container" 
       type="org.apache.catalina.UserDatabase" 
       description="User database that can be updated and saved" 
       factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
       pathname="conf/tomcat-users.xml" /> 
    </GlobalNamingResources> 

    <!-- A "Service" is a collection of one or more "Connectors" that share 
     a single "Container" Note: A "Service" is not itself a "Container", 
     so you may not define subcomponents such as "Valves" at this level. 
     Documentation at /docs/config/service.html 
    --> 
    <Service name="Catalina"> 

    <!--The connectors can use a shared executor, you can define one or more named thread pools--> 
    <!-- 
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
     maxThreads="150" minSpareThreads="4"/> 
    --> 


    <!-- A "Connector" represents an endpoint by which requests are received 
     and responses are returned. Documentation at : 
     Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) 
     Java AJP Connector: /docs/config/ajp.html 
     APR (HTTP/AJP) Connector: /docs/apr.html 
     Define a non-SSL HTTP/1.1 Connector on port 8080 
    --> 
    <Connector port="8080" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 
    <!-- A "Connector" using the shared thread pool--> 
    <!-- 
    <Connector executor="tomcatThreadPool" 
       port="8080" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 
    -->   
    <!-- Define a SSL HTTP/1.1 Connector on port 8443 
     This connector uses the JSSE configuration, when using APR, the 
     connector should be using the OpenSSL style configuration 
     described in the APR documentation --> 

<!-- 
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 
       maxThreads="150" scheme="https" secure="true" 
       clientAuth="false" sslProtocol="TLS" /> 
--> 

<Connector 
    clientAuth="true" port="8443" minSpareThreads="5" maxSpareThreads="75" 
    enableLookups="true" disableUploadTimeout="true" 
    acceptCount="100" maxThreads="200" 
    scheme="https" secure="true" SSLEnabled="true" 
    keystoreFile="${catalina.home}/conf/server.jks" 
    keystoreType="JKS" keystorePass="password" 
    truststoreFile="${catalina.home}/conf/server.jks" 
    truststoreType="JKS" truststorePass="password" 
    SSLVerifyClient="require" SSLEngine="on" SSLVerifyDepth="2" sslProtocol="TLS" 
/> 

    <!-- Define an AJP 1.3 Connector on port 8009 --> 
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 


    <!-- An Engine represents the entry point (within Catalina) that processes 
     every request. The Engine implementation for Tomcat stand alone 
     analyzes the HTTP headers included with the request, and passes them 
     on to the appropriate Host (virtual host). 
     Documentation at /docs/config/engine.html --> 

    <!-- You should set jvmRoute to support load-balancing via AJP ie : 
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">   
    --> 
    <Engine name="Catalina" defaultHost="localhost"> 

     <!--For clustering, please take a look at documentation at: 
      /docs/cluster-howto.html (simple how to) 
      /docs/config/cluster.html (reference documentation) --> 
     <!-- 
     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 
     -->   

     <!-- Use the LockOutRealm to prevent attempts to guess user passwords 
      via a brute-force attack --> 
     <Realm className="org.apache.catalina.realm.LockOutRealm"> 
     <!-- This Realm uses the UserDatabase configured in the global JNDI 
      resources under the key "UserDatabase". Any edits 
      that are performed against this UserDatabase are immediately 
      available for use by the Realm. --> 
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
       resourceName="UserDatabase"/> 
     </Realm> 

     <Host name="localhost" appBase="webapps" 
      unpackWARs="true" autoDeploy="true"> 

     <!-- SingleSignOn valve, share authentication between web applications 
      Documentation at: /docs/config/valve.html --> 
     <!-- 
     <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 
     --> 

     <!-- Access log processes all example. 
      Documentation at: /docs/config/valve.html 
      Note: The pattern used is equivalent to using pattern="common" --> 
     <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
       prefix="localhost_access_log." suffix=".txt" 
       pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/> 

     </Host> 
    </Engine> 
    </Service> 
</Server> 

回答

21

如果您使用APR連接器,則無法使用密鑰存儲。它需要與Apache使用的相同的證書格式。

編輯:如果您在Linux上運行Debian或Ubuntu,則可以使用ssl-cert軟件包生成一個自簽名證書,該文件可以在http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Edit_the_Tomcat_Configuration_File(向下滾動到APR部分)中記錄的APR連接器上使用。

編輯:試試這個作爲你的server.xml文件。我刪除了一些評論並評論了APR的聽衆。您的密鑰庫現在應該可以工作。

<?xml version='1.0' encoding='utf-8'?> 
<Server port="8005" shutdown="SHUTDOWN"> 
    <!-- Security listener. Documentation at /docs/config/listeners.html 
    <Listener className="org.apache.catalina.security.SecurityListener" /> 
    --> 
    <!--APR library loader. Documentation at /docs/apr.html --> 
    <!-- <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> --> 
    <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 
    <Listener className="org.apache.catalina.core.JasperListener" /> 
    <!-- Prevent memory leaks due to use of particular java/javax APIs--> 
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 

    <!-- Global JNDI resources 
     Documentation at /docs/jndi-resources-howto.html 
    --> 
    <GlobalNamingResources> 
    <!-- Editable user database that can also be used by 
     UserDatabaseRealm to authenticate users 
    --> 
    <Resource name="UserDatabase" auth="Container" 
       type="org.apache.catalina.UserDatabase" 
       description="User database that can be updated and saved" 
       factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
       pathname="conf/tomcat-users.xml" /> 
    </GlobalNamingResources> 

    <!-- A "Service" is a collection of one or more "Connectors" that share 
     a single "Container" Note: A "Service" is not itself a "Container", 
     so you may not define subcomponents such as "Valves" at this level. 
     Documentation at /docs/config/service.html 
    --> 
    <Service name="Catalina"> 

    <!--The connectors can use a shared executor, you can define one or more named thread pools--> 
    <!-- 
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
     maxThreads="150" minSpareThreads="4"/> 
    --> 


    <!-- A "Connector" represents an endpoint by which requests are received 
     and responses are returned. Documentation at : 
     Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) 
     Java AJP Connector: /docs/config/ajp.html 
     APR (HTTP/AJP) Connector: /docs/apr.html 
     Define a non-SSL HTTP/1.1 Connector on port 8080 
    --> 
    <Connector port="8080" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 
    <!-- A "Connector" using the shared thread pool--> 
    <!-- 
    <Connector executor="tomcatThreadPool" 
       port="8080" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 
    -->   
    <!-- Define a SSL HTTP/1.1 Connector on port 8443 
     This connector uses the JSSE configuration, when using APR, the 
     connector should be using the OpenSSL style configuration 
     described in the APR documentation --> 

<!-- 
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 
       maxThreads="150" scheme="https" secure="true" 
       clientAuth="false" sslProtocol="TLS" /> 
--> 

<Connector 
    clientAuth="true" port="8443" minSpareThreads="5" maxSpareThreads="75" 
    enableLookups="true" disableUploadTimeout="true" 
    acceptCount="100" maxThreads="200" 
    scheme="https" secure="true" SSLEnabled="true" 
    keystoreFile="${catalina.home}/conf/server.jks" 
    keystoreType="JKS" keystorePass="password" 
    truststoreFile="${catalina.home}/conf/server.jks" 
    truststoreType="JKS" truststorePass="password" 
    SSLVerifyClient="require" SSLEngine="on" SSLVerifyDepth="2" sslProtocol="TLS" 
/> 

    <!-- Define an AJP 1.3 Connector on port 8009 --> 
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 


    <!-- An Engine represents the entry point (within Catalina) that processes 
     every request. The Engine implementation for Tomcat stand alone 
     analyzes the HTTP headers included with the request, and passes them 
     on to the appropriate Host (virtual host). 
     Documentation at /docs/config/engine.html --> 

    <!-- You should set jvmRoute to support load-balancing via AJP ie : 
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">   
    --> 
    <Engine name="Catalina" defaultHost="localhost"> 

     <!--For clustering, please take a look at documentation at: 
      /docs/cluster-howto.html (simple how to) 
      /docs/config/cluster.html (reference documentation) --> 
     <!-- 
     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 
     -->   

     <!-- Use the LockOutRealm to prevent attempts to guess user passwords 
      via a brute-force attack --> 
     <Realm className="org.apache.catalina.realm.LockOutRealm"> 
     <!-- This Realm uses the UserDatabase configured in the global JNDI 
      resources under the key "UserDatabase". Any edits 
      that are performed against this UserDatabase are immediately 
      available for use by the Realm. --> 
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
       resourceName="UserDatabase"/> 
     </Realm> 

     <Host name="localhost" appBase="webapps" 
      unpackWARs="true" autoDeploy="true"> 

     <!-- SingleSignOn valve, share authentication between web applications 
      Documentation at: /docs/config/valve.html --> 
     <!-- 
     <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 
     --> 

     <!-- Access log processes all example. 
      Documentation at: /docs/config/valve.html 
      Note: The pattern used is equivalent to using pattern="common" --> 
     <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
       prefix="localhost_access_log." suffix=".txt" 
       pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/> 

     </Host> 
    </Engine> 
    </Service> 
</Server> 
+0

我可以在沒有Keystore的情況下創建SSL連接,還是可以實施與我的密鑰庫的SSL連接?我想用SSL Transportlayer在Tomcat上運行WebService。 – Happo 2011-06-10 12:34:44

+2

您需要一個證書才能創建SSL連接:如果您未使用APR連接器,則可以使用密鑰庫,或者如果您使用的是APR連接器,則必須使用OpenSSL格式的證書文件。更改您的'server.xml'文件並刪除已配置的APR偵聽器,您將可以使用現有的密鑰存儲庫。 – Femi 2011-06-10 12:38:49

+0

你能舉一個server.xml的例子嗎?我不知道我是如何實現這一點的。 – Happo 2011-06-10 13:03:57

23

評論:

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
+2

評論此爲m工作 – 2013-09-13 07:05:56

+0

因爲我所需要做的就是在Windows盒子上測試,這是一個很好的臨時解決方法。 – cschooley 2013-11-04 20:01:24

+2

也適用於我。但你能解釋一下AprLifecycleListener的用途嗎? – grep 2014-09-09 10:34:26

0

有實現SSL上的TOMCAT

(APR實現SSL和JSSE實現的SSL的)

的區別兩種方式是JDK正在使用它自己的SSL實現,而APR它使用計算機上安裝的東西,即在大多數情況下使用OpenSSL。使用

第一種方式(JSSE)的Java

  1. 創建於COMAND prompet CMD [CD $ JAVA_HOME /斌]

    密鑰存儲文件

(窗口-OS)

keytool -genkey -alias tomcat -keyalg RSA

  1. (配置Tomcat的SSL連接器)在(.. \ Tomcat的8.0 \的conf \ server.xml中)使用

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" 
 
scheme="https" URIEncoding="UTF-8"sslProtocol="TLS"keystorePass="yourPassword" 
 
keystoreFile="locationofkeystorefile" keyAlias="youralias" clientAuth="false" />

方式二(ARP)OpenSSL的

  1. 使用Java創建密鑰庫文件

  2. (配置Tomcat的SSL連接器)中(.. \ Tomcat的8.0 \ CONF \ server.xml中)

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
 

 
<Connector protocol="org.apache.coyote.http11.Http11AprProtocol" 
 
port="8443" clientAuth="false" sslProtocol="TLS" 
 
SSLEnabled="true" maxThreads="150" scheme="https" secure="true" 
 
SSLCertificateFile="/tmp/monitoringPortalCert.pem" 
 
SSLCertificateKeyFile="/tmp/monitoringPortalKey.pem" 
 
SSLPassword="hide"/>

有用網址:

http://java.dzone.com/articles/setting-ssl-tomcat-5-minutes

http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html