1、環境搭建java
2、製做證書web
1.在c目錄下建立ca文件夾:c:\ca\文件用於存放咱們製做證書過程當中產生的文件。redis
打開cmd 輸入 apache
cd C:\Win32OpenSSL\bin
按enter執行tomcat
2.設置 OPENSSL_CONF:(不設置的話接下來的操做都會報錯)服務器
set OPENSSL_CONF=c:\[PATH TO YOUR OPENSSL DIRECTORY]\bin\openssl.cfg
3.建立製做根證書的私鑰文件:測試
openssl genrsa -out c:\ca\myCA.key
私鑰文件名爲myCA.key。spa
4.而後建立根證書:code
openssl req -x509 -new -key c:\ca\myCA.key -out c:\ca\myCA.cer -days 730
按enter執行,會要求輸入一些東西,按要求輸入就行(沒試過可不能夠不輸入直接enter),不能輸入中文,否則會是亂碼,根證書文件名爲myCA.cer。server
3、製做自簽名SSL證書(葉證書)
一、首先建立一個私鑰:
openssl genrsa -out c:\ca\server.key
私鑰文件名爲server.key。
二、而後建立CSR:
openssl req -new -out c:\ca\server.req -key c:\ca\server.key -subj /CN=xxx/CN=xxx/CN=localhost
這裏假設服務器的」xxxx」爲服務器ip地址如:192.168.2.1。輸出文件爲server.req。
三、而後用CSR 去建立SSL 證書:
openssl x509 -req -in c:\ca\server.req -out c:\ca\server.cer -CAkey c:\ca\myCA.key -CA c:\ca\myCA.cer -days 36500 -CAcreateserial -CAserial c:\ca\server.serial
這裏咱們假設有效期爲100年,輸出文件爲server.cer,序號文件爲server.serial(撤銷證書時使用)。
四、將.key 和.cer 文件導出爲.p12 證書:
openssl pkcs12 -export -in c:\ca\server.cer -inkey c:\ca\server.key -out ca:\ca\server.p12 -name "server"
根據命令提示,須要輸入兩次證書密碼。這裏咱們假設密碼爲1234。輸出文件名爲server.p12。
五、將.p12 文件導入到java keystore 中:
keytool -importkeystore -v -srckeystore c:\ca\server.p12 -srcstoretype pkcs12 -srcstorepass 123456 -destkeystore c:\ca\server.keystore -deststoretype jks -deststorepass 123456
這裏srcstorepass後面的123456爲server.p12的密碼,deststorepass後的123456爲keyStore的密碼(密碼不得少於6位)。
4、使用SSL證書
將最後獲得的keystore 文件(server.keystore) 放在web 服務器上。例如Tomcat 目錄的conf 目錄下。
而後修改server.xml:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" keystoreFile="C:/apache-tomcat-6.0.14/bin/conf/server.keystore" keystorePass="123456" clientAuth="false" sslProtocol="TLS" />
PS:protocal爲上面的提供的內容,tomcat默認內容有可能會出錯,注意keyStoreFile的路徑斜槓爲:」/」;
重啓Tomcat,
進入Tomcat的bin目錄:
a、 shutdown.bat
b、 startup.bat
經過如下地址訪問https 服務:https://localhost:8443/ 或者https://127.0.0.1:8443/。
若是看到了tomcat的歡迎頁則說明配置成功。
5、安裝證書
找到c:\ca\文件夾,複製到tomcat的webApp文件夾下
經過safari訪問路徑如:https://192.168.0.1:8843/c/myCA.cer,下載證書。
6、安裝ipa
把你配置好的ipa相關路徑所有改成https接口訪問,恭喜你,若是你沒出現沒法連接xxxx,或證書爲NULL,以內的警告,說明你就成功了。