配置httpd-2.2支持https功能

SSL會話的簡化過程html

     (1) 客戶端發送可供選擇的加密方式,並向服務器請求證書;數據庫

     (2) 服務器端發送證書以及選定的加密方式給客戶端;vim

     (3) 客戶端取得證書並進行證書驗正:瀏覽器

      若是信任給其發證書的CA:bash

         (a) 驗正證書來源的合法性;用CA的公鑰解密證書上數字簽名;服務器

         (b) 驗正證書的內容的合法性:完整性驗正ide

         (c) 檢查證書的有效期限;測試

         (d) 檢查證書是否被吊銷;ui

         (e) 證書中擁有者的名字,與訪問的目標主機要一致;加密

     (4) 客戶端生成臨時會話密鑰(對稱密鑰),並使用服務器端的公鑰加密此數據發送給服務器,完成密鑰交換;

     (5) 服務用此密鑰加密用戶請求的資源,響應給客戶端;

    

注意:SSL會話是基於IP地址建立;因此單IP的主機上,僅能夠使用一個https虛擬主機;



配置httpd支持https:


一、爲服務器申請數字證書;

1)建立私有CA
    
(1)生成私鑰文件

1
2
3
4
5
6
7
8
9
[root@wlm ~] # mkdir -p /etc/pki/CA/private    #建立私鑰保存的目錄
[root@wlm ~] # (umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
Generating RSA private key, 4096 bit long modulus
....................................................................++
..................................................................++
e is 65537 (0x10001)
[root@wlm ~] # ll /etc/pki/CA/private/ # 私鑰只能本身保存,對保密性要求高
總用量 4
-rw-------. 1 root root 3243 11月 15 10:34 cakey.pem

    (2)生成自簽證書

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@wlm ~] # openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3650
# 若是是自請自籤 加-x509 若是不是就不用加了
#這個過程會自動從剛纔第一步的私鑰中抽取公鑰
#-new 生成新證書籤署請求
#-x509 生成自籤格式證書 專用於建立私有CA時
#-key 生成請求時用到的私有文件路徑
#-out 生成的請求文件路徑 若是是自籤操做將生成簽署過的證書
#-days 證書的有效時常 但爲是day 
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.
-----
Country Name (2 letter code) [XX]:CN     #國家
State or Province Name (full name) []:SH     #省
Locality Name (eg, city) [Default City]:SH     #城市
Organization Name (eg, company) [Default Company Ltd]:DZH     #公司組織
Organizational Unit Name (eg, section) []:Ops     #職位
Common Name (eg, your name or your server's  hostname ) []:ca.wlm.com     #主機名
Email Address []:mail@wlm.com     #郵箱

    (3)爲CA提供所需的目錄和文件

1
2
3
4
5
6
7
8
9
10
11
[root@wlm ~] # touch /etc/pki/CA/index.txt # 建立數據庫文件
[root@wlm ~] # echo 01 > /etc/pki/CA/serial # 建立序列號文件並給明第一個證書的序列號碼
[root@wlm ~] # ll /etc/pki/CA
總用量 8
-rw-r--r--. 1 root root 2049 11月 15 10:41 cacert.pem
drwxr-xr-x. 2 root root    6 6月  29 2015 certs
drwxr-xr-x. 2 root root    6 6月  29 2015 crl
-rw-r--r--. 1 root root    0 11月 15 10:45 index.txt
drwxr-xr-x. 2 root root    6 6月  29 2015 newcerts
drwx------. 2 root root   22 11月 15 10:34 private
-rw-r--r--. 1 root root    3 11月 15 10:46 serial

    至此,私有CA建立完畢。

2)證書申請:    

   (1)在證書申請的主機上生成私鑰

