1,通过jdk自带的keytool生成.keystore文件执行下面的命令:
/usr/bin/keytool -genkey -alias xiaomaodan -keyalg RSA -validity 36500 -keystore c:\keystore
执行上面的命令后需要输入相关的证书信息
Enter keystore password: Re-enter new password: What is your first and last name? [Unknown]: localhost What is the name of your organizational unit? [Unknown]: shizhai What is the name of your organization? [Unknown]: shizhai What is the name of your City or Locality? [Unknown]: sz What is the name of your State or Province? [Unknown]: gd What is the two-letter country code for this unit? [Unknown]: cn Is CN=shizihan, OU=shizhai, O=shizhai, L=sz, ST=gd, C=cn correct? [no]: yes Enter key password for <xiaomaodan> (RETURN if same as keystore password): 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目录
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="D:\soft\apache-tomcat-6.0.37\conf\。keystore" keystorePass="123456"/>
</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> <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>
4,验证:在浏览器输入部署的应用地址:http://localhost:8081/361sky/,则浏览器端会自动跳转到 https://localhost:8443/361sky/
5,由于不是授信的证书机构颁发的证书,所以要把证书添加的受信任的根证书
8,再次访问后,浏览器地址栏的地址错误木有了