Quantcast
Channel: Hiraku Dev
Viewing all articles
Browse latest Browse all 241

弄個自簽名 HTTPS SSL 網站憑證並安裝到 iOS

$
0
0

因為最近要測試一個本地開發的網站,該網站強制必須使用 SSL 連線,然後我又要用 iOS 測試 RWD …搞半天終於搞定可以讓 iOS 信任的 HTTPS SSL 自簽名憑證。

寫一下英文關鍵字方便其他人迷路的時候可以搜尋到吧。

How to make a self-signed HTTP SSL certification and install it to iOS

先建立 ssl.conf 檔案,內容如下,DNS 裡面可以新增或修改為自己的域名

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = api.localhost.dev
DNS.2 = admin.localhost.dev
DNS.3 = app.localhost.dev
IP.1 = 127.0.0.1

 

再執行下面指令。請不要自作聰明改掉 390 這個數字。因為 2020 年 9 月之後系統不會信任到期日 13 個月以上的憑證,所以如果你抄太久以前的網站教學,一次簽十年那種,就會搞半天然後一直翻車不成功。

openssl req -x509 -nodes -new -sha256 -days 390 -newkey rsa:2048 -keyout "RootCA.key" -out "RootCA.pem" -subj "/C=TW/CN=localhost.dev"
openssl x509 -outform pem -in "RootCA.pem" -out "RootCA.crt"

openssl req -new -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "/C=TW/ST=Tawian/L=City/O=Organization/CN=localhost.local"
openssl x509 -req -sha256 -days 390 -in server.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile ssl.conf -out server.crt

之後會產生兩個 crt,分別是 root.crt 跟 server.crt,把這兩個檔案分別 AirDrop 進去 iPhone 裡面,然後安裝憑證。最後再去設定的 一般 → 關於本機 → 憑證信任設定 裡面把開關打開就可以了。

這篇文章 弄個自簽名 HTTPS SSL 網站憑證並安裝到 iOS 最早出現於 Hiraku Dev


Viewing all articles
Browse latest Browse all 241

Trending Articles