1
2
3
4
5
6
7
8
9
10
11
[root@wlm ~] # cd /etc/httpd/
[root@wlm httpd] # mkdir ssl    #建立保存私鑰的目錄
[root@wlm httpd] # cd ssl
[root@wlm ssl] # (umask 077;openssl genrsa -out httpd.key 2048) #生成私鑰
Generating RSA private key, 2048 bit long modulus
......................................................+++
...........................................+++
e is 65537 (0x10001)
[root@wlm ssl] # ll
總用量 4
-rw-------. 1 root root 1675 11月 15 11:05 httpd.key

   (2)生成證書籤署請求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@wlm ssl] # openssl req -new -key httpd.key -out httpd.csr -days 365 # 在本地生成
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.
-----
Country Name (2 letter code) [XX]:CN      
State or Province Name (full name) []:SH
Locality Name (eg, city) [Default City]:SH
Organization Name (eg, company) [Default Company Ltd]:DZH
Organizational Unit Name (eg, section) []:Ops    
Common Name (eg, your name or your server's  hostname ) []:www.wlm.com
Email Address []:mail.wlm.com
 
Please enter the following  'extra'  attributes
to be sent with your certificate request
A challenge password []:      #密碼能夠不設置
An optional company name []:

  (3)把請求發送給CA

1
2
3
4
5
6
7
8
[root@wlm ssl] # scp httpd.csr root@10.10.10.3:/tmp/ # 10.10.10.3位CA主機
# 將請求籤發的證書發個證書服務器,咱們這裏是同一臺機器模擬了證書服務器和申請簽發的客戶機
The authenticity of host  '10.10.10.3 (10.10.10.3)'  can't be established.
ECDSA key fingerprint is 93:b6:c3:bf:a6:51:a7:4a:be:0c:14:93:ab:86:a1:56.
Are you sure you want to  continue  connecting ( yes /no )?  yes
Warning: Permanently added  '10.10.10.3'  (ECDSA) to the list of known hosts.
root@192.168.208.130's password: 
httpd.csr                                           100% 1025     1.0KB /s    00:0

  (4)CA簽發證書(在CA10.10.10.3主機上操做)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[root@wlm tmp] # openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
# 簽發證書,有效期爲一年
Using configuration from  /etc/pki/tls/openssl .cnf
Check that the request matches the signature
Signature ok
Certificate Details:
         Serial Number: 1 (0x1)
         Validity
             Not Before: Nov 15 03:15:54 2016 GMT
             Not After : Nov 15 03:15:54 2017 GMT
         Subject:
             countryName               = CN
             stateOrProvinceName       = SH
             organizationName          = DZH
             organizationalUnitName    = Ops
             commonName                = www.wlm.com
             emailAddress              = mail.wlm.com
         X509v3 extensions:
             X509v3 Basic Constraints: 
                 CA:FALSE
             Netscape Comment: 
                 OpenSSL Generated Certificate
             X509v3 Subject Key Identifier: 
                 49:7A:99:41:6E:72:27:8F:B8:F0:C3:77:6C:B8:8B:C0:9F:C7:7D:2A
             X509v3 Authority Key Identifier: 
                 keyid:A8:28:9A:3B:91:A9:4C:90:A4:08:3D:79:34:0D:D3:19:0E:68:6F:1A
 
Certificate is to be certified  until  Nov 15 03:15:54 2017 GMT (365 days)
Sign the certificate? [y /n ]:y
 
 
1 out of 1 certificate requests certified, commit? [y /n ]y
Write out database with 1 new entries
Data Base Updated
[root@wlm tmp] # cd /etc/pki/CA/
[root@wlm CA] # ls
cacert.pem  crl        index.txt.attr  newcerts  serial
certs       index.txt  index.txt.old   private   serial.old
[root@wlm CA] # cat index.txt    #查看第一個簽發的證書
V   171115031554Z       01  unknown  /C =CN /ST =SH /O =DZH /OU =Ops /CN =www.wlm.com /emailAddress =mail.wlm.com

  (5)把簽署好的證書發還給請求者

1
2
3
4
5
6
7
8
[root@wlm CA]
[root@wlm CA] # pwd
/etc/pki/CA
[root@wlm CA] # scp certs/httpd.crt root@10.10.10.4:/etc/httpd/ssl/ # 發送證書
root@192.168.208.130's password: 
httpd.crt                                           100% 5781     5.7KB /s    00:00    
[root@wlm CA] # ls /etc/httpd/ssl/
httpd.crt  httpd.csr  httpd.key  root@192.168.208.130     # 查看已經簽發好的證書



二、配置httpd支持使用ssl,及使用的證書;

(1)安裝支持ssl的模塊

[root@wlm CA]# yum install -y mod_ssl

(2)修改配置文件

vim /etc/httpd/conf.d/ssl.conf
<VirtualHost _default_:443>
DocumentRoot "/var/www/html"
ServerName www.wlm.com:443
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key


(3) 測試基於https訪問相應的主機;

重啓httpd服務以後經過瀏覽器驗證

wKioL1gzpafBcI5aAAXezTF0FwU724.jpg

關於httpd的配置,見http://afterdawn.blog.51cto.com/7503144/1873617

openssl詳解見:http://afterdawn.blog.51cto.com/7503144/1872753

相關文章
相關標籤/搜索