生成证书
keytool -genkey -alias cas -keyalg RSA -keystore cas.keystore
CN的名字必须和cas server的域名一直。比如localhost。这里证书密码为test1234。
导出证书
keytool -export -file cas.crt -alias cas -keystore cas.keystore
导入证书到JRE
keytool -import -keystore "${jdk_path}\jre\lib\security\cacerts" --file cas.crt -alias cas
执行需要管理者权限,Windows下需要以“管理者”运行cmd。
tomcat的 server.xml 的配置
<!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<Connector protocol="org.apache.coyote.http11.Http11NioProtocol"
port="8443" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="${user.home}/.keystore" keystorePass="test1234"
/>
问题一:keytoolエラー: java.lang.Exception: 鍵ペアは生成されませんでした。別名はすでに存在します
解决方法: 执行 keytool -delete -alias <别名>
问题二: 运行时异常java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 的处理
根据下面方法生成,导出,导出证书到JRE
1. 删除 %JRE_HOME%/lib/security/cacerts
生成证书
keytool -genkey -alias tomcat -keyalg RSA -keystore ~/Documents/keys/tomcat导出证书
keytool -export -file ~/Documents/keys/tomcat.crt -alias tomcat -keystore ~/Documents/keys/tomcat导入证书
sudo keytool -import -keystore /usr/lib/jvm/jdk1.6.0_22/jre/lib/security/cacerts -file ~/Documents/keys/tomcat.crt -alias tomcat
参考:http://steven-wiki.readthedocs.io/en/latest/security/cas-tomcat/