马哥教育网络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 []:[email protected]
以上就是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 [email protected] /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/[email protected]
    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)
wostopwostop
上一篇 2016-09-26 07:43
下一篇 2016-09-26 07:43

相关推荐

  • 20160803普通权限与特殊权限及umask

    权限     任何一个可执行程序文件能不能启动为进程,取决发起者对程序文件是否拥有执行权限.即权限决定用户对文件或者目录的使用范围.在Linux系统中,root的权限是最高的,可操作的权限最大,通常情况下root账号只用于管理系统的重要信息,并不做日常维护工作,所以正确设定用户的权限对系统的安全性尤为重要. 普通权限: 文件目录只针对三类…

    Linux干货 2016-08-04
  • CentOS系统安装

    centos系统安装        安装程序:anaconda,Anaconda是RedHat、CentOS、Fedora等Linux的安装管理程序。它可以提供文本、图形等安装管理方式,并支持Kickstart等脚本提供自动安装的功能。此外,其还支持许多启动参数,熟悉这些参数可为安装带来很多方便。该程序的功能是把位于光…

    Linux干货 2016-09-23
  • Linux的哲学思想

    一切皆文件:所有设备在linux都表现为一个文件,比如目录文件、块文件、字符文件、设备文件; 用小型,单一用途的程序完成复杂功能:复杂的任务可以通过连接多个简单的程序实现复杂的功能;配置服务器,只要修改配置文件即可实现;

    Linux干货 2018-03-04
  • CPU 处理器架构知识

    CPU处理器架构: 主要有ARM、X86/Atom、MIPS、PowerPC,其中ARM在智能手机上面一枝独秀;其中ARM/MIPS/PowerPC均是基于精简指令集机器处理器的架构;X86则是基于复杂指令集的架构,Atom是x86或者是x86指令集的精简版。 Android在支持各种处理器的现状: ARM+Android 最早发展、完善的支持,主要在手机市…

    Linux干货 2015-08-03
  • vim

    VIM常用操作命令 模式转换 1、ESC键:编辑模式 --> 一般模式;2、从一般模式 --> 编辑模式 i:在光标所在处的前方转换为编辑模式 a:在光标所在处的后方转换为编辑模式 o:在光标所在行的下方新建一个空行并转换为编辑模式 I:在光标所在行的行首输入 A:在光标所在行的行尾输入 O:在光标所在行的上方新建一个空白行 3、一般模式 --> 末行模式:…

    Linux干货 2017-04-06
  • linux高级文件系统管理

    磁盘配额:         (1)如果存放的文件空间不足,虽然分区后不能直接扩容,但是可以迁移,下面以/home目录示例: 1、新建分区,同步分区表 /dev/sda62、mkfs.ext4 /dev/sda6             &n…

    Linux干货 2017-03-14

评论列表(1条)

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

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