自建的CA配置基於mod_ssl模塊實現對ssl的支持

https簡介

    http協議在網絡中是以明文傳輸的,自然安全性不高。https使用了ssl加密機制,彌補了這點不足。
    http:80端口
    https:443端口

案例:

    自建CA,實現一個https安全的會話機制。
    這裏爲了方便期間,CA和web服務器是用一臺服務器共同實現
  1. web生成並提交請求

    [root@web CA]# (umask 077;openssl genrsa 1024 > httpd.key)
    [root@web CA]# openssl req -new -key httpd.key -out httpd.csr


  2. 自建ca

    [root@web CA]# (umask 077;openssl genrsa 2048 > private/cakey.pem)
    [root@web CA]# openssl req -new -x509 -key private/cakey.pem -days 365 -out cacert.pem


  3. web服務器端發給CA簽署(可以使用scp命令)
     

    [root@web ssl]# openssl ca -in httpd.csr -out httpd.crt


  4. 簽署成功後有CA服務器發送個web,此時web服務器端就得到了3個相關私鑰和證書

    [root@web ssl]# pwd
         /etc/httpd/conf/ssl
     [root@web ssl]# ls
     httpd.crt  httpd.csr  httpd.key


  5. 接下來開始部署我們web支持ssl功能了,想要支持ssl,apache必須加載mod-ssl模塊

  6. 查看我們的apache是否已經配置支持了ssl

    [root@web ~]# grep mod_ssl /etc/httpd/conf/httpd.conf
    # (e.g. :80) if mod_ssl is being used, due to the nature of the
    [root@web ~]# grep mod_ssl /etc/httpd/conf.d/*.conf


  7. 既然grep不到,說明沒有支持,此時我們需要安裝一個mod_ssl

    [root@web ~]# yum -y install mod_ssl
    [root@web ~]# 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


  8. 查看一下新安裝的配置文件吧,這裏加載了ssl的模塊支持,和新的端口號443等。

    [root@web ~]# vim /etc/httpd/conf.d/ssl.conf
    LoadModule ssl_module modules/mod_ssl.so
    Listen 443
    <VirtualHost _default_:443>


  9. 我們需要修改一下這個配置文件,讓其知道我們的web服務器的證書在哪裏,私鑰在哪裏,以方便把我們的證書發給客戶端,並且用私鑰解密客戶端用我們的證書中的公鑰加密的對稱密碼。

    <VirtualHost _default_:443>
    # General setup for the virtual host, inherited from global configuration
    DocumentRoot "/var/www/html"
    ServerName www.magelinux.com:443--------要與證書申請時對應
    ErrorLog logs/ssl_error_log-------------日誌文件
    TransferLog logs/ssl_access_log
    LogLevel warn---------------------------日誌級別
        SSLEngine on----------------------------是否開啓ssl功能
        #   SSL Protocol support:
        # List the enable protocol levels with which clients will be able to
        # connect.  Disable SSLv2 access by default:
        SSLProtocol all -SSLv2
        #   SSL Cipher Suite:
        # List the ciphers that the client is permitted to negotiate.
        # See the mod_ssl documentation for a complete list.
        SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
        #   Server Certificate:
        SSLCertificateFile /etc/httpd/conf/ssl/httpd.crt------證書位置
        #   Server Private Key:
        SSLCertificateKeyFile /etc/httpd/conf/ssl/httpd.key---私鑰位置


  10. 通過命令ss -tunl 可以看出此時443端口已經開始監聽了,此時通過瀏覽器訪問會提示證書不守信用,有風險,這是因爲我們的證書是我們自建的CA簽署的,客戶端沒有認可

    wKiom1M3sebA2sBBAADsxSXxl3g439.jpgXIU

  11. 將CA證書導入到我們的客戶端電腦,並安裝。

    wKiom1M3s3HSO6_SAARxXTeC3U8549.jpgwKiom1M3s9WiatuQAALgPcHJcME562.jpg

    wKiom1M3tMriXjpCAAFInBgF7a4418.jpg

  12. 當然我們也可以用openssl s_client -connect ip:443來診斷(man s_client)




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