zoukankan      html  css  js  c++  java
  • openssl req 证书请求及自签名证书

    介绍

    openssl req 用于生成证书请求,以让第三方权威机构CA来签发,生成我们需要的证书。req 命令也可以调用x509命令,以进行格式转换及显示证书文件中的text,modulus等信息。如果你还没有密钥对,req命令可以一统帮你生成密钥对和证书请求,也可以指定是否对私钥文件进行加密。

    语法

    openssl req[-inform PEM|DER] [-outform PEM|DER] [-in filename] [-passin arg] [-out filename] [-passout arg] [-text] [-pubkey] [-noout] [-verify] [-modulus] [-new] [-rand file(s)] [-newkey rsa:bits] [-newkey alg:file] [-nodes] [-key filename] [-keyform PEM|DER] [-keyout filename] [-keygen_engine id] [-[digest]] [-config filename] [-subj arg] [-multivalue-rdn] [-x509] [-days n] [-set_serial n] [-asn1-kludge] [-no-asn1-kludge] [-newhdr] [-extensions section] [-reqexts section] [-utf8] [-nameopt] [-reqopt] [-subject] [-subj arg] [-batch] [-verbose] [-engine id]

    -new

    这个选项用于生成一个新的证书请求,并提示用户输入个人信息。如果没有指定-key 则会先生成一个私钥文件,再生成证书请求。

     
    1. E:OpenSSLfoo>openssl req -new -key rsa_pri_nopw.pem -out crs.pem  
    2. Loading 'screen' into random state - done  
    3. You are about to be asked to enter information that will be incorporated  
    4. into your certificate request.  
    5. What you are about to enter is what is called a Distinguished Name or a DN.  
    6. There are quite a few fields but you can leave some blank  
    7. For some fields there will be a default value,  
    8. If you enter '.', the field will be left blank.  
    9. -----  
    10. Country Name (2 letter code) [AU]:CN  
    11. State or Province Name (full name) [Some-State]:HeBei  
    12. Locality Name (eg, city) []:SJZ  
    13. Organization Name (eg, company) [Internet Widgits Pty Ltd]:CCIT  
    14. Organizational Unit Name (eg, section) []:CCIT  
    15. Common Name (eg, YOUR name) []:fym  
    16. Email Address []:fym0121@163.com  
    17.   
    18. Please enter the following 'extra' attributes  
    19. to be sent with your certificate request  
    20. A challenge password []:  
    21. An optional company name []:  
    22. E:OpenSSLfoo>ls  
    23. crs.pem  
    24. rsa_pri_nopw.pem  

    没有指定-key选项时,会生成私钥文件,默认是有密码保护的,-nodes(no des),可以明确指定不需要密码保护。-keyout可以指定生成的私钥文件名,-pubout可以指定生成的公钥文件名

     
    1. openssl req -new -out crs.pem  
    2. openssl req -new -out crs.pem -nodes  

    -subj   替换或指定证书申请者的个人信息

    格式是:/type0=value0/type1=value1/type2=...(其中C是Country,ST是state,L是local,O是Organization,OU是Organization Unit,CN是common name)

     
    1. E:OpenSSLfoo>openssl req -new -key rsa_pri_nopw.pem -out crs.pem -subj /C=CN/S  
    2. T=HB/L=SJZ/O=CCIT/OU=CCIT/CN=fym/emailAddress=fym0121@163.com  
    3. Loading 'screen' into random state - done  

    -newkey arg     生成私钥和证书请求,类似与-new

    arg的格式是rsa:nbit  ,还有几个格式,我只能看懂这个

     
    1. openssl req -newkey rsa:1024 -out crs.pem  

    -xf09 生成自签名证书

     
    1. openssl req -newkey rsa:1024 -x509 -nodes -out selfsing.pem  


    -config 指定配置文件,参见config

    产生自签名的root CA

    1、建立目录结构(参加ca directory structure)

    假设当前工作目录为E:OpenSSLfoo,在此目录下建立以下目录结构

     
    1. E:OpenSSLfoo>mkdir demoCA  
    2. E:OpenSSLfoo>mkdir demoCAprivate demoCA ewcerts  

    在demoCA目录下建立两个空文件,serial和index.txt,并向serial文件中写入"01"两个字符

    2、产生自签名证书,作为root ca使用

     
    1. E:OpenSSLfoo>openssl req -new -x509 -keyout cakey.pem -out cacert.pem  

    提示输入密码保护私钥,和自签名root ca的信息。生成两个文件,将cakey.pem放到demoCAprivate目录下,将cacert.pem放到demoCA目录下。

     
    1. E:OpenSSLfoo>move cacert.pem demoCA  
    2. E:OpenSSLfoo>move cakey.pem demoCAprivate  

    至此,root ca已经建立完毕。

    证书请求及签名

    1、生成请求

     
    1. E:OpenSSLfoo>openssl req -new -nodes -out req.pem  

    提示输入个人信息,最后生成req.pem证书请求文件。

    2、签名,生成证书

     
      1. E:OpenSSLfoo>openssl ca -in req.pem -out newcert.pem  
      2. Using configuration from e:OpenSSLinopenssl.cfg  
      3. Loading 'screen' into random state - done  
      4. Enter pass phrase for ./demoCA/private/cakey.pem:  
      5. Check that the request matches the signature  
      6. Signature ok  
  • 相关阅读:
    FreeSWITCH呼叫参数之sip_cid_type
    FreeSWITCH收到重复的DTMF信号
    ajaxupload.js调用始终进入error回调
    df -h和du -sh显示结果不一样的原因及解决
    公网用户接入NAT后面的freeswitch配置
    Jedis工具类(含分布式锁的调用和释放)
    【读书笔记《Android游戏编程之从零开始》】19.游戏开发基础(游戏音乐与音效)
    【读书笔记《Android游戏编程之从零开始》】18.游戏开发基础(碰撞检测)
    【读书笔记《Android游戏编程之从零开始》】17.游戏开发基础(游戏适屏的简述和作用、让游戏主角动起来)
    【读书笔记《Android游戏编程之从零开始》】16.游戏开发基础(动画)
  • 原文地址:https://www.cnblogs.com/wajika/p/6604063.html
Copyright © 2011-2022 走看看