https搭建

https

 

          http over ssl = https 443/tcp

                ssl: v3

                tls: v1

                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]

                openssl CA配置部分詳解

                ]# vim /etc/pki/tls/openssl.cnf

                [ CA_default ]

                dir             = /etc/pki/CA           # Where everything is kept                  默認工作目錄,數據存儲目錄

                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/cacert.pem       # The CA certificate                        自己的證書

                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/cakey.pem# The private key                           自己私鑰存放路徑

                RANDFILE        = $dir/private/.rand    # private random number file

                x509_extensions = usr_cert              # The extentions to add to the cert         

主機ip:192.168.8.98

        創建私有CA

        ]# cd /etc/pki/CA/

        ]# ls

        certs  crl  newcerts  private

        (1) 創建所需要的文件

        ]# touch index.txt

        ]# echo 01 > serial

        ]# ll

        total 20

        drwxr-xr-x. 2 root root 4096 Sep 27  2013 certs

        drwxr-xr-x. 2 root root 4096 Sep 27  2013 crl

        -rw-r–r–  1 root root    0 Jun 21 23:39 index.txt

        drwxr-xr-x. 2 root root 4096 Sep 27  2013 newcerts

        drwx——. 2 root root 4096 Sep 27  2013 private

        -rw-r–r–  1 root root    3 Jun 21 23:39 serial

        (2) CA自簽證書

        生成私鑰

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

        生成證書請求

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

            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) []:Shanghai

            Locality Name (eg, city) [Default City]:Shanghai

            Organization Name (eg, company) [Default Company Ltd]:anneng

            Organizational Unit Name (eg, section) []:ops

            Common Name (eg, your name or your server's hostname) []:ca.anneng.com

            Email Address []:809889031@qq.com

            -new: 生成新證書簽署請求;

            -x509: 專用于CA生成自簽證書;

            -key: 生成請求時用到的私鑰文件;

            -days n:證書的有效期限;

            -out /PATH/TO/SOMECERTFILE: 證書的保存路徑;

主機ip:192.168.8.94

配置httpd支持https:

            ]# cd /etc/httpd/

            ]# mkdir ssl

            ]# cd ssl/

            生成私鑰

            ]# (umask 077; openssl genrsa -out httpd.key 2048)

            創建證書簽署請求

            ]# openssl req -new -key httpd.key -days 365 -out httpd.csr

                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) []:Shanghai

                Locality Name (eg, city) [Default City]:Shanghai

                Organization Name (eg, company) [Default Company Ltd]:anneng

                Organizational Unit Name (eg, section) []:ops

                Common Name (eg, your name or your server's hostname) []:www.xzx.com

                Email Address []:               

                Please enter the following 'extra' attributes

                to be sent with your certificate request

                A challenge password []:

                An optional company name []:

            ]# ll

                總用量 8

                -rw-r–r– 1 root root 1005 6月  21 19:34 httpd.csr

                -rw——- 1 root root 1679 6月  21 19:29 httpd.key

            講證書簽署請求傳遞給CA   

            ]# scp httpd.csr root@192.168.8.98:/tmp/

主機ip:192.168.8.98

            簽署證書并講簽署后的證書發還黑httpd服務器

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

            ]# scp httpd.crt root@192.168.8.94:/etc/httpd/ssl/

主機ip:192.168.8.94

            安裝httpd的ssl模塊

            ]# yum -y install mod_ssl

            查看模塊生成的文件

            ]# rpm -ql mod_ssl

            /etc/httpd/conf.d/ssl.conf

            /usr/lib64/httpd/modules/mod_ssl.so

            /var/cache/mod_ssl

            /var/cache/mod_ssl/scache.dir

            /var/cache/mod_ssl/scache.pag

            /var/cache/mod_ssl/scache.sem

            編輯httpd關于ssl的配置

            ]# vim /etc/httpd/conf.d/ssl.conf

            <VirtualHost *:443>

            DocumentRoot "/var/www/html"

            ServerName www.xzx.com:44

            ]# service httpd restart

            停止 httpd:                                               [確定]

            正在啟動 httpd:                                           [確定]

測試基于https訪問相應的主機;

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

從本地windows端訪問https服務器

        修改本地hosts文件,將CA的自簽證書下載到本地,并將cacert.pem修改為cacert.crt,本地安裝證書,然后通過瀏覽器訪問

原創文章,作者:809889031@qq.com,如若轉載,請注明出處:http://www.www58058.com/20724

(0)
809889031@qq.com809889031@qq.com
上一篇 2016-06-28
下一篇 2016-06-28

相關推薦

  • Linux學習小結3

    1.列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。[root@node1 ~]# who -q | sed -n ‘1p’centos root fedora redhat mint2.取出最后登錄到當前系統的用戶的相關信息。[root@node1 ~]# who -a | tail -1min…

    Linux干貨 2017-10-24
  • 每日一練–8.10 腳本

    1、編寫腳本/root/bin/systeminfo.sh,顯示當前主機系統信息,包括主機名,IPv4地址,操作系統版本,內核版本,CPU型號,內存大小,硬盤大小。 2、編寫腳本/root/bin/backup.sh,可實現每日將/etc/目錄備份到/root/etcYYYY-mm-dd中 3、編寫腳本/root/bin/disk.sh,顯示當前硬盤分區中空…

    Linux干貨 2016-08-15
  • N22-第十一周作業

    1、詳細描述一次加密通訊的過程,結合圖示最佳。 (1)數字簽名 A與B通信,B發給A一段數據,為了證明數據確實是B發送過來的,B首先會用單向加密算法從數據中提取一段特征碼,然后用自己的私鑰加密這段特征碼和原始數據后,發送給A;A接受到數據,首先用B的公鑰解密,獲取到特征碼和原始數據;然后用同樣的單向加密算法從原始數據中提取一段特征碼,與之前用公鑰解密得到的特…

    Linux干貨 2016-11-01
  • 學習積累01#計算機組成#Linux版本#基本命令

    第一周的積累 問題1:描述計算機的組成及其功能 CPU:中央處理器,主要功能是進行運算和邏輯運算,內部大致可分為控制單元、邏輯算術單元、存儲單元; 主板:核心部件,是電腦的“脈絡”,CPU\內存\控制核心電路均安裝在主板上,各種外部設備也通過主板上的插槽相互連接; 硬盤:常見的外存儲器,容量大,保存時間長、安全性高。接口主要分為IDE、SATA、SCSI。 …

    Linux干貨 2016-10-25
  • 第9天:壓縮,任務,rpm包

    http://note.youdao.com/yws/public/redirect/share?id=b3e4fc37bdd98991638dce69ce3eea53&type=false

    Linux干貨 2016-08-18
  • 打造自己小小的RPM包

    關于源碼RPM包的安裝于制作 什么是RPM與SRPM? 1     RPM: 1     SRPM: 2     SRPM的安裝 2 一 .利用rpmbuild默認安裝SRPM檔案 2 二.配置路徑與需要的軟件功能模塊 3  &n…

    Linux干貨 2016-08-24

評論列表(1條)

  • stanley
    stanley 2016-06-28 11:39

    文章有待提高呀~

欧美性久久久久