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 11:03
下一篇 2016-06-28 11:48

相關推薦

  • 馬哥教育網絡班21期+第七周課程練習

    1、創建一個10G分區,并格式為ext4文件系統;    (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;    (2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳; ~]# fdisk &n…

    Linux干貨 2016-08-30
  • nginx 基礎筆記

    一、Nginx 優點 高性能web,可以支持反向代理 比Apache性能優越,支持更多的并發連接,但資源占用很少,輕量級的web服務器??梢灾С指哌_50000個并發連接數的響應 Nginx 在Linux 2.6+ 使用epoll模型,提供卓越性能 做為負載均衡服務器,可以在內部直接支持PHP和Rails,也可以支持作為HTTP代理服務器對外進行服務 Ngin…

    Linux干貨 2016-03-19
  • RPM包管理——運維必備技能之一

    軟件運行環境: API:Application Programming Interface     POSIX :Portable OS 程序源代碼 –> 預處理 –> 編譯 –> 匯編 –> 鏈接     …

    Linux干貨 2016-08-21
  • 第五周學習總結–任務計劃

    寫在前面 隨著學習的不斷深入,漸漸的已經意識到不再是開始一天只知道幾個簡單的命令而已了,但是呢,命令還必須要繼續學習的,修房子哪有不用磚的,所以,要想有一棟堅實穩固的房子,還必須靜下心來繼續認識命令。 命令注解 今天要講的幾個命令是跟工作息息相關的,他們都是在以后的生活中使用率比較高的命令之一,比如馬上要講的這個,如果你的老板讓你在每天凌晨三點執行一次數據備…

    2017-12-29
  • 網絡管理總結

      在學習Linux的快兩個月時間的這個階段,我們學習到了網絡的相關知識,哇,原來我們上網是需要這么多步驟的,玩了這么久的電腦,打開過無數網站還只是停留在以為打開網站只需要點點鼠標的層面,慚愧慚愧。學習了一周,終于了解了一些網絡的基層結構和一些網絡協議,下面是對這一周所學知識的一些總結,加強記憶和理解。還停留在以為打開一個網站只是動動鼠標…

    2017-09-02
  • 【N25第一周作業】Linux上命令的使用格式和基礎命令詳解

    一、Linux上命令的使用格式 命令行提示符詳解: 用戶通過終端的命令行接口來控制操作系統,登陸后如下: [root@localhost ~]# root: 當前登錄的用戶 @:分隔符 localhost: 當前主機的主機名,非完整格式;此處的完整格式為:localhost.localdomain [root@localhost ~]#&…

    Linux干貨 2016-12-03

評論列表(1條)

  • stanley
    stanley 2016-06-28 11:39

    文章有待提高呀~

欧美性久久久久