1、生成证书
使用JDK自带的工具keytool,命令行如下:
keytool -genkey -alias keystore -keypass 123456 -keyalg RSA -keystore thekeystore
输入密钥库口令(123456),输入名字与姓氏为具体路由地址,其余的根据具体情况填写即可,然后就会在当前目录下生成证书。
2、导出数字证书
keytool -export -alias keystore -keystore thekeystore -rfc -file cas.crt
输入先前的密钥库口令,生成具体的cas.crt数字证书。
3、将数字证书导入jdk下的jre里
keytool -import -alias keystore -keystore %JAVA_HOME%\jre\lib\security\cacerts -file cas.crt -trustcacerts -storepass keystore2022
导入JDK时需要默认密码keystore2022,在命令中已经配置好了。如果没有该密码,则会报java.io.IOException: Keystore was tampered with, or password was incorrect错误。
4、配置DNS
用管理员身份修改C:\Windows\System32\drivers\etc\hosts文件,添加映射地址:
127.0.0.1 sso.itlearning.vip
5、配置Tomcat
编辑Tomcat目录Conf下的server.xml文件。
将8443的端口配置文件打开,配置如下(添加前面刚刚生成的keystore的地址和密匙):
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="C:\Users\yawpe\keystore\thekeystore"
type="RSA" certificateKeystoreType="JKS" certificateKeystorePassword="123456"/>
</SSLHostConfig>
</Connector>