create https chain certificate for test

因為要測自己家的 SSL VPN 所以上次複習了一次怎麼申請憑證和設定,但是因為自家的設備三不五時改版就要測一下,免費的測試憑證有效期大概三個月左右 (上次測試是找 Comodo 申請的),而且過程也不見得容易 (Comodo 要 domain 管理者 email 確認,所以我又自己架了 mail server 來收信),然後就開始研究怎麼自己簽中繼憑證。

  1. 首先編輯系統的 openssl.cnf,或是自己生一份。把裡面的 v3_ca 部分 keyUsagensCertType 的註解拿掉
  2. 接著用老方法產生一個自簽憑證當作 Root CA
    openssl req -x509 -nodes -newkey rsa:2048 -days 999 -keyout root.key -out root.crt
    # CN的地方可以填像是 Root CA 之類的方便辨認
  3. 接著用剛剛產生的 Root CA 簽一份自己的中繼憑證
    openssl req -nodes -newkey rsa:2048 -days 999 -keyout cert1.key -out cert1.csr
    # CN 的地方可以填像是 Class 1 CA 之類的
    openssl x509 -req -in cert1.csr -extfile openssl.cnf -extensions v3_ca -CA root.crt -CAkey root.key -CAcreateserial -out cert1.crt
    # -extfile 後面接的是 openssl.cnf 的位置,請自行更換
  4. 最後才是產生 server 要用的憑證
    openssl req -nodes -newkey rsa:2048 -days 999 -keyout server.key -out server.csr
    # 這個 CN 一定要填和 SSL 設備的 domain name 或是 IP 相同,不然瀏覽器會跳出警告
    openssl x509 -req -in server.csr -CA cert1.crt -CAkey cert1.key -CAcreateserial -out server.crt
  5. 最後把 server.keyserver.crt 放上 SSL 設備,把 root.crtcert1.crt 放在一個檔案 (ex.chain.crt) 也在設備上設定好,最後在 client 端安裝 root.crt 然後打開 SSL 設備試試看
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.