tomcat配置双向认证,客户端证书pkcs12格式,方便导入浏览器

来源:互联网 发布:中易智联软件多少钱 编辑:程序博客网 时间:2024/04/30 12:26

1.生成证书   pkcs12  别名很重要

keytool -genkeypair -v -alias clientKey -keyalg RSA -storetype PKCS12 -validity 3650 -keystore  G:\ca\client.p12 

2.导出cer证书   

注意 由于pkcs12格式不能直接导入证书库,所以需要转换成.cer证书

keytool -export -alias clientKey -keystore G:\ca\client.p12 -storetype PKCS12 -storepass a123456 -rfc -file G:\ca\client.cer

红色密码为 中的证书密码

3.让服务器信任此证书

keytool -import -v -file G:\ca\client.cer -keystore G:\ca\struststore.keystore -storepass 123456 

此密码为 服务器配置可信任证书的密码

双向认证时:需要将client.p12 证书导入浏览器中。

注意:

如果为web服务,需要将下面代码加入到web.xml中,防止客户用http访问

<login-config>

<auth-method>CLIENT-CERT</auth-method>

<realm-name>Client cert Users-only Area</realm-name>

</login-config>

<security-constraint> 

<web-resource-collection>

<web-resource-name>SSL</web-resource-name>

<url-pattern>/*</url-pattern>

</web-resource-collection>

<user-data-constraint>

<transport-guarantee>CONFIDENTIAL</transport-guarantee>

</user-data-constraint>

</security-constraint>


Tomcat-6.0.26  server.xml配置:


<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="true" sslProtocol="TLS"
keystoreFile="G:\sslbotyway\server\kserver.jks" keystorePass="11961677"
truststoreFile="G:\trutstore.keystore" truststorePass="123456"
/>


文中所使用证书下载地址:

http://download.csdn.net/detail/xk_11961677/5283674


原创粉丝点击