馬哥教育網絡21期+第十一周練習博客(上)

馬哥教育網絡21期+第十一周練習博客(上)

1、詳細描述一次加密通訊的過程,結合圖示最佳。

加密同性過程中使用到最重要的就是openssl
    安全加密傳輸過程中要確保如下幾個環節:
    保密性:數據保密性,隱私性
    完整性:數據完整性,系統完整性
    可用性:數據的可用性,系統可用性
安全攻擊:
    被動攻擊:竊聽
    主動攻擊:偽裝,重放,消息篡改,拒絕服務等等
面對以上的安全攻擊定義了如下的安全機制:
    數據加密,數字簽名,訪問控制,數據完整性,認證交換機制,流量填充,路由控制,公證等等
安全服務:
    認證服務
    訪問控制
    數據的保密性:連接保密性,無連接保密性,選擇域保密性,流量保密性
    數據完整性
    不可否認性
在確保以上的安全服務當中采用了密碼算法和協議進行加密:
    密碼算法和協議:對稱加密,公鑰加密,單向加密,認證協議
        對稱加密:加密與解密使用同一個密鑰,將原始數據分割成固定大小的塊,逐個進行加密;
            缺點:密鑰過多,一個連接就要使用一組密鑰進行加密,密鑰分發;
        公鑰加密:密鑰成對出現,公鑰公開給所有人,私鑰自己留存,但必須保證其私密性
            特點:用公鑰加密的數據,必須使用與之配對的私鑰進行解密,反正亦然;
        在公鑰加密中如何防止被篡改其公鑰呢?
        數字簽名:讓接收方確認發送方身份;
        密鑰交換:發送方用對方公鑰加密一個堆成密鑰,并發送給對方,然后進行數據加密;
    單向加密:只能加密,無法解密,提取數據指紋;
        特性:定長輸出,雪崩效應
        功能:保證了數據的完整性

綜上所述:一次加密通信過程:
    例如兩者A,B進行加密通信:
    雙方建立TCP連接,B將自己的CA證書發送給A,A使用存留本機的CA證書庫中找到其公鑰進行解密,如果能解密說明證書可信任,下一步比對其主機名,如果主機名正確可以進行交換,下一步使用單向加密,加密其特征碼與證書中的特征碼進行比對,如果正則,此證書則完全被信任,下一步進行數據交換!
    A將呀發送的內容進行編寫發送給B;
    使用單向加密算法提取數據的特征碼,用自己的私鑰加密這段特征碼附加在這段數據后面
    A再用對稱密鑰將這整段數據進行加密,此時B是沒有這段對稱加密的密鑰的,那么可以使用B的公鑰加密這段對稱密鑰附加在上一段數據后面。
    B使用自己的私鑰解密對稱加密得到對稱加密密鑰,使用對稱解密算法得到明文數據和特征碼,使用對方的公鑰解密特征碼,使用同樣的算法提取特征碼,說明數據完整性得到驗證;
    以上密鑰需要在網上傳送所以這里需要使用到密鑰交換協議:IKE
    A需要拿到B的證書,B需要拿到A的證書,雙方發送由第三方信任的簽署機構發送的證書,
    需要找到發行者的名稱與發行者的簽名,用本地CA的公鑰解密發行者的簽名比較如果正確是可靠
    使用X509里面的加密算法和特征碼做比較,如果正確,證書是可信的!

