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

相关推荐

  • 文本处理工具

    分页查看文件内容 less和more命令介绍 分页查看文件内容:less和more less:一页一页地查看文件或STDIN输出   # less FILE less的快捷键:     Ctrl+u:向上翻半屏     Ctrl+d:向下翻…

    Linux干货 2016-08-07
  • Linux基础之文件查找压缩

    为何学习本章节,可以设想一下,在未来工作中面对大量用户时,想要找到同一类型属性的用户文件时,需要一个工具可以快速准确的定位到所寻找的文件,那就是locate和find。   ******************************************************* 重点:     1.德摩根定律     非(P且Q) = (非P…

    2016-08-22
  • CentOS 7 tomcat 7.0.54 的功能实现及详解

    一、 jdk 安装配置 # yum install java-1.8.0-openjdk-devel (依赖的java-1.8.0-openjdk,java-1.8.0-openjdk,headless也会被安装 ) # alternatives -h # vim /e…

    2016-08-19
  • 20160803用户权限作业

    三种权限rwx对文件和目录的不同意义 文件:r:可以cat查看文件中的内容,可以查看文件的属性          w:可以ll查看文件的属性,也可以往文件中写入内容,如果其父目录具有写和执行权限就可删除其内部文件        &…

    Linux干货 2016-08-07
  • linux常用基础命令简介

    linux常用基础命令简介 linux入门 基础 笔记 linux新手入门常用命令语法参数简介 linux常用基础命令简介 cd 语法 选项 ls 语法 选项 echo 语法 选项 history 语法 选项 man 语法 选项 cd cd命令用来切换工作目录至指定目录。 其中指定目录表示法可为绝对路径或相对路径。若目录名称省略,则变换至…

    Linux干货 2017-03-26
  • bash的工作特性之命令执行状态返回值和命令行展开

    bash特性之一:命令别名 将一个命令用其他名字来代替,可以用别名来简化操作。 获取当前用户可用的别名的定义: ~]#alias NAME=’COMMAND’ bash的特性之二:命令历史 shell进程会保存其会话中用户曾经执行过的命令;命令通过其“历史文件”来持久保存此前执行过的命令;每个用户都有其自己专用的历史文件; HISTSIZE:shell进程的…

    Linux干货 2016-11-06