1、tomcat相关配置
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" keystoreFile="D:/Java/apache-tomcat-7.0.62/conf/10.20.134.22.keystore"
keystorePass="123456" sslProtocol="TLS" />
2、项目相关配置(HTTPS访问资源可选)
<security-constraint>
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/index.jsp</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
上面这种配置方式对于限制的资源
|
浏览器访问 |
接口调用 |
HTTP |
服务器会返回302状态码要求浏览器重定向访问 |
接口没有自动重定向功能,调用失败 |
HTTPS |
正常访问 |
正常访问 |
对于非限制的资源,用HTTP方式和HTTPS方式都可以正常访问
3、验证方式
采用HTTPS单项验证,传输的数据加密过了,但是不会校验客户端的来源。双向验证服务端会对客户端的进行验证
为服务端生成证书:
keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/10.20.134.22.keystore -validity 36500
导出证书:
keytool -export -alias tomcat -file D:/filr.cer -keystore d:/10.20.134.22.keystore -validity 36500
导入证书:
keytool -import -alias tomcat -file d:/filr.cer -keystore d:/truststore
借鉴博客:
http://www.blogjava.net/stevenjohn/archive/2012/09/26/388600.html
http://xiaohuafyle.iteye.com/blog/1538719