P9PT0TZG(U9[DBON3_DOLH6.png

2、描述創建私有CA的過程,以及為客戶端發來的證書請求進行辦法證書。
實驗環境:準備2太虛擬機
CA的配置文件在
[root@localhost CA]# cat /etc/pki/tls/openssl.cnf 
 [  ca ]
default_ca  = CA_default        # The default ca section

####################################################################
[ 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

按照以上的配置文件將沒有的文件進行創建:
[root@localhost CA]# touch index.txt
[root@localhost CA]# echo 01 > serial

將其中一臺服務器創建為CA進行證書的頒發:
    1,先建立CA的私有密鑰:
    [root@localhost CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048)
    建立私鑰密鑰,但是這里生成的密鑰文件必須是cakey.pem
    2,提取CA私鑰文件中的公鑰文件:
    [root@localhost CA]# openssl req -new -x509 -key  private/cakey.pem -days 7300 -out 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) []:Beijing
    Locality Name (eg, city) [Default City]:Beijing
    Organization Name (eg, company) [Default Company Ltd]:xitongjicheng
    Organizational Unit Name (eg, section) []:Ops
    Common Name (eg, your name or your server's hostname) []:ca.xitongjicheng.com
    Email Address []:wanghongkai@163.com
以上就是CA創建完畢?。。?
將另外一臺主機模擬成需要申請CA證書的公司!這里我們使用http進行模擬!!在http下創建一個目錄為ssl
同樣生成私鑰文件:
[root@localhost httpd]# (umask 077; openssl genrsa -out httpd.key 2048)
提出公鑰文件:
[root@localhost httpd]# 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) []:Beijing
Locality Name (eg, city) [Default City]:Beijing
Organization Name (eg, company) [Default Company Ltd]:xitongjicheng
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server's hostname) []:WEB1.xitongjicheng.com
Email Address []:wang#@163.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

然后將B主機要申請的CA發送給CA主機!
    [root@localhost httpd]# scp httpd.csr root@172.16.0.124 /tmp/
然后CA對其申請進行認證:
[root@localhost CA]# openssl ca -in /tmp/httpd.csr -out newcerts/web1xitongjicheng.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: Sep  5 23:52:50 2016 GMT
        Not After : Sep  5 23:52:50 2017 GMT
    Subject:
        countryName               = CN
        stateOrProvinceName       = Beijing
        organizationName          = xitongjicheng
        organizationalUnitName    = Ops
        commonName                = WEB1.xitongjicheng.com
        emailAddress              = wang#@163.com
    X509v3 extensions:
        X509v3 Basic Constraints: 
            CA:FALSE
        Netscape Comment: 
            OpenSSL Generated Certificate
        X509v3 Subject Key Identifier: 
            FB:7D:FF:33:03:30:AE:3F:62:48:AE:95:9B:15:36:87:9A:CE:74:38
        X509v3 Authority Key Identifier: 
            keyid:76:DB:F3:67:97:88:C7:CA:E1:20:E4:55:62:38:CE:08:92:4D:FC:AC

Certificate is to be certified until Sep  5 23:52:50 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-->這里提示證書已經更新!
這里需要主機要新的生成證書復制一份到certs目錄下進行保存!
[root@localhost CA]# cp newcerts/web1xitongjicheng.crt certs/
將已簽好的證書發還給客戶端:
root@localhost CA]# scp newcerts/web1xitongjicheng.crt 172.16.0.2:/etc/httpd/ssl/

在客戶端查看證書簽發的內容:
[root@localhost ssl]# openssl x509 -in /etc/httpd/ssl/web1xitongjicheng.crt -noout -text
Certificate:
Data:
    Version: 3 (0x2)
    Serial Number: 1 (0x1)
Signature Algorithm: sha1WithRSAEncryption
    Issuer: C=CN, ST=Beijing, L=Beijing, O=xitongjicheng, OU=Ops, CN=ca.xitongjicheng.com/emailAddress=wanghongkai@163.com
    Validity
        Not Before: Sep  5 23:52:50 2016 GMT
        Not After : Sep  5 23:52:50 2017 GMT
    Subject: C=CN, ST=Beijing, O=xitongjicheng, OU=Ops, CN=WEB1.xitongjicheng.com/emailAddress=wang#@163.com
總結:
.key格式:私有的密鑰    
.crt格式:證書文件,certificate的縮寫    
.csr格式:證書簽名請求(證書請求文件),含有公鑰信息,certificate signing request的縮寫    
.crl格式:證書吊銷列表,Certificate Revocation List的縮寫    
.pem格式:用于導出,導入證書時候的證書的格式,有證書開頭,結尾的格式

這樣一次完整私建CA和簽發證書完成!


原創文章,作者:wostop,如若轉載,請注明出處:http://www.www58058.com/48883

(0)
wostopwostop
上一篇 2016-09-26
下一篇 2016-09-26

相關推薦

  • 文件查找與壓縮-2

    1、tar [OPTION]… (1) 創建歸檔(打包而非壓縮) 其中-c是創建備份,-f是指定創建備份成的文件即是/PATH/TO/SOMEFILE.tar #tar -c -f /PATH/TO/SOMEFILE.tar  FILE… #tar cf / PATH/TO/SOMEFILE.tar FILE… …

    Linux干貨 2016-08-18
  • 配置基于mysql的虛擬用戶認證vsftp服務器

    1.安裝vsftp、mysql、epel_release(epel源,后面要安裝的pam_mysql認證模塊需要這個源)、pam_mysql 2.剛裝的mysql運行一下/usr/bin/mysql_secure_installation 3.建立數據庫vsftpd,建表user,     create database vsftpd; …

    Linux干貨 2016-06-22
  • 178linux博客寫作技巧

    為什么要寫博客 為什么要寫在178linux上 如何注冊178linux 178linux的文章提審規則 178linux寫文章的技巧 markdown 語法 為什么要寫博客 寫博客的好處不言而喻,也不做過多解釋,眼過千遍不如手過一遍。知識的吸收需要很長的過程,這個過程越艱難越我們對知識的吸收程度也越好。對于找工作也有好處,側面是自己工作能力的證明,大量學員…

    Linux干貨 2016-09-06
  • 馬哥教育網絡班-N26

    From the beginning~~~

    Linux干貨 2016-12-26
  • 第九周shell腳本編程練習

    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現; 2、寫一個腳本 (1)?獲取當前主機的主機名,保存于hostname變量中; (2)?判斷此變量的值是否為localhost,如果是,則將當前主機名修改www.magedu.com; (3…

    2017-11-23
  • rpm 程序包管理器的基本使用

    目錄 安裝程序包 卸載 升級 查詢 校驗 來源合法性和完整性驗證 數據庫重建 1     安裝程序包 rpm -ivh /path/to/package_file -v     顯示執行過程的參數。 -h   &nbsp…

    Linux干貨 2016-06-22

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-09-27 09:34

    寫的很好,圖畫的也很漂亮,希望繼續保持

欧美性久久久久