SSL 與 CA(憑證授權伺服器)

    版本為 13:25, 6 Oct 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    說明

    憑證伺服器 - Certificate Authority (CA),這個伺服器可以用來建立加密連線所需的 Server 及 Root 憑證檔。

    對於商用服務的加密連線,通常會使用 Verisign 或其他第三方認證機構,來簽署需要的憑證檔,但這些需要定期付費,如果不想付費給這些機構做簽署,可以自己架設伺服器來建立及發行所需的憑證檔。

    CA 可以使用 Linux 或 Windows 來架設,此篇將以 Linux 為案例,Windows 用戶可以安裝 Windows 元件:Certificate Service。

    步驟開始

    主要檔案類型說明:

    檔案用途: 檔案類型:
     私密金鑰(Private Key)  xxx.key
     憑證簽署要求檔(CSR)  xxx.csr
     Server 憑證檔  xxx_SERVER.crt
     Root 憑證檔  xxx_ROOT.crt

     

    必要的套件:

    • openssl
    建立所需的目錄
    cd /etc/pki
    mkdir -m 0755 mypbxCA
    mkdir -m 0755 private certs newcerts crl 
    
    • mypbxCA 憑證工作的根目錄
    • private 私密金鑰檔儲存目錄
    • certs 憑證檔儲存目錄
    • newcerts 用來放 PEM 檔
    • crl 用來儲存已停用的憑證列表
    建立 openssl 設定檔
    cp /etc/pki/tls/openssl.cnf /etc/pki/mypbxCA/openssl.my.cnf
    chmod 0600 /etc/pki/mypbxCA/openssl.my.cnf
    touch /etc/pki/mypbxCA/index.txt
    echo '01' > /etc/pki/mypbxCA/serial 
    
    建立 CA(Root) 憑證 及 Private key

    假設 FQDN 是 this.is.my.host

    cd /etc/pki/mypbxCA
    openssl req -config openssl.my.cnf -new -x509 -extensions v3_ca -keyout private/this-is-my-host_ROOT.key -out certs/this-is-my-host_ROOT.crt -days 1825 
    

    Enter PEM pass phrase: <輸入一組密碼>
    ...
    ... <隨便輸入>

    Common Name (eg, your name or your server's hostname) []: <這裡一定要輸入正確的 FQDN>

    憑證的期限可設定為五年

    執行完後,會產生兩個檔案

    1. private/this-is-my-host_ROOT.key 私密金鑰,需妥善保存且已設有密碼
    2. certs/this-is-my-host_ROOT.crt 這是 ROOT 憑證檔,可以公開讓用戶下載
    修改 openssl 設定檔

    編輯 /etc/pki/mypbxCA/openssl.my.cnf:

    [ CA_default ]
    
    dir             = .             # 改這行 <==
    certs           = $dir/certs            # Where the issued certs are kept
    crl_dir         = $dir/crl              # Where the issued crl are kept
    database        = $dir/index.txt        # database index file.
    #unique_subject = no                    # Set to 'no' to allow creation of
                                            # several ctificates with same subject.
    new_certs_dir   = $dir/newcerts         # default place for new certs.
    
    certificate     = $dir/certs/this-is-my-host_ROOT.crt      # 改這行 <==
    serial          = $dir/serial           # The current serial number
    crlnumber       = $dir/crlnumber        # the current crl number
                                            # must be commented out to leave a V1 CRL
    crl             = $dir/crl.pem          # The current CRL
    private_key     = $dir/private/this-is-my-host_ROOT.key # 改這行 <==
    RANDFILE        = $dir/private/.rand    # private random number file
    
    建立一個 Server 憑證

    新增一個憑證簽署要求檔(CSR)

    cd /etc/pki/mypbxCA
    openssl req -config openssl.my.cnf -new -nodes -keyout private/this-is-my-host_SERVER.key -out this-is-my-host.csr -days 365 
    

    Common Name:<必須是正確的 FQDN>

    A challenge password []: <這裡不要輸入密碼,否則服務會無法自動重啟>

    憑證期限可以設定為一年

    執行完後,會產生兩個檔案

    1. private/this-is-my-host_SERVER.key
    2. this-is-my-host.csr Server 憑證簽署要求檔(CSR)
       

    設定權限

    chown root:asterisk /etc/pki/mypbxCA/private/this-is-my-host_SERVER.key
    chmod 0440 /etc/pki/mypbxCA/private/this-is-my-host_SERVER.key 

    簽署(發行)剛剛建立的 CSR 檔

    cd /etc/pki/mypbxCA
     

    Using configuration from openssl.my.cnf
    Enter pass phrase for ./private/this-is-my-host_ROOT.key: <這裡要輸入 CA 金鑰的密碼,如果密碼不正確將無法完成簽署>

    Powered by MindTouch Core