[爆卦]server憑證是什麼?優點缺點精華區懶人包

為什麼這篇server憑證鄉民發文收入到精華區:因為在server憑證這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!http://giayiu.adsldns.org/FreeBSD/CA.htm * 本文可以任意...

http://giayiu.adsldns.org/FreeBSD/CA.htm

* 本文可以任意轉載,但是請不要篡名。
* 有錯誤的地方,煩請告知,謝謝。

當你想為您的伺服器建立 SSL 連線時 (ex. web, smtp, pop3, imap ...),
您首先需要製作一些憑證給伺服器以及客戶端使用。

假如您不需要花錢去申請公正憑證中心所簽發的憑證 (ex. VeriSign ...),
您就可以使用如下的方式自行當做憑證中心簽發憑證給自行使用。

發行憑證流程:

1.使用者建立 Private Key,使用所建立的 Private Key 產生憑證申請書送至憑證中心。
2.憑證中心收到憑証申請書後,使用憑證中心的憑證對使用者的憑證申請書做簽名,
完成簽發憑證。


建立憑證都需要三個步驟:

1. 建立 Private Key。
2. 使用 Private Key 產生憑證申請書。
3. 為憑證申請書簽名做簽發憑證。


所以您需要:

‧產生根憑證 (Root CA)。(簽發伺服器憑證用。)

要先建立根憑證的 Private Key。
產生根憑證的申請書。
使用根憑證本身簽發根憑證。(因為您是憑證鍊的最高等級)
‧產生伺服器憑證。

建立伺服器憑證的 Private Key。
產生伺服器憑證的申請書。
使用根憑證簽發伺服器憑證。

‧在製作之前,有幾點要注意:

請自行更改所有的輸入、輸出檔名及路徑,放在 /usr/local/CA 是個不錯的選擇 。
所有的 Private Key 請妥善保存,不可外洩,
否則其它人可以冒名簽發憑證,或者解碼被加密的資料。
根憑證的 Private Key 在製作時請一定要設定密碼。(不用做伺服器憑證)
根憑證的憑證名稱 (Common Name) 請填上發行人或單位名稱 (ex. ISU CNA Root CA)。
(不用做伺服器憑證)
伺服器憑證的憑證名稱 (Common Name) 請填上主機的全名 (ex. mail.cna.isu.edu.tw)。
憑證申請書填寫方法請見作法之後說明。
日後需要重新簽發或者製做其它的伺服器憑證,
只需要重覆做產生伺服器憑證的動作就可以了。 (除非根憑證過期才需要重做根憑證。)
製作好的憑證在使用上可能會出現「憑證無效」、「憑證無法驗證」等的訊息。
因為這些憑證的簽發者不是客戶端所已知且被信任的,
所以您需要將 RootCA.crt 發散出去給需要用到這些憑證的使用者。
在 Internet Explorer 上,下載根憑證後開啟可以將憑證匯入系統之內,
日後此根憑證所簽發的憑證都會被信任。
注意:發散的是憑證檔 (.crt, ex. RootCA.crt),
不是 Private Key (.key, ex. RootCA.key) 檔。

‧根憑證 (Root CA) 作法:

‧建立根憑證的 Private Key

# 在此步驟請務必要設定密碼!
openssl genrsa -des3 -out RootCA.key 2048
# 讓其它人無法讀寫 Private Key 檔。
chmod og-rwx RooCA.key

‧產生根憑證的申請書

# 請參考後面所提供的範例,Common Name 請不要填 Hostname。
# (不用做伺服器憑證)
# 在這要輸入產生根憑證 Private Key 時所設定的密碼。
openssl req -new -key RootCA.key -out RootCA.req

‧使用根憑證本身簽發根憑證

# 在這要輸入產生根憑證 Private Key 時所設定的密碼。
# -days 設定根憑證的有效期限。(3650 ~= 十年)
openssl x509 -req -days 3650 -sha1 -extensions v3_ca \
-signkey RootCA.key -in RootCA.req -out RootCA.crt
# 刪除申請書。(憑證已經簽發完成)
rm -f RootCA.req


‧伺服器憑證作法:

‧建立伺服器憑證的 Private Key

# 伺服器憑證不設定密碼。(否則開機啟動時會停住要求使用者輸入密碼。)
openssl genrsa -out HostCA.key 2048
# 讓其它人無法讀寫 Private Key 檔。
chmod og-rwx HostCA.key

‧產生伺服器憑證的申請書

# 請參考後面所提供的範例,Common Name 請填上 Hostname。
openssl req -new -key HostCA.key -out HostCA.req

‧使用根憑證簽發伺服器憑證

# 在這要輸入產生根憑證 Private Key 時所設定的密碼。
# -days 設定根憑證的有效期限。(365 ~= 一年)
# CAserial 是憑證序號檔。
# CAcreateserial 是前面所指定的序號檔不在時自動建立之。
openssl x509 -req -days 365 -sha1 -extensions v3_req \
-CA RootCA.crt -CAkey RootCA.key -CAserial RootCA.srl -CAcreateserial \
-in HostCA.req -out HostCA.crt
# 刪除申請書。(憑證已經簽發完成)
rm -f HostCA.req

‧憑證申請書填寫方法

/usr/local/CA# openssl req -new -key RootCA.key -out RootCA.req
Enter pass phrase for RootCA.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
# 填入TW 代表 Taiwan
Country Name (2 letter code) [AU]:TW
# TW 的全名 Taiwan
State or Province Name (full name) [Some-State]:Taiwan
# 城市名
Locality Name (eg, city) []:Kaohsiung Country
# 組織名稱 (公司名稱)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:I-Shou University
# 單位名稱 (部門名稱)
Organizational Unit Name (eg, section) []:Campus Network Association
# 憑證名稱 (請注意先前所提到有關根憑證與伺服器憑證的注意事項)
Common Name (eg, YOUR name) []:CNA Root CA
# 填入連絡信箱
Email Address []:[email protected]

# 以下請都按 [Enter] 跳過,不需要用到。
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:



你可能也想看看

搜尋相關網站