iT邦幫忙

DAY 26
8

關於IT資訊界的筆記和學習紀錄系列 第 35

SSL憑證設定(上)

一、 SSL介紹
安全套接層(Secure Sockets Layer,SSL)是網景公司(Netscape)在推出Web瀏覽器首版的同時,提出的協議。SSL採用公開密鑰技術,保證兩個應用間通信的保密性和可靠性,使客戶與伺服器應用之間的通信不被攻擊者竊聽。可在伺服器和客戶機兩端同時實現支持,目前已成為網際網路上保密通訊的工業標準,現行Web瀏覽器亦普遍將Http和SSL相結合,從而實現安全通信。此協議和其繼任者傳輸層安全(Transport Layer Security,TLS)是為網路通信提供安全及數據完整性的一種安全協議。TLS與SSL在傳輸層對網路連接進行加密。
二、 SSL設定說明
安裝SSL時,openssl 一定要安裝最新版本,stable版本。(請依當時的最新版本安裝)
SSL 官網 查最新的SSL http://www.openssl.org/source/
完成以上軟體的安裝後, 我們便可開始進行憑證申請及安裝, 其程序大致如下:

  1. 產製金鑰對
  2. 產生憑證申請檔
  3. 購買SSL憑證(或自行產生)
  4. 安裝憑證
  1. 安裝OPENSSL

    [root@localhost ~]# wget http://www.openssl.org/source/openssl-0.9.8q.tar.gz [root@localhost ~]# tar zxvf openssl-0.9.8q.tar.gz
    [root@localhost ~]# cd openssl-0.9.8q
    [root@localhost ~]# ./config
    [root@localhost ~]# make
    [root@localhost ~]# make install

  2. 設定OpenSSL 設定檔的位置
    2.1 先把要用的資料夾建立好

    [root@localhost ~]# mysql -u root -p cacti < pa.sql
    [root@localhost ~]# mkdir /etc/ssl
    [root@localhost ~]# cp /etc/pki/tls/openssl.cnf /etc/ssl/.
    [root@localhost ~]# cd /etc/ssl
    [root@localhost ~]# mkdir private
    [root@localhost ~]# mkdir certs
    [root@localhost ~]# mkdir crl
    [root@localhost ~]# mkdir newcerts
    [root@localhost ~]# touch index.txt
    [root@localhost ~]# export OPENSSL_CONF="/etc/ssl/openssl.cnf"

2.2 修改openssl.cnf設定

[root@localhost ~]# vi /etc/ssl/openssl.cnf 
#把這行
dir	 = ../../CA	 # Where everything is kept
#改為
dir	 = /etc/ssl	 # Where everything is kept

#把這行
countryName_default = GB 
#改為 
countryName_default = TW

2.3 把 OpenSSL 設定檔的位置加進 .bashrc 中

[root@localhost ~]# echo "export OPENSSL_CONF=\"/etc/ssl/openssl.cnf\"" >> ~/.bashrc

2.4 產生亂數的檔案

[root@localhost ~]# openssl rand 1024 > /etc/ssl/private/.rand
[root@localhost ~]# chmod og-rwx /etc/ssl/private/.rand

以上準備好後,可以開始製作Root CA

  1. 製作Root CA
    退出 shell 重新登入root
    我們要做的Root CA 為winners.ca ,如果之前有做過的話,現在再做一次,之前簽的憑證都會失效。
    3.1 建立憑證密碼

    [root@localhost ~]# openssl genrsa -des3 -out /etc/ssl/private/faq.ca.key 1024
    #此時必須為最高層認證中心的 Private Key 設定一個適當的密碼,以後在用這把Private Key簽發#其它憑證時,都需要用到這個密碼。
    #參數說明:
    genrsa 表示使用 RSA 演算法產製金鑰\r
    -des3 表示使用 DES3 加密演算法
    -out mykeys.key 表示輸出的檔案為何, 檔名及路徑可自定
    1024 表示金鑰對長度為 1024 (建議使用)
    % 您可以另外使用 openssl genrsa ? 看其全部的參數\r
    Enter PEM pass phrase: (請在此輸入金鑰對密碼)
    [root@localhost ~]# chmod og-rwx /etc/ssl/private/faq.ca.key

3.2 接著填寫憑證申請
跟誰申請?因為是Root CA ,沒有上級了,所以就是跟自己申請。

[root@localhost ~]#  openssl req -new -key /etc/ssl/private/faq.ca.key -out  /tmp/faq.ca.req 
#參數說明: 
req 表示要產生 CSR 檔 
-new 新的檔案 
-key mykeys.key 金鑰對檔案的路徑及檔名 
-out mysite.key 所產生的 CSR 檔案的路徑及檔名 
接著, 會出現 Enter PEM pass phrase: (請輸入先前設定好的密碼)

3.3 填入資料

Country Name (2 letter code) [TW]:TW                       #請用兩個英文字元表示
State or Province Name (full name) [Taiwan]:Taiwan         #省份名稱
Locality Name (eg, city) [Newbury]:Taipei                  #城市名稱
Organization Name (eg, company) [My Company Ltd]:FAQ-BOOK  #(公司名稱) 
Organizational Unit Name (eg, section) []:CA               #部門名稱
Common Name (eg, your name or your server's hostname) []:blog.faq-book.com
#網址名稱, 即公用名稱, 您要使用 SSL 加密的站台名稱
Email Address []:derek@faq-book.com  #網站管理者的email address

此外, 尚有一些 extra 的資料, 您可不理會, 直接按 Enter 過去即可, 最後即可產生 faq.ca.crt 檔

3.4 自己給自己簽名

[root@localhost ~]# openssl x509 -req -days 7305 -sha1 \-extfile /etc/ssl/openssl.cnf -extensions v3_ca \-signkey /etc/ssl/private/faq.ca.key \-in /tmp/faq.ca.req -out /etc/ssl/certs/faq.ca.crt

3.5 刪除憑證申請書

[root@localhost ~]# rm -f /tmp/faq.ca.req

SSL憑證設定(下)
全文同步於FAQ-BOOK
IT鐵人文章分享


上一篇
Linux DNS(BIND)安裝與設定(上)
下一篇
SSL憑證設定(下)
系列文
關於IT資訊界的筆記和學習紀錄41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言