Tomcat SSL 设置

时间:2021-01-03 04:30:36

1. 先用如下命令生成tomcat 证书

 cls 

 rem please set the env JAVA_HOME before run this bat file
SET JAVA_HOME=C:\Programs\Java\jdk1..0_51
SET PATH=%PATH%;%JAVA_HOME%/bin rem delete alias tomcat if it is existed
keytool -delete -alias tomcatsso -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit REM DELETE existing tomcatsso certified book
keytool -delete -alias tomcatsso -storepass changeit rem list all alias in the cacerts
REM List ALL certified in certified warehouse
keytool -list -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit rem generator a key
REM use RSA algorithm, generate a certified with name=tomcatsso, password=changeit
REM certified DN= cn=locahost, please make sure the DN = the host name
keytool -genkey -keyalg RSA -alias tomcatsso -dname "cn=localhost" -storepass changeit rem export the key
REM expoert the certified from keystore, generate tomcatsso.crt file
keytool -export -alias tomcatsso -file %JAVA_HOME%/jre/lib/security/tomcatsso.crt -storepass changeit REM import into trust cacerts, generate tomcatsso.crt file
REM import the tomcatsso.crt INTO JRE trusted certified warehouse, make sure the jre dir is the same as the jre which used by Tomcat, or Tomcat will not able to find the Certified
keytool -import -alias tomcatsso -file %JAVA_HOME%/jre/lib/security/tomcatsso.crt -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit rem list all alias in the cacerts
keytool -list -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit

2.After the script run complete, verify the certificate generated correctly

(1) check there is a tomcatsso.crt in your %JAVA_HOME%\jre\lib\security

(2) check there is a .keystore in your C:\Documents and Settings\YOUR_USERNAME

3.在Eclipse 中的配置tomcat

保证启动tomcat的jdk是刚才用于生成证书的jdk

Tomcat SSL 设置

(2) 编辑Server.XML, 加入keystore和CA 证书

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
keystoreFile="C:/Documents and
Settings/e527051/.keystore" keystorePass="changeit"      
truststoreFile="C:/Programs/Java/jdk1.6.0_22/jre/lib/security/cacerts"

clientAuth="false" sslProtocol="TLS" />

(3) 用8443端口打开应用

https://localhost:8443/ewusu-network

https://localhost:8443/ewusu-engine

下一篇文章讲解如何使用jasig cas在Tomcat中设置single sign on