OpenSSL

OpenSSL由三部分组成:

            libencrypto

            libssl

            openssl多用途命令行工具

加密算法和协议:

            对称加密:加密和解密使用同一个密钥;

                    DES 3DES AES Blowfish Twofish IDEA RC6 CAST5

                    特性:

                        1、加密、解密使用同一个密钥;

                        2、将原始数据分割成为固定大小的块,逐个进行加密;

                    缺陷:

                        1、密钥过多;

                        2、密钥分发困难;

            公钥加密:密钥分为公钥与私钥

                    公钥:从私钥中提取产生;可公开给所有人;public key

                    私钥:通过工具创建,使用者自己留存,必须保证其私密性;secret key

                    特点:用公钥加密的数据,只能使用与之配对儿的私钥解密;反之亦然;

                    用途:

                        数字签名:主要在于让接收方确认发送方的身份;

                        密钥交换:发送方用对方公钥加密一个对称密钥,并发送给对方;

                        数据加密

                    算法:RSADSA, ELGamal, DSS, DSA

            单向加密:即提出数据指纹;只能加密,不能解密;

                    特性:定长输出、雪崩效应;

                    功能:完整性;

                    算法:

                        md5Message Digest 5, 128bits

                        sha1Secure Hash Algorithm 1, 160bits

                        sha224, sha256, sha384, sha512

            密钥交换: IKEInternet Key Exchange

                    公钥加密

                        DHDeffie-Hellman

                        Ap, g

                        Bp, g

                        A: x

                        –> p^x%g ==> B

                        A: (p^y%g)^x=p^yx%g

                        B: y

                        –> p^y%g ==> A => (p^y%g)^x=p^xy%g

                        B: (p^x%g)^y=p^xy%g

PKIPublic Key Infrastructure

            公钥基础设施:

                    注册机构:RA

                    证书吊销列表:CRL

                    证书存取库:

            证书的结构以及认证协议标准:

                    版本号

                    序列号

                    签名算法ID

                    发行者名称

                    有效期限

                    主体名称

                    主体公钥

                    发行者的惟一标识

                    主体的惟一标识

                    扩展

                    发行者的签名

                    SSLSecure sockets Layer

                    TLS: Transport Layer Security

            分层设计:

                    1、最底层:基础算法原语的实现,aes, rsa, md5

                    2、向上一层:各种算法的实现;

                    3、再向上一层:组合算法实现的半成品;

                    4、用各种组件拼装而成的各种成品密码学协议软件;

openssl:许多子命令,分为三类:

                   标准命令

                   消息摘要命令(dgst子命令)

                   加密命令(enc子命令)

            标准命令: enc, ca, req, genrsa, …

                        对称加密:

                            工具:openssl  enc,  gpg

                            支持的算法:3des, aes, blowfish, towfish

                            enc命令:

                                加密:~]# openssl  enc  -e  -des3  -a  -salt  -in fstab   -out fstab.ciphertext

                                解密:~]# openssl  enc  -d  -des3  -a  -salt  -out fstab   -in fstab.ciphertext

                        单向加密:

                                工具:openssl dgst, md5sum, sha1sum, sha224sum, …

                                dgst命令:

                                        ~]# openssl  dgst  -md5  /PATH/TO/SOMEFILE

                        生成用户密码:

                                工具:passwd, openssl  passwd

                                 openssl  passwd  -1  -salt  SALT

                        生成随机数:

                                工具:openssl  rand

                                    ~]# openssl  rand  -hex  NUM

                                    ~]# openssl  rand  -base  NUM

                        公钥加密:

                                加密解密:

                                算法:RSAELGamal

                                工具:openssl  rsautl, gpg

                                数字签名:

                                算法:RSADSAELGamal

                                密钥交换:

                                算法:DH

                                生成密钥:

                                          生成私钥: ~]# (umask 077;  openssl  genrsa  -out  /PATH/TO/PRIVATE_KEY_FILE   NUM_BITS)

                                          提出公钥: ~]#  openssl  rsa  -in  /PATH/FROM/PRIVATE_KEY_FILE  -pubout

                        随机数生成器:

                                        /dev/random:仅从熵池返回随机数;随机数用尽,阻塞;

                                        /dev/urandom:从熵池返回随机数;随机数用尽,会利用软件生成伪随机数,非阻塞;

                                                           伪随机数不安全;

                                        熵池中随机数的来源:

                                                           硬盘IO中断时间间隔;

                                                           键盘IO中断时间间隔;

