###
##自簽名證書
##配置Apache服務器SSL
##自己作為CA簽發證書
###這里是OpenSSL和HTTPS的介紹
開啟HTTPS
配置前提是已在Mac上
搭建Apache
服務器 →Mac上Apache
服務器搭建
先在桌面創建個SSL文
件夾,用來放生成的私鑰證書文件 打開終端cd
到SSL
文件夾
cd desktop/SSL
#1. 自簽名證書
(1) 在SSL文件夾中生成私鑰
openssl genrsa -out server.key 2048
生成rsa
私鑰,2048
位強度,server.key
是秘鑰文件名 (2) 生成自簽名證書
openssl req -new -sha256 -x509 -days 365 -key server.key -out server.crt
輸入信息
Common Name
應該與域名保持一致(如我的電腦搭建的服務器IP
地址為10.100.152.185
)
#2. 配置Apache服務器SSL
(1) 放入證書
將server.crt
和server.key
兩個文件拷貝 放到/etc/apache2/
目錄
(2) 修改配置文件
編輯/etc/apache2/httpd.conf
文件 找到去掉下面前邊的注釋#號
LoadModule ssl_module libexec/apache2/mod_ssl.so
Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/httpd-ssl.conf
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so
打開/etc/apache2/extra/httpd-ssl.conf
文件 去掉以下兩項注釋並檢查是否與之前安裝私鑰和證書的路徑一致 (默認已打開)
SSLCertificateFile "/private/etc/apache2/server.crt"
SSLCertificateKeyFile "/private/etc/apache2/server.key"
編輯/etc/apache2/extra/httpd-vhosts.conf
文件 在<VirtualHost *:80> .....</VirtualHost>
后面添加一段如下內容:
<VirtualHost *:443>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /private/etc/apache2/server.crt
SSLCertificateKeyFile /private/etc/apache2/server.key
ServerName 10.100.152.185
DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>
注意ServerName
填寫域名與所需訪問一致
(3) 重啟服務器
sudo apachectl restart
訪問https://10.100.152.185/
提示不安全什么的(因為自己的證書沒添加到瀏覽器信任列表),繼續訪問
#3. 自己作為CA簽發證書
(1) 生成CA
根證書
其實就是自簽名證書
先在桌面的SSL
文件夾里創建個CA
文件夾,用來存放放自己作為CA生成的私鑰證書文件 打開終端cd到CA文件夾
cd desktop/SSL/CA
私鑰
openssl genrsa -des3 -out ca.key 4096
這里使用-des3
進行加密,需要四位以上密碼
證書
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
按1自簽名證書流程,得到ca.key
和ca.crt
(2 )創建服務器私鑰
openssl genrsa -out server.key 4096
(3) 生成證書請求文件CSR
openssl req -new -key server.key -out server.csr
此時已得到如下4個文件
(4) 自己作為CA簽發證書
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -days 365
然后需要輸入生成ca.key時設置的密碼
如果遇到這個問題
用/System/Library/OpenSSL/oppenssl.cnf
替換目錄中的/private/etc/ssl/openssl.cnf
文件
I am unable to access the ./demoCA/newcerts directory ./demoCA/newcerts: No such file or directory
解決方法 沒有目錄創造目錄也要上 執行以下幾條命令創建所需的目錄及文件
mkdir -p ./demoCA/newcerts
touch demoCA/index.txt
touch demoCA/serial
echo 01 > demoCA/serial
創建好所需目錄及文件
重新執行命令
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -days 365
輸入ca.key
密碼 然后會打印出證書詳細進行確認
輸入兩次y
得到最終生成的所有文件
所有生成文件 圖示server.crt
即自己作為CA
簽發的服務器證書
(5)測試
*測試1 CA生成服務器證書可用性: (1)前往/etc/apache2/
文件夾
(2)刪除原來自簽名證書兩個文件 (3)發現https://10.100.152.185/
已經不能訪問(能訪問有可能是緩存,可以刷新或重啟Apache) (4)將CA生成的server.key
和server.crt
兩個文件拷貝進去 (5)https://10.100.152.185/
又可以訪問成功
*測試2 CA根證書可用性: (1)新打開https://10.100.152.185/
,由於自己的CA根證書未在信任列表,會有警告 (2)雙擊ca.crt安裝(我這里使用的是Mac電腦) (3)到鑰匙串訪問,找到安裝的證書,右鍵點擊 → 顯示簡介 → 設置始終信任 (4)發現https://10.100.152.185
不再警告
*手機安裝必須
(5)手機安裝ca.crt證書,使用自帶的mail郵箱發送證書到手機上面安裝。
*提示無法連接‘XXXXXX'
最后把plist放到github上 點擊raw
預覽得到地址
itms-services:///?action=download-manifest&url=https://raw.githubusercontent.com/Blavtes/IPALoadConfig/master/manifest.plist
可以正常下載安裝。(需要app打包證書支持。)
*提示服務器證書 無效,可能因為ipa 地址路徑不對,檢查mainfest.plist 中ipa地址
*注意: itms-services:后面是三個“ / ”,千萬別漏掉一個!!!
#(6)如何獲取mainfest.plist文件
在xcode
->organizer
-> archives
下選擇已打包好的文件,導出ipa包。選擇development(開發者模式、也可替換為企業證書打包模式),填寫APPURL 。 appURL 為支持https服務器上ipa包地址
生成的plist 放到服務器。這里放到github。https服務器為本地環境
#制作html web下載文件
<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<body style="background:#CDE; color:#FFF">
<a href="itms-services:///?action=download-manifest&url=https://raw.githubusercontent.com/Blavtes/IPALoadConfig/master/GjFax/manifest-my.plist">
<div style="margin-top:30px;">
<center>
<font size="10" color="#3789dd" style="padding-left:0pt;">ios-集成下載 </font>
</center>
</div>
</a>
//可加個二維碼
<div style="margin-top: 100px">
<center>
<img src="https://github.com/Blavtes/IPALoadConfig/blob/master/GjFax/AppIcon57x57.png?raw=true" width="200" />
</center>
</div>
</body>
</html>
至此結束web下載安裝app測試版本。(👏👏👏👏👏)