Tomcat 7 SSL失败

k0pti3hp  于 2023-04-21  发布在  其他
关注(0)|答案(5)|浏览(186)

我使用Tomcat 7并将启用SSL连接器。实际上我已经将此解决方案编辑到server.xml文件:

<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"/>

但是我在启动服务器时得到了这个异常。
将SSL与APR一起使用时,必须定义连接器属性SSLCertificateFile。无法初始化连接器[Connector[HTTP/1.1-8443]]
我使用一个自己创建的密钥库。有没有人一个好的和容易的教程或一个好主意?
谢谢
P.S.我发布我的actuall 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>
p8ekf7hl

p8ekf7hl1#

注解掉这一行:

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

mu0hgdu02#

如果使用APR连接器,则不能使用密钥库。它需要与Apache使用的相同的证书格式。
编辑:如果你在Linux上运行Debian或Ubuntu,你可以使用ssl-cert包来生成一个自签名的证书,它将与APR连接器一起工作,如www.example.com所述http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Edit_the_Tomcat_Configuration_File(向下滚动到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>
bvuwiixz

bvuwiixz3#

Tomcat中的8443端口默认用于SSL连接。
我建议你看看Tomcat的SSL文档:
http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html
还有一个链接,我发现它可以解决你的问题在任何时间:
http://java.dzone.com/articles/setting-ssl-tomcat-5-minutes这是一个惊人的文章.请通过解决问题.希望这有帮助!

hsgswve4

hsgswve44#

关闭自动切换

这里有一个自动机制在工作。我建议你禁用它,并明确选择你想要的连接器。下面的详细信息。

详情

您的连接器配置如下:

<Connector port="8443" protocol="HTTP/1.1" ...

这里重要的参数是protocol部分。Tomcat 7 documentation says this:(线打破我的)
protocol
设置协议以处理传入通信。
默认值是HTTP/1.1,它使用自动切换机制来选择基于Java的阻塞连接器或基于APR/本机的连接器。
如果PATH(Windows)或LD_LIBRARY_PATH(在大多数unix系统上)环境变量包含Tomcat本地库,则将使用APR/本地连接器。
如果找不到本机库,将使用基于Java的阻塞连接器。请注意,APR/本机库连接器的HTTPS设置与Java连接器不同。
[...]
因此,似乎正在使用自动切换,但它不工作。原因在上面的最后一段中给予:我们会自动切换到“APR”连接器
然后发生了这样的事:

  1. APR连接器具有名为SSLCertificateFile的强制参数。
    1.我们没有在server.xml中提供该参数。
  2. Tomcat抱怨缺少参数。

选项

为了解决这个问题,你有几个选择:

  • 关闭自动切换功能,将“HTTP/1.1”文本替换为所需的连接器。
  • 保留自动切换并修复它。通过将所需参数添加到server.xml。
  • 保留自动切换并故意中断它。只需删除“tomcat\bin\tcnative-1.dll”。这将触发上面提到的 * 如果无法找到本机库 * 之后的部分。这是一个有点肮脏的解决方案。我在这里提到这个并不是因为我认为这是一个好主意。而是因为我碰巧发现这已经在我们的一台开发Tomcat机器上完成了。
avwztpqn

avwztpqn5#

在TOMCAT上实现SSL有两种方法
(APR SSL实现和SSL的JSSE实现)
区别在于JDK使用自己的SSL实现,而APR使用计算机上安装的内容,即大多数情况下的OpenSSL。

第一种方式(jSSE)使用java

1.创建密钥库文件
(windows-os)in comand prompt cmd [cd $JAVA_HOME/bin]

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" />

使用openssl的第二种方式(阿普)

1.使用Java创建密钥库文件
1.(配置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

相关问题