1.生成tomcat.keystore 密鑰文件;
keytool -keysize 2048 -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore
然後會提示輸入DNS 信息及密碼:
Enter keystore password: 設置一個用於保護你keystore文件的密碼,例如123456
Re-enter new password: 重複上面的密碼
What is your first and last name?
[Unknown]: yourdomain.com 輸入你網站的域名,注意Godaddy的證書一個只能簽名一個域名,也就是說 baidu.com 和 www.baidu.com 不是同一個域名,這裏應該填寫你準備簽名的那一個域名。
What is the name of your organizational unit?
[Unknown]: Networking 組織單位名稱(隨便)
What is the name of your organization?
[Unknown]: yourdomain.com 組織名稱(隨便)
What is the name of your City or Locality?
[Unknown]: Guangzhou 所在城市(隨便)
What is the name of your State or Province?
[Unknown]: Guangdong 所在省份(隨便)
What is the two-letter country code for this unit?
[Unknown]: CN 所在國家的兩位代號(隨便)
Is CN=www.yourdomain.com, OU=Networking, O=yourdomain.com, L=Shenzhen, ST=Guangdong, C=CN correct?
[no]: yes 以上信息正確則輸入yes
Enter key password for
(RETURN if same as keystore password): 輸入前面的keystore 密碼
2.使用keytool 通過tomcat.keystore 生成csr文件,csr.csr 是csr的文件,提前的csr 名稱可以自定義;
keytool -certreq -keyalg RSA -alias tomcat -file csr.csr -keystore tomcat.keystore
3.官方申請證書;
進入到GoDaddy的ssl證書管理界面,根據提示進入輸入 CSR 的頁面,用文本編輯器打開剛纔生成的 csr.csr 文件,把裏面的文本內容複製粘貼到頁面的表單裏即可。SSL 證書商會根據你的域名發送一封驗證郵件到域名註冊者的Email(所以你要提前注意你的域名註冊的Email地址是什麼,如果是錯誤的話需要先修正,否則收不到驗證Email)。這個過程可能需要幾分鐘或者幾小時,收到驗證Email之後點擊裏面的鏈接地址就完成私鑰簽名了;
4.
將官方生成的證書導入到 tomcat.keystore 裏面;
登錄到你購買 SSL 的證書商,下載你的網站已簽名的證書文件,在 GoDaddy 裏你下載會得到一個壓縮包,裏面放有(domain.crt,gd_bundle-g2-g1.crt,gdig2.crt)
導入的流程順序:根證書,中級證書,個人證書;
我所下載的包裏面包含:(f91dc12f8b1fb94e.crt,gd_bundle-g2-g1.crt,gdig2.crt)
所以根證書是:gd_bundle-g2-g1.crt 中級證書:gdig2.crt 個人證書:f91dc12f8b1fb94e.crt
請注意:在默認安裝證書時,到最後安裝個人證書會提示:keytool error: java.lang.Exception: Failed to establish chain from reply
解決方法:原因是官方下載的根證書與中級證書可能是過期,你到它的repository裏找到對應名稱的根證書下載覆蓋
5.導入證書:
keytool -import -alias root -keystore tomcat.keystore -trustcacerts -file gd_bundle-g2-g1.crt
keytool -import -alias intermed -keystore tomcat.keystore -trustcacerts -file gdig2.crt
keytool -import -alias tomcat -keystore tomcat.keystore -trustcacerts -file f91dc12f8b1fb94e.crt
6.tomcat 配置server.xml ,先在tomcat 目錄下面新建一個ssl 文件夾存放tomcat.keystore 文件
<Connector port="8443" maxThreads="200" protocol="org.apache.coyote.http11.Http11NioProtocol"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile="/usr/local/tomcat/tomcat.keystore" keystorePass="xxx"
clientAuth="false" sslProtocol="TLS"/>
7.啓動tomcat,添加防火牆端口,測試