Install AlwaysOnSSL Cert on IIS

Introduction

AlwaysOnSSL 為一家提供免費、自動化 SSL 憑證的德國公司,如同 Let’s Encrypt 般一樣讓使用者可免費申請、註冊 SSL 憑證,但其提供的 SSL 憑證有效期限為一年 (Let’s Encrypt 為三個月)。

而 AlwaysOnSSL 其簽發的檔案為 pem,無法直接在 IIS 主機上使用,故本篇紀錄一下申請後如何透過 OpenSSL 轉換憑證為 pfx 供 IIS 使用。

Preparation

  • Website Domain(網站域名)

Steps

Install OpenSSL

由於接下來的操作大多會使用到 OpenSSL,因此建議先安裝 OpenSSL,若為 Windows 使用者可先將程式路徑加入環境變數方便操作,若為 Ubuntu 使用者可鍵入以下指令以安裝 OpenSSL:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 解壓縮檔案
$ sudo tar -zxvf openssl-1.0.2o.tar.gz
$ cd openssl-1.0.2o/

# 設定安裝路徑
$ sudo ./config --prefix=/usr/local --openssldir=/usr/local/openssl

# 建立安裝檔案
$ sudo make

# 檢查安裝檔案
$ sudo make test

# 安裝 openssl
$ sudo install

安裝完成後,輸入 openssl version 可顯示版本,輸入 which openssl 可顯示安裝路徑。

Create CSR File

透過 AlwaysOnSSL 申請 SSL 時需要主機的 CSR 檔案,可以透過 CSR Generator 網站產生憑證或利用 OpenSSL 指令產生(Ubuntu 須加上 sudo 權限執行):

1
2
3
4
5
6
7
8
9
# 建立資料夾
$ mkdir ~/blog.holey.cc/
$ cd ~/blog.holey.cc/

# 建立 RSA file
$ openssl genrsa -out cert.key 2048

# 建立 CSR file
$ openssl req -new -sha256 -key cert.key -out cert.csr

Apply SSL Certificate

申請 SSL 憑證流程則可參考以下連結:

Transform Certificate

若為 Windows Server 用戶,由於 IIS 僅支援 pfx 憑證。因此在完成申請憑證後,需下載 PKCS#7 檔案(*.p7b),並鍵入以下指令透過 .key 與 .p7b 轉換為 .pfx:

1
2
$ sudo openssl pkcs7 -print_certs -in cert.p7b -out cert.cer
$ sudo openssl pkcs12 -export -in cert.cert -inkey cert.key -out cert.pfx

References