zoukankan      html  css  js  c++  java
  • Linux九阴真经之九阴白骨爪残卷1(加密和安全)

    CA和证书

    1、KPI :公共秘钥体系
            签证机构:CA
            注册机构:RA
            证书吊销列表:CRL
            证书存取库
    509:定义了证书的结构以及认证协议标准
     
    版本号
    序列号
    签名算法                   主体公钥        
    颁发者                      CRL分发点
    有效期限                    扩展信息
    主体名称                   发行者签名

    证书类型:

    证书授权机构的证书

    服务器

    用户证书

    获取证书两种方法:

    •使用证书授权机构

    生成签名请求(csr)

    将csr发送给CA

    从CA处接收签名

    •自签名的证书
    自已签发自己的公钥
     
    安全协议
     
    SSL:Secure  Socket  Layer
    TLS:Transport  Layer  Security
     
    功能:机密性,认证,完整性,重放保护(重新发一遍用户名和密码,跨过网站检查,危险)
     
    HTTPS 协议:就是“HTTP 协议”和“SSL/TLS 协议”的组合。

      

    OpenSSL                         

    三个组件:

    openssl:加密模块应用库,实现了ssl及tls,包nss

    libcrypto:加密算法库,包openssl-libs

    libssl:加密模块应用库,实现了ssl及tls,包nss

    openssl命令

    两种运行模式:交互模式和批处理模式

    标准命令:
    enc, ca, req, ...

    对称加密

    工具:oopenssl  enc,

    算法:3des, aes,  blowfish,  twofish

    enc命令

    帮助:man   enc

    加密:  openssl   enc -e  -des3   -a -salt  -in  testfile  -out  testfile.cipher

    enc(对称加密)

    -des3 (加密算法)

    -a(以base64编码,用可见字符表示,方便查看)

    解密: openssl  enc  -d(解密)  -des3  -a  -salt  -in  testfile.cipher  -out  testfile

    单向加密:
    工具:md5sum, sha1sum, sha224sum,sha256sum…
    openssl dgst

    生成用户密码

    passwd命令:

    帮助:man  sslpasswd

    openssl passwd -1(以md5加密)  -salt (加盐,杂质,不容易破解)

    生成随机数

    openssl  rand  -base64 | -hex  NUM

    NUM: 表示字节数;-hex时,每个字符为16进制,相当于4位二进制,出现的字符数为NUM*2

    openssl  rand  -base64   9   (3的倍数 就不用添加=号)   ,生成随机数,适合当口令
    openssl  rand  -base 64    12  | tr  -dc '[:alnum:]'   生成一个12位随机密码,并且只留下数字和字母

    生成密钥对儿
      生成私钥    (umask 066;openssl  genrsa -out  private.key 1024)
      私钥加密    (umask 066;openssl  genrsa -out  private.key -des 1024)
      生成公钥     (openssl rsa -in private.key -pubout -out public.key)将加密key解密
     
    从私钥中提取出公钥

    openssl  rsa  -in  PRIVATEKEYFILE  -pubout  -out  PUBLICKEYFILE

    openssl  rsa  -in  test.key  -pubout  -out test.key.pub

    创建CA和申请证书

    一、创建CA

    1、ROOT  CA   自己创建CA

    生成私钥

    自签名证书

    二、用户或服务器

    1、生成私钥

    2、生成证书申请文件

    3、将申请文件发给CA

    三、CA颁发证书

     证书签名

    四、证书发送给客户端

    五、应用软件使用证书

    例:向CA申请证书

    1、建立Root CA   ,生成私钥   umask 077 是取反的意思,目的是达到700的效果,为什么不用mask 700呢? 因为没有这条命令。

    [root@laobai ~#cd /etc/pki/CA
    [root@laobai /etc/pki/CA#(umask 077;openssl genrsa -out private/cakey.pem 4096)
    Generating RSA private key, 4096 bit long modulus
    ...........++
    .................................................................................................................++
    e is 65537 (0x10001)

    2、自签名证书

    [root@laobai /etc/pki/CA#openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
    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.
    -----


    3、用户服务器

    (1)在客户端生成私钥

    [root@laobai /etc/pki/CA#(umask 077;openssl genrsa -out app.key 1024)
    Generating RSA private key, 1024 bit long modulus
    .......++++++
    .................................................................................++++++
    e is 65537 (0x10001)

    (2)生成证书申请文件

    [root@laobai /etc/pki/CA#openssl req -new -key app.key -out app.csr
    
    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]:magedu
    Organizational Unit Name (eg, section) []:m30
    Common Name (eg, your name or your server's hostname) []:www.magedu.com
    Email Address []:
    
    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:
    An optional company name []:


    (3)将申请文件发给CA,并发送给服务器端

    [root@laobai /etc/pki/CA#sz certs/app.crt 
    [root@centos7 CA]#scp app.csr 172.20.110.62:/etc/pki/CA
    root@172.20.110.62's password: 
    app.csr                                                        100%  651     1.2MB/s   00:00    

    4、CA颁发证书

    (1) 新建一个index.txt  存储证书颁发信息

    [root@laobai /etc/pki/CA#touch index.txt

    (2)建一个serial文件 存储下一个颁发证书的编号

    [root@laobai /etc/pki/CA#echo 0F > serial

    (3)颁发证书

    [root@laobai /etc/pki/CA#openssl ca -in app.csr -out certs/app.crt -days 100
    Using configuration from /etc/pki/tls/openssl.cnf
    Check that the request matches the signature
    Signature ok

    (4)将证书发送给客户端相应的文件夹内,客户端就可直接适用了。

  • 相关阅读:
    在Salesforce中对某一个Object添加 Validation Rule
    在Salesforce中创建Schedule的Job去定时触发对应的Class
    在Salesforce中向Page Layout中添加Visualforce Page
    【LeetCode】229. Majority Element II
    【LeetCode】230. Kth Smallest Element in a BST (2 solutions)
    【LeetCode】231. Power of Two
    【LeetCode】232. Implement Queue using Stacks
    【LeetCode】219. Contains Duplicate II
    【LeetCode】217. Contains Duplicate (2 solutions)
    【LeetCode】216. Combination Sum III
  • 原文地址:https://www.cnblogs.com/huxiaojun/p/9058285.html
Copyright © 2011-2022 走看看