当前位置: > Linux服务器 > Tomcat >

tomcat6.0+jdk1.6 ssl单向配置

时间:2015-02-02 16:31来源:linux.it.net.cn 作者:IT

1,通过jdk自带的keytool生成.keystore文件执行下面的命令:

 


 
  1. /usr/bin/keytool -genkey -alias xiaomaodan -keyalg RSA  -validity 36500  -keystore c:\keystore  
执行上面的命令后需要输入相关的证书信息

 

 


 
  1. Enter keystore password:    
  2. Re-enter new password:   
  3. What is your first and last name?  
  4.   [Unknown]:  localhost  
  5. What is the name of your organizational unit?  
  6.   [Unknown]:  shizhai  
  7. What is the name of your organization?  
  8.   [Unknown]:  shizhai  
  9. What is the name of your City or Locality?  
  10.   [Unknown]:  sz  
  11. What is the name of your State or Province?  
  12.   [Unknown]:  gd  
  13. What is the two-letter country code for this unit?  
  14.   [Unknown]:  cn  
  15. Is CN=shizihan, OU=shizhai, O=shizhai, L=sz, ST=gd, C=cn correct?  
  16.   [no]:  yes  
  17.   
  18. Enter key password for <xiaomaodan>  
  19.     (RETURN if same as keystore password):    
  20. Re-enter new password:   

 

注意:

注意事项:
A、Enter keystore password:此处需要输入大于6个字符的字符串
B、“What is your first and last name?”这是必填项,并且必须是TOMCAT部署主机的域名或者IP[如:gbcom.com 或者 10.1.25.251],就是你将来要在浏览器中输入的访问地址
C、“What is the name of your organizational unit?”、“What is the name of your organization?”、“What is the name of your City or Locality?”、“What is the name of your State or Province?”、“What is the two-letter country code for this unit?”可以按照需要填写也可以不填写直接回车,在系统询问“correct?”时,对照输入信息,如果符合要求则使用键盘输入字母“y”,否则输入“n”重新填写上面的信息
D、Enter key password for <tomcat>,这项较为重要,会在tomcat配置文件中使用,建议输入与keystore的密码一致,设置其它密码也可以
l  完成上述输入后,直接回车则在你在第二步中定义的位置找到生成的文件

 

E、"-validity 36500含义是证书有效期,36500表示100年,默认值是90

2 ,配置tomcat的server.xml文件,打开ssl的注释,并将生成的keystore文件拷贝到tomcat的conf目录

 


 
  1. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"  
  2.            maxThreads="150" scheme="https" secure="true"  
  3.            clientAuth="false" sslProtocol="TLS" keystoreFile="D:\soft\apache-tomcat-6.0.37\conf\。keystore" keystorePass="123456"/>  

 
  1. </pre>注意:keystoryFile:生成的keystore文件.keystorePass为生成keystore填入的password<p></p><p>3,配置web.xml文件,是应用程序的http请求自动转换到https</p><p></p><pre code_snippet_id="589187" snippet_file_name="blog_20150126_5_8919926" name="code" class="html"><security-constraint>   
  2.        <web-resource-collection >   
  3.               <web-resource-name >SSL</web-resource-name>   
  4.               <url-pattern>/*</url-pattern>   
  5.        </web-resource-collection>  
  6.                                
  7.        <user-data-constraint>   
  8.               <transport-guarantee>CONFIDENTIAL</transport-guarantee>   
  9.        </user-data-constraint>   
  10. </security-constraint>  


 

4,验证:在浏览器输入部署的应用地址:http://localhost:8081/361sky/,则浏览器端会自动跳转到 https://localhost:8443/361sky/

5,由于不是授信的证书机构颁发的证书,所以要把证书添加的受信任的根证书

8,再次访问后,浏览器地址栏的地址错误木有了

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容