• 在 Apache Tomcat 中配置双向 SSL


    环境

    • Red Hat Enterprise Linux (RHEL)
      • 6.x
      • 7.x
    • 红帽企业 Web 服务器 (EWS)
      • 2.x
    • 红帽 JBoss Web Server (JWS)
      • 3.x
      • 5.x
    • 阿帕奇雄猫
      • 6.x
      • 7.x
      • 8.x
      • 9.x

    问题

    • 在服务器和客户端中设置 ssl
    • 如何要求客户端身份验证以及服务器身份验证?

    解决方案

    首先,按照 如何在 Tomcat 上设置 SSL 中的说明配置服务器。

    在服务器使用 SSL 后,使用 certificateVerification="required" 参数:

    Java Keystore

    Raw

    1. <Connector port="8443" minProcessors="5" maxProcessors="75" enableLookups="true"
    2. protocol="org.apache.coyote.http11.Http11Protocol"
    3. disableUploadTimeout="true" acceptCount="100" debug="0" scheme="https" secure="true"
    4. SSLEnabled="true" clientAuth="true" sslProtocol="TLS"
    5. keystoreFile="/full/path/to/tomcat.keystore" keystorePass="keystore_password" />

    APR 连接器

    Raw

    1. <Connector port="8443" maxThreads="200" scheme="https" secure="true" SSLEnabled="true"
    2. protocol="org.apache.coyote.http11.Http11AprProtocol"
    3. SSLCertificateFile="/usr/local/ssl/server.crt"
    4. SSLCertificateKeyFile="/usr/local/ssl/server.key"
    5. clientAuth="required" SSLProtocol="TLSv1"/>

    现在需要将服务器的公共证书安装到客户端的密钥库中,反之亦然,允许客户端和服务器在建立安全连接时正确地相互认证和信任:

    Raw

    1. # Export the Client’s Public Certificate and Import it in to the Server’s Keystore
    2. keytool -exportcert -alias {YourClientKeyAlias} -file {/path/to/your/Client/Certificate}.cer -keystore {YourClientKeystore}.jks -storepass {ChangeThis}
    3. keytool -importcert -keystore {YourServerKeystore}.jks -alias {YourClientCertAlias} -file {/path/to/your/Client/Certificate}.cer -storepass {ChangeThis} -noprompt
    4. # view the contents of the keystore (use -v for verbose output)
    5. keytool -list -keystore YourServerKeystore.jks -storepass {ChangeThis}
    6. # Export the Server’s Public Certificate and Import it in to the Client’s Keystore
    7. keytool -exportcert -alias {YourServerKeyAlias} -file {/path/to/your/Server/Certificate}.cer -keystore {YourServerKeystore.jks} -storepass {ChangeThis}
    8. keytool -importcert -keystore {YourClientKeystore}.jks -alias {YourServerCertAlias} -file {/path/to/your/Server/Certificate}.cer -storepass {ChangeThis} -noprompt
    9. # view the contents of the keystore (use -v for verbose output)
    10. keytool -list -keystore {YourClientKeystore}.jks -storepass {ChangeThis}
    11. keytool -importcert -keystore server.jks -alias clientcert -file client-public.cer -storepass ChangeThis! -noprompt
    12. # view the contents of the keystore (use -v for verbose output)
    13. keytool -list -keystore server.jks -storepass password

    诊断步骤

    您可以使用以下命令测试服务器的双向 SSL:

    Raw

    $ openssl s_client -connect TomcatHostnameOrIp:8443 -CAfile ServerCertificate.crt -cert ClientCertificate.crt -key ClientKeystore.key
    

    响应应为成功的 GET,如下所示:

    Raw

    1. GET /application/ HTTP/1.1
    2. Host:TomcatHostnameOrIp
  • 相关阅读:
    Android篇二:Android Studio使用Genymotion
    说完 Java 的 Abstract 后再来说说接口 (interface )
    局部刷新,例如,列表中只更新 收藏图标
    Ubuntu20.04安装pycharm
    Vue3种常用插槽的使用
    线程安全介绍
    Java基于SpringBoot的学生就业管理信息系统
    gici-open示例数据运行(1.1开阔环境数据运行)
    在字节跳动干软件测试5年,4月无情被辞,想给划水的兄弟提个醒
    拼凑硬币问题
  • 原文地址:https://blog.csdn.net/allway2/article/details/126571806