马哥教育网络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.178linux.com/48883

(0)
上一篇 2016-09-26 07:43
下一篇 2016-09-26 07:43

相关推荐

  • Linux软件包安装

    Linux系统和Windows系统在软件包安装上区别很大:     软件运行环境:         API: Application Programming Interface    POSIX: P…

    Linux干货 2016-08-21
  • 马哥教育网络班22期+第六周课程练习

    1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; ]# cp -v  /etc/rc.d/rc.sysinit /tmp/    `/etc/rc.d/rc.sysinit' -> `/tmp/rc.sysinit&…

    Linux干货 2016-10-17
  • shell编程之循环及函数

    for 循环 for 变量名 in 列表;do    循环体 done   执行机制: 依次将列表中的元素赋值给“变量名”; 每次赋值后即执行一次循环体; 直到列表中 的元素耗尽,循环结束   列表生成方式: (1)直接给出列表 (2)整数列表: (a) {start..end} (b) $(seq [start [s…

    Linux干货 2016-08-24
  • sed命令的用法和vim编辑器的使用

    一、文本处理工具sed sed [option]….'script] [input-file]… 简介: sed是一种流编辑器,他一次处理一行的内容,处理时把当前处理的行存储在临时缓冲区中,这个缓冲区被称为模式空间,接着用sed命令处理,处理完成后把模式空间的内容送往屏幕,接着处理下一行,知道文件末尾,而文件的内容…

    Linux干货 2016-08-15
  • N25-第19周博客作业

    1、描述Tomcat的架构; 2、详细解释Tomcat的配置文件及配置文件中的参数所代表的含义; 3、配置apache通过mod_proxy模块与Tomcat连接的详细过程; 4、配置基于mod_jk的负载均衡; 5、配置tomcat集群,能够实现用户的session会话保持。 1、描述Tomcat的架构; Tomcat组件,分为4类: 顶层类组件:包括&l…

    2017-05-21
  • 推荐-DNS BIND初探

    DNS BIND DNS BIND 正向解析 反向解析 从服务器 子域授权 转发 view DNS 什么是DNS? DNS是domain name system,域名系统的简写,负责实现域名与IP的转换。 DNS的功能是什么? DNS能够将IP地址与域名相互双向转换,能够实现域名访问。 DNS的历史:  1. 初期网络…

    2016-04-19

评论列表(1条)

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

    写的很好,图画的也很漂亮,希望继续保持