由于配置CAS的单点登陆系统,需要先配置
Tomcat 的SSL, 在配置tomcat的SSL过程中,我配置的版本是tomcat5.5.20,参考了很多资料,但发现一直不行,后来我换到了5.5.9,结果非常顺利, 我于是换了总共4个主要版本,发现SSL的配置还真有些不同,现在我将这些配置记录下来,供下次参考。
参考文档
Keytool
使用指南:
Tomcat-ssl
配置指南:
配置过程
1. 生成 server key :
以命令行方式切换到目录%TOMCAT_HOME%,在command命令行输入如下命令(jdk1.4以上带的工具):
keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass changeit -keystore server.keystore -validity 3600
用户名输入域名,如localhost(开发或测试用)或hostname.domainname(用户拥有的域名),其它全部以 enter 跳过,最后确认,此时会在%TOMCAT_HOME%下生成server.keystore 文件。
注:参数 -validity 指证书的有效期(天),缺省有效期很短,只有90天。
2. 将证书导入的JDK的证书信任库中:
这步对于T omcat的SSL配置不是必须,但对于CAS SSO是必须的,否则会出现如下错误:edu.yale.its.tp.cas.client.CASAuthenticationException: Unable to validate ProxyTicketValidator。。。
导入过程分2步,第一步是导出证书,第二步是导入到证书信任库,命令如下:
keytool -export -trustcacerts -alias tomcat -file server.cer -keystore server.keystore -storepass changeit
keytool -import -trustcacerts -alias tomcat -file server.cer -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit
如果有提示,输入Y就可以了。
其他有用keytool命令(列出信任证书库中所有已有证书,删除库中某个证书):
keytool -list -v -keystore D:/sdks/jdk1.5.0_11/jre/lib/security/cacerts
keytool -delete -trustcacerts -alias tomcat -keystore D:/sdks/jdk1.5.0_11/jre/lib/security/cacerts -storepass changeit
3. 配置TOMCAT :
修改%TOMCAT_HOME%\conf\server.xml,以文字编辑器打开,查找这一行:
xml 代码
将之后的那段的注释去掉,并加上 keystorePass及keystoreFile属性。
注意, tomcat 不同版本配置是不同的:
Tomcat4.1.34 配置:
xml 代码
-
- < Connector className = "org.apache.coyote.tomcat4.CoyoteConnector"
- port = "8443" enableLookups = "true" scheme = "https" secure = "true"
- acceptCount = "100"
- useURIValidationHack = "false" disableUploadTimeout = "true"
- clientAuth = "false" sslProtocol = "TLS"
- keystoreFile = "server.keystore"
- keystorePass = "changeit" />
Tomcat5.5.9 配置:
xml 代码
-
- < Connector port = "8443" maxHttpHeaderSize = "8192"
- maxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
- enableLookups = "false" disableUploadTimeout = "true"
- acceptCount = "100" scheme = "https" secure = "true"
- clientAuth = "false" sslProtocol = "TLS"
- keystoreFile = "server.keystore"
- keystorePass = "changeit" />
Tomcat5.5.20 配置 ( 此配置同样可用于 Tomcat6.0) :
xml 代码
-
- < Connector protocol = "org.apache.coyote.http11.Http11Protocol"
- port = "8443" maxHttpHeaderSize = "8192"
- maxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
- enableLookups = "false" disableUploadTimeout = "true"
- acceptCount = "100" scheme = "https" secure = "true"
- clientAuth = "false" sslProtocol = "TLS"
- keystoreFile = "server.keystore"
- keystorePass = "changeit" />
Tomcat6.0.10 配置:
xml 代码
- < Connector protocol = "org.apache.coyote.http11.Http11NioProtocol"
- port = "8443" minSpareThreads = "5" maxSpareThreads = "75"
- enableLookups = "true" disableUploadTimeout = "true"
- acceptCount = "100" maxThreads = "200"
- scheme = "https" secure = "true" SSLEnabled = "true"
- clientAuth = "false" sslProtocol = "TLS"
- keystoreFile = "D:/tools/apache-tomcat-6.0.10/server.keystore"
- keystorePass = "changeit" />