最近要替 IIS 更新 Let’s Encrypt 三個月期限的憑證,發現使用快半年的 FreeSSL 突然不能申請了(請參閱:SSL For Free 多域名(Multi-Domin SSL Certificate)要收費,改用FreeSSL.cn解決流程分享),會一直跳出「acme: urn:ietf:params:acme:error:badPublicKey: sa.StorageAuthority.KeyBlocked timed out after 5000 ms」錯誤訊息,看起來是這個平台已經有問題無法申請,這些平台最終還是以收費為主。
後來小編還是認真研究了一下 向 Let’s Encrypt 註冊免費的 SSL/TLS 憑證輔助工具(網址:ACME Client Implementations),基本上任何工具只要實作 ACME(Automatic Certificate Management Environment)協定,就可以順利的向 Let’s Encrypt 組織申請到為期 3 個月的免費 SSL/TLS 憑證,當然其中也可以包含萬用子網域憑證。
沒錯小編這次要講兩個方法解決萬用子網域憑證申請方式,因為畢竟大部分介紹都是單一網域來說明!先來說這個以 Let’s Encrypt 官網推薦的 Certbot 工具,分享完整的 Let’s Encrypt 申請與在 IIS上設定步驟!
小編的使用環境:
- Windows Server 2008 R1 SP1
- IIS 7.5
- 兩個網域,各有 3~4 子域名皆都需要憑證
1. 請到 Certbot 官網於下方說明,在https://dl.eff.org/certbot-beta-installer-win32.exe下載適用於 Windows 的最新版本安裝檔。(因為小編來不及擷取安裝畫面,所以後面都是以文字敘述)
2. 下載完成後直接執行安裝,很簡單的下一步下一步就可以完成,且也會自動設定好 PATH 環境變數,也就是說接下來用命令提示字元( Command Prompt )操作時,就不用特別切換到安裝目錄了。
3. 以系統管理員身份執行開啟命令提示字元(或 PowerShell 命令列視窗)。
4. 先測試一下 Certbot,執行:
certbot –version
certbot -h
5. 準備好你要申請的域名(注意:要有權限可以控管該域名的 DNS),小編因為在同台主機上有兩個不同的域名,且都需要萬用子網域!就以 abc.com.tw、test.net 兩個域名為例來說明。
6. 請輸入以下命令同時產生 abc.com.tw、test.net 兩個萬用子網域憑證
certbot certonly –manual -m youremail@example.com -d *.abc.com.tw -d *.test.net
7. 接著就是「互動式」的方式完成設定,顯示偵錯紀錄檔的路徑與要你輸入 y 同意服務使用條款
Saving debug log to C:\Certbot\log\letsencrypt.log
Plugins selected: Authenticator manual, Installer None
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
(Y)es/(N)o: y
8. 問你是不是要提供 E-mail 給 Electronic Frontier Foundation (EFF) 做註冊使用?這個步驟會將你的 E-mail 自動註冊為 ACME 帳戶!
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let’s Encrypt project and the non-profit organization that
develops Certbot? We’d like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
(Y)es/(N)o: y
Account registered.
9. 發出憑證請求,下面訊息很清楚的說明完成 dns-01、dns-02 驗證,得通過驗證才能「證明」你真的擁有該域名。
Requesting a certificate for *.abc.com.tw and *.test.net
Performing the following challenges:
dns-01 challenge for abc.com.tw
dns-02 challenge for test.net
10. 這裡其實他一共有兩種驗證方式,一個是http 網站連結方式驗證,另一個是 DNS 域名驗證。要特別說明的是若你是申請跟小編一樣萬用子網域憑證的,又或者你的網站還沒有上線,沒有對外的網站連結的話,都只能使用 DNS 域名驗證喔!所以前面才會提到要有 DNS 控制權限!這個跟之前透過 SSL For Free 和 Freedns.cn 申請時一樣!
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Please deploy a DNS TXT record under the name
_acme-challenge.abc.com.tw with the following value:
GY_prmhxrXuRBbw3G76hn_2WJKdey1w0dHkk7-bhg7
Before continuing, verify the record is deployed.
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Press Enter to Continue
11. 看到上面的說明就是要到 DNS 域名管理上設定新增一筆 TXT 紀錄到 _acme-challenge.abc.com.tw 的域名上,並將其值設定為 GY_prmhxrXuRBbw3G76hn_2WJKdey1w0dHkk7-bhg7,然後按下 Enter 繼續。
12. 免費憑證申請成功,並顯示憑證檔路徑,Certbot 還會幫你訂閱一個 EFF mailing list 郵件清單,並提示你憑證 PEM 檔案所在路徑與憑證到期日:
Waiting for verification…
Cleaning up challenges
Subscribe to the EFF mailing list (email: youremail@example.com).
IMPORTANT NOTES:
– Congratulations! Your certificate and chain have been saved at:
C:\Certbot\live\abc.com.tw\fullchain.pem
Your key file has been saved at:
C:\Certbot\live\abc.com.tw\privkey.pem
Your certificate will expire on 2022-02-22. To obtain a new or
tweaked version of this certificate in the future, simply run
certbot again. To non-interactively renew *all* of your
certificates, run “certbot renew”
– If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
13. OK!我們就可以從 C:\Certbot\live\abc.com.tw 目錄看到產生的憑證檔案清單:
14. 接著將產生的這份 TLS/SSL 憑證到 IIS 就必須再產生 PFX (PKCS#12) 憑證檔案才能安裝,這個之前 SSL For Free 有教過(可以去參考這篇:使用 SSL For Free 產生 Let’s Encrypt SSL 憑證上傳給 IIS 站台使用),小編就不特別在這邊說明!直接在 Command 用 OpenSSL 工具產生 PFX 憑證檔,命令如下(請先確認你自己安裝的 Openssl 路徑):
C:\Program Files\OpenSSL-Win64\bin>openssl.exe pkcs12 -export -out “certificate_combined.pfx” -inkey “privkey.pem” -in “cert.pem” -certfile “fullchain.pem”
15. 接著輸入產生 PFX 憑證檔密碼,到時匯入憑證時才能用!在相同目錄下應該就會看到 certificate_combined.pfx 檔案,就可以匯入到 IIS 憑證管理員裡面囉!到這邊應該就大功告成。另外這個產生 PFX 憑證檔若你日後有配合工作排程來達到自動產生的話,也可以透過批次檔來用,範例如下:
SET PASSWORD=QaWsEdRf
“\Program Files\OpenSSL-Win64\bin\openssl.exe” pkcs12 -export -out “G:\certificate_combined.pfx” -inkey “privkey.pem” -in “cert.pem” -certfile “fullchain.pem” -password “pass:%PASSWORD%”
做個筆記,避免日後需要!後面還有個方式在 Windows Server IIS 平台上非常的方便!小編另一篇分享。