CA:公共信任的CA,私有CA

               建立私有CA

                       openssl

                       openCA

                       配置文件:/etc/pki/tls/openssl.cnf

            构建私有CA:

                    在确定配置为CA的服务上生成一个自签证书,并为CA提供所需要的目录及文件即可;

                    步骤:

                            (1) 生成私钥;

                                ~]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)

                            (2) 生成自签证书;

                                ~]# openssl,req  -new  -x509  -key  /etc/pki/CA/private/cakey.pem  -out    /etc/pki/CA/cacert.pem -days 3655

                                                    -new:生成新证书签署请求;

                                                    -x509:生成自签格式证书,专用于创建私有CA时;

                                                    -key:生成请求时用到的私有文件路径;

                                                    -out:生成的请求文件路径;如果自签操作将直接生成签署过的证书;

                                                    -days:证书的有效时长,单位是day

                            (3) CA提供所需的目录及文件;

                                    ~]# mkdir  -pv  /etc/pki/CA/{certs,crl,newcerts}

                                    ~]# touch  /etc/pki/CA/{serial,index.txt}

                                    ~]# echo  01 > /etc/pki/CA/serial

                    要用到证书进行安全通信的服务器,需要向CA请求签署证书:

                            步骤:(以httpd为例)

                            (1) 用到证书的主机生成私钥;

                                    ~]# mkdir  /etc/httpd/ssl

                                    ~]# cd  /etc/httpd/ssl

                                    ~]# (umask  077; openssl  genrsa -out  /etc/httpd/ssl/httpd.key  2048)

                            (2) 生成证书签署请求

                                    ~]# openssl  req  -new  -key  /etc/httpd/ssl/httpd.key  -out /etc/httpd/ssl/httpd.csr  -days  365

                            (3) 将请求通过可靠方式发送给CA主机;

                            (4) CA主机上签署证书;

                                    ~]# openssl ca  -in  /tmp/httpd.csr  -out  /etc/pki/CA/certs/httpd.crt  -days  365

                    查看证书中的信息:

                            ~]# openssl  x509  -in /etc/pki/CA/certs/httpd.crt  -noout  -serial  -subject

                    吊销证书:

                             步骤:

                                (1) 客户端获取要吊销的证书的serial(在使用证书的主机执行):

                                 ~]# openssl  x509  -in /etc/pki/CA/certs/httpd.crt  -noout  -serial  -subject

                                (2) CA主机吊销证书

                                    先根据客户提交的serialsubject信息,对比其与本机数据库index.txt中存储的是否一致;

                                    吊销:

                                            # openssl  ca  -revoke  /etc/pki/CA/newcerts/SERIAL.pem

                                 其中的SERIAL要换成证书真正的序列号;

                                (3) 生成吊销证书的吊销编号(第一次吊销证书时执行)

                                            # echo  01  > /etc/pki/CA/crlnumber

                                (4) 更新证书吊销列表

                                            # openssl  ca  -gencrl  -out  thisca.crl

                                        查看crl文件:

                                            # openssl  crl  -in  /PATH/FROM/CRL_FILE.crl  -noout  -text

原创文章,作者:忠神通,如若转载,请注明出处:http://www.178linux.com/77178

(0)
忠神通忠神通
上一篇 2017-05-30
下一篇 2017-05-30

相关推荐

  • varnish4 基础实战

    实验环境 node1 192.168.0.8 varnish服务器 node2 192.168.0.3 动态web node3 192.168.0.7 静态web node1安装varnish ##安装varnish yum源  # wget http://repo.varnish-cache.org/redhat/v…

    Linux干货 2016-11-15
  • Linux发展史

    简述 Linux于1991年10月5日诞生,由Linus torvalds和后面陆续加入的众多爱好者共同开发完成的操作系统 Linux只表示Linux kernl,但由于习惯用Linux来形容整个基于Linux kernl,使用GNU计划的各种工具和数据库的操作系统 Linux的标志 一只名为Tux的企鹅 大家要Linus Torvalds想一只吉祥物,他想…

    2017-03-26
  • 马哥教育网络班22期中秋节课程练习1

    #!/bin/sh   set -e CheckRoot() { #check if currect use is root user     CUR_USER=`whoami`     if&nbs…

    Linux干货 2016-10-09
  • N23-卡卡琦-第一周

    1、描述计算机的组成及其功能 硬件: 控制器:是整个计算机的中枢神经,其功能是对程序规定的控制信息进行解释,根据其要求进行控制,调度程序、数据、地址,协调计算机各部分工作及内存与外设的访问等;运算器:运算器的功能是对数据进行各种算术运算和逻辑运算,即对数据进行加工处理;存储器:存储器的功能是存储程序、数据和各种信号、命令等信息,并在需要时提供这些信息;输入输…

    Linux干货 2016-11-16
  • N25_第三周

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 who | cut -d' ' -f1 | sort -u [root@server1 ~]# who  | cut -d' ' -f1 …

    Linux干货 2016-12-17
  • Linux初认识

    1、计算机的五大部件 CUP: CUP中包含了两大部件分别是运算器、控制器。其中运算器主要是进行数学运算、逻辑运算等各种运算的。除了两大部件以外CUP内部还有寄存器、缓存,它们是提升CUP性能的辅助性工具。 存储器: 内存RAM(Random Access Memory)。 输入设备Input: 输入设备用来下指令,提供数据等。输入设备有键盘,鼠标,麦克风等…

    Linux干货 2017-07-09