1. 程式人生 > >cas 單點登陸實戰-sso-config篇(四)

cas 單點登陸實戰-sso-config篇(四)

本篇章繼續講解寫cas時遇到的坑------證書生成。

在window下的證書生成,在linxu下的cas證書生成,證書用域名,證書用ip

糾正一點,網上說的cas證書生成只能用域名是錯誤的。也是可以用ip的,親測有效。

1.在windows下的證書生成(域名)

注意:CN=域名,我們採用passport.sso.com

keytool -genkeypair -keyalg RSA -keysize 2048 -sigalg SHA1withRSA -validity 36500 -alias passport.sso.com -keystore d:/tomcat.keystore -dname "CN=passport.sso.com,OU=kawhi,O=carl,L=GuangZhou,ST=GuangDong,C=CN"

輸入上述命令,下面密碼我們輸入changeit,然後一直回車,就在d盤生成了tomcat.keystore檔案;

在cmd下輸入如下命令,密碼為上面輸入的changeit:keytool -exportcert -alias passport.sso.com -keystore d:/tomcat.keystore -file d:/tomcat.cer -rfc

輸入密碼為 changeit並同意匯入:keytool -import -alias passport.sso.com -keystore %JAVA_HOME%\jre\lib\security\cacerts -file d:/tomcat.cer -trustcacerts

2.在linxu下的證書生成(域名)

其實和在windows上的一樣,只需要改一下地址就可以了。進入你伺服器上的jdk的bin目錄,之後執行上述步驟就可以了。

3.在linxu或者windows下的證書生成(ip)

keytool -genkeypair -keyalg RSA -keysize 2048 -sigalg SHA1withRSA -validity 36500 -alias 172.17.1.10 -keystore /opt/jdk1.8.0_151/bin/tomcat.keystore -dname "CN=172.17.1.10,OU=kawhi,O=carl,L=GuangZhou,ST=GuangDong,C=CN" -ext san=ip:172.17.1.10


keytool -exportcert -alias 172.17.1.10 -keystore /opt/jdk1.8.0_151/bin/tomcat.keystore  -file /opt/jdk1.8.0_151/bin/tomcat.cer -rfc


keytool -import -alias 172.17.1.10 -keystore /opt/jdk1.8.0_151/jre/lib/security/cacerts -file /opt/jdk1.8.0_151/bin/tomcat.cer -trustcacerts

發現了嗎?其實只是在第一句證書後加上了-ext san=ip:172.17.1.10這個而已,問題就可以解決了。