Overview

OpenSSL 是一個 TLS 和 SSL 的跨平台工具包,可以用來產生可信賴的 SSL/TLS 自簽憑證。

Installation

<aside> 💡 安裝完成後可以使用 openssl version 查看版本確定是否成功。

</aside>

Usage

建立憑證

  1. 首先建立 ssl.conf 設定檔,填入以下內容。

    [req]
    prompt = no
    default_md = sha256
    default_bits = 4096
    distinguished_name = dn
    x509_extensions = v3_req
    
    [dn]
    C = TW
    ST = Taiwan
    L = Taipei
    O = Support
    OU = Self-signed certificate
    emailAddress = [email protected]
    CN = localhost: Self-signed certificate
    
    [v3_req]
    subjectAltName = @alt_names
    
    [alt_names]
    DNS.1 = *.localhost
    DNS.2 = localhost
    IP.1 = 192.168.0.43
    
  2. 透過 OpenSSL 命令產生出自簽憑證與相對應的私密金鑰

    openssl req -x509 -new -nodes -days 3650 -keyout key.pem -out cert.pem -config ssl.conf
    
  3. 將產生出私密金鑰 (key.pem) 與憑證檔案 (cert.pem),兩者皆為使用 PEM 格式。

安裝 ( 匯入 ) 憑證

由於憑證屬於自簽憑證,因此還需要將憑證加入到設備的「受信任的根憑證授權單位」中,這樣子當設備看到這張憑證時才會將憑證視為「可信任的連線」。

Reference

/docs/man3.0/man1/openssl-req.html

The Will Will Web

[譯]通過HTTPS協議執行你的Flask程式