tomcat实现SSL配置

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0cm; margin-bottom:.0001pt; text-align:center; mso-pagination:none; tab-stops:center 207.65pt right 415.3pt; layout-grid-mode:char; border:none; mso-border-bottom-alt:solid windowtext .75pt; padding:0cm; mso-padding-alt:0cm 0cm 1.0pt 0cm; font-size:9.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} p.MsoFooter, li.MsoFooter, div.MsoFooter {margin:0cm; margin-bottom:.0001pt; mso-pagination:none; tab-stops:center 207.65pt right 415.3pt; layout-grid-mode:char; font-size:9.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} span.style71 {mso-style-name:style71;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:1309479251; mso-list-template-ids:-1839971966;} @list l0:level1 {mso-level-tab-stop:36.0pt; mso-level-number-position:left; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

tomcat 实现 SSL 配置  

编辑 tomcat 的配置文件 server.xml ,去掉下面 SSL Connector 的注释 , 修改为如下:
  <!-- Define an SSL HTTP/1.1 Connector on port 8443 -->

  <Connector className="org.apache.catalina.connector.http.HttpConnector"
          port="8443" minProcessors="5" maxProcessors="75"
          enableLookups="true"
    acceptCount="10" debug="0" scheme="https" secure="true">
    <Factory className="org.apache.catalina.net.SSLServerSocketFactory"
          clientAuth="false" keystoreFile="tomcat.keystore"
          keystorePass="tomcat" protocol="TLS"/>
  </Connector>
keystoreFile 的路径是 TOMCAT 的安装路径下的 tomcat.keystore( 使用 keytool 生成的证书库文件 )
>keytool -genkey -alias tomcat -keyalg RSA -keysize 1024 -validity 365 -keystore tomcat.keystore
keystoreFile
保存了服务器端的证书库,用于客户端认证。

常用的配置属性:
clientAuth
如果想要 Tomcat 为了使用这个 socket 而要求所有 SSL 客户出示一个客户证书,置该值为 true  
keystoreFile
如果创建的 keystore 文件不在 Tomcat 认为的缺省位置(一个在 Tomcat 运行的 home 目录下的叫 .keystore 的文件),则加上该属性。可以指定一个绝对路径或依赖 $CATALINA_BASE 环境变量的相对路径。
keystorePass
如果使用了一个与 Tomcat 预期不同的 keystore (和证书)密码,则加入该属性。  
keystoreType
如果使用了一个 PKCS12 keystore ,加入该属性。有效值是 JKS PKCS12  
sslProtocol
socket
使用的加密 / 解密协议。如果使用的是 Sun JVM ,则不建议改变这个值。据说 IBM 1.4.1 版的 TLS 协议的实现和一些流行的浏览器不兼容。这种情况下,使用 SSL  
ciphers
socket 允许使用的被逗号分隔的密码列表。缺省情况下,可以使用任何可用的密码。  
algorithm
使用的 X509 算法。缺省为 Sun 的实现( SunX509 )。对于 IBM JVMS 应该使用 ibmX509 。对于其它 JVM ,参考 JVM 文档取正确的值。  
truststoreFile
用来验证客户证书的 TrustStore 文件。  
truststorePass
访问 TrustStore 使用的密码。缺省值是 keystorePass  
truststoreType
如果使用一个不同于正在使用的 KeyStore TrustStore 格式,加入该属性。有效值是 JKS PKCS12  


使用 https://localhost:8443  就可以进行 ssl 连接的检测

----------------------------------------------------------------------------------------
上诉的 SSL 连接是客户端单向认证服务器,如果双向认证,将 server.xml 文件的 Connector 配置
clientAuth="false" 

Java
服务器端的证书库,服务器认证客户端时使用的根证书库。

证书库位置: JAVA_HOME/jre/lib/security/cacerts keystore 密码为 :changeit

将客户端个人证书的根证书导入服务器的证书库,就可以认证客户端。

服务器端证书的生成:

>keytool -genkey -alias tomcat -keyalg RSA -keysize 1024 -validity 365 -keystore tomcat.keystore
>keytool -certreq -alias tomcat -file Server.csr -keystore tomcat.keystore 
生成证书请求文件

使用 openssl 命令用根证书签名 , 再导入签名证书

>keytool -import -trustcacerts -alias tomcat -file Server.pem -keystore tomcat.keystore

注意 -trustcacerts 选项,使用服务器的证书库认证该证书,首先要将根证书导入 cacerts 中。

----------------------------------------------------------------------------------------
Tomcat
配置 SSL ,我出现的问题

我用 openssl 创建了 CA 证书, Server 证书, Client 证书。
使用 keytool Server 证书导入 tomcat.keystore 文件中 , Tomcat 的配置文件 server.xml 关于 SSL 的配置设为 keystoreFile=tomcat.keystore.SSL 连接时,客户端认证 tomcat.keystore 中的服务器证书。
CA 证书导入 $JAVA_HOME/jre/lib/security/cacerts 这个 keystore 中,用于验证客户端证书。
IE 中安装 CA 证书和 Client 证书 (pkcs12, 包含私钥的个人证书形式 )
建立 SSL 连接 https://localhost:8443, 连接失败。

经过反复思量,知道问题所在, SSL 连接时 , 客户端认证服务器时,需要验证服务器的签名,那么 tomcat.keystore 中就应该有 Server 的私钥。所以导入 Server 证书时,应该导入包含私钥的 Server 证书。
keytool 命令不能导入私钥文件,可以通过在 keystore 中生成自签名证书,导出证书请求,用 CA 证书签名后,在导回的方法。
导回签名证书的过程
>keytool -import -trustcacerts -alias tomcat -file Server.pem -keystore tomcat.keystore
注意 -trustcacerts 选项,使用服务器的证书库认证该证书,首先要将根证书导入 Java 的根证书库中 :JAVA_HOME/jre/lib/security/cacerts 中。

----------------------------------------------------------------------------------------

分析 IE 实现实现 SSL 连接的中的证书双向认证过程
在地址栏中输入 https://localhost:8443
客户端向服务器发送 hello 消息, tomcat 服务器侦听 8443 端口,收到 SSL 连接的 hello 消息,服务器发送 server certificate ,并且发送 client certificate request. 客户端 IE 收到 server certificate 后取出 issuer 项,和 IE 受信任的根证书库中证书的 subject 比对,找到合适的根证书认证 server certificate 。并且同时向服务器发送 client certificate ,服务器收到 client certificate 后, tomcat 服务器查找根证书库 cacerts 中的根证书的 suject ,找到合适的根证书认证 client certificate. 在认证的同时完成密钥协商。客户端认证结束后, IE 会弹出 " 安全警报 " 对话框,用户可以查看服务器证书,以及服务器证书是否受信任,可以选择是否继续 SSL 连接。

地震让大伙知道:居安思危,才是生存之道。
用心专研技术,用实际行动尽一份绵力吧!

 

为Jboss/tomcat 配置Yale-CAS( 一) 证书和SSL

环境信息:

jdk1.5

jboss 4.0.3sp1

cas-server-3.2.1.1-release

cas-client-2.0.11

1. 生成证书:

 

写道

一条命令建立keystore
keytool -genkey -keyalg RSA -keysize 512 -dname "CN=pso.cas.server,O=infolab,C=cn,L=infolab,S=Hangzhou,OU=pso" -alias pso -keypass 123456 -keystore e:/alfred/cas/pso.keystorefile -storepass 123456 -validity 365
逐个输入域名组织等信息来建立keystore
keytool -genkey -alias pso -keyalg RSA -keypass 123456 -storepass 123456 -keystore pso.keystorefile -validity 3600

 

注: -dname 信息注解
CN:
域名或 IP ,这里一定需要服务器的域名,而不能是ip ,
(测试环境下你可以自己造一个域名,并在C:/WINDOWS/system32/drivers/etc/host(linux:/etc/hosts ) 文件中加入映射:192.168.10.1 cas.server
OU:
部门,没有部门的可不要此项 O: 单位名称 L: 单位地址 S: 省份的拼音 C: 国家的简写( CN 代表中国)

2. 配置服务端jboss/tomcate ssl 并指定对应的keystore

找到jboss/tomcateserver.xml 文件(jboss:D:/jboss-4.0.3SP1/server/default/deploy/jbossweb-tomcat55.sar/)

Xml 代码

  1. <Connector port="8443" address="${jboss.bind.address}"  
  2.            maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"  
  3.            emptySessionPath="true"  
  4.            scheme="https" secure="true" clientAuth="false"   
  5.            keystoreFile="e:/xxxx/xxxx.keystorefile"             
  6.            keystorePass="123456"   
  7.            sslProtocol = "TLS" />  

<Connector port="8443" address="${jboss.bind.address}"

           maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"

            emptySessionPath="true"

           scheme="https" secure="true" clientAuth="false"

           keystoreFile="e:/xxxx/xxxx.keystorefile"          

           keystorePass="123456"

           sslProtocol = "TLS" />

 

3. 导出证书

写道

keytool -export -keystore pso.keystorefile -alias pso -file pso.cert

 

4. pso.cert 导入java 信任证书库

写道

keytool -import -trustcacerts -alias tomcat_pso -file pso.cert -keypass changeit -keystore "%JAVA_HOME%/jre/lib/security/cacerts"

 

注:%JAVA_HOME%/jre/lib/security/cacertsjava 自带的证书库,默认密码为changeit

写道

keytool -list -v -keystore c:/jdk15/jre/lib/security/cacerts ( 列出信任库中已经存在的证书)
keytool -delete -trustcacerts -alias tomcat -keystore c:/jdk15/jre/lib/security/cacerts -storepass changeit(
删除某一个证书)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值