Linux實現https方式訪問站點

一:SSL會話的簡化過程

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

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

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

         如果信任給其發證書的CA:

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

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

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

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

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

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

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

注意:SSL會話是基於IP地址創建;所以單IP的主機上,僅可以使用一個https虛擬主機

二:配置httpd支持https

(1) 爲服務器申請數字證書;

     測試:通過私建CA發證書

          (a) 創建私有CA

          (b) 在服務器創建證書籤署請求

          (c) CA簽證

    (2) 配置httpd支持使用ssl,及使用的證書;

     # yum -y install mod_ssl

     配置文件:/etc/httpd/conf.d/ssl.conf

          DocumentRoot

          ServerName

          SSLCertificateFile

          SSLCertificateKeyFile

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

         # openssl s_client [-connect host:port] [-cert filename] [-CApath directory] [-CAfile filename]

三: 實驗過程:

       (1)創建CA證書

        #(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

        #touch /etc/pki/CA/index.txt

        #echo 01 >/etc/pki/CA/serial    

        #openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out cacert.pem -days 7300

        //切換到httpd服務主機

        #mkdir /etc/httpd/certs

        #(umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)

        #openssl req -new -x509 -key -out /etc/httpd/ssl/httpd.csr 

        //證書文件發送到CA主機

        #scp /etc/httpd/ssl/httpd.csr [email protected]:/tmp

        #openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/www.zenghui.wang.crt -days 365

        #scp  /etc/pki/CA/certs/www.zenghui.wang.crt 199.100.77.135:/etc/httpd/certs



針對Apache httpd軟件默認配置中:

httpd軟件默認沒有使用ssl模塊,需要安裝相應的模塊程序包

[root@www certs]# yum install mod_ssl -y

[root@www ~]# rpm -qa mod_ssl

mod_ssl-2.2.15-39.el6.centos.x86_64

安裝之後會在/etc/httpd/conf.d/目錄下生成ssl.conf的配置文件,我們配置https就在此文件中配置:

配置ssl.conf文件,重要配置都在下面文件中了:

[root@www conf.d]#vim  /etc/httpd/conf.d/ssl.conf

LoadModule ssl_module modules/mod_ssl.so

Listen 443

<VirtualHost 172.16.31.31:443>

         DocumentRoot"/web/vhosts/www2"

         ServerName www2.stu31.com:443

         SSLEngineon

         SSLCertificateFile /etc/httpd/certs/httpd.crt

         SSLCertificateKeyFile /etc/httpd/certs/httpd.key

</VirtualHost>

測試文件語法:

[root@www conf.d]# httpd -t

Syntax OK

重啓httpd服務

[root@www conf.d]# service httpd restart

Stopping httpd:                                           [  OK  ]

Starting httpd:                                           [  OK  ]

查看服務監聽端口:

[root@www conf.d]# ss -tunl |grep 443

tcp   LISTEN     0      128                   :::443                  :::*

windows端進行測試:

先將CA服務器的證書安裝進windows中;將cacert.pem發送到windows中,改名cacert.crt,安裝證書:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章