介绍

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:\OpenSSL\foo>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. Please enter the following 'extra' attributes
  18. to be sent with your certificate request
  19. A challenge password []:
  20. An optional company name []:
  21. E:\OpenSSL\foo>ls
  22. crs.pem
  23. 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:\OpenSSL\foo>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:\OpenSSL\foo,在此目录下建立以下目录结构

  1. E:\OpenSSL\foo>mkdir demoCA
  2. E:\OpenSSL\foo>mkdir demoCA\private demoCA\newcerts

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

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

  1. E:\OpenSSL\foo>openssl req -new -x509 -keyout cakey.pem -out cacert.pem

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

  1. E:\OpenSSL\foo>move cacert.pem demoCA
  2. E:\OpenSSL\foo>move cakey.pem demoCA\private

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

证书请求及签名

1、生成请求

  1. E:\OpenSSL\foo>openssl req -new -nodes -out req.pem

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

2、签名,生成证书

    1. E:\OpenSSL\foo>openssl ca -in req.pem -out newcert.pem
    2. Using configuration from e:\OpenSSL\bin\openssl.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

openssl req 证书请求及自签名证书的更多相关文章

  1. openssl 证书请求和自签名命令req详解

    1.密钥.证书请求.证书概要说明 在证书申请签发过程中,客户端涉及到密钥.证书请求.证书这几个概念,初学者可能会搞不清楚三者的关系,网上有的根据后缀名来区分三者,更让人一头雾水.我们以申请证书的流程说 ...

  2. (11) openssl req(生成请求证书、私钥和自建CA)

    伪命令req大致有3个功能:生成证书请求文件.验证证书请求文件和创建根CA. 由于openssl req命令选项较多,所以先各举几个例子,再集中给出openssl req的选项说明.若已熟悉opens ...

  3. [https][openssl] OpenSSL 公钥、私钥以及自签名证书

    转自:https://www.zybuluo.com/muyanfeixiang/note/392079 简介 公钥私钥用来互相加解密的一对密钥,一般是采用RSA非对称算法.公钥加密的私钥能解密,私钥 ...

  4. 解决linux netcore https请求使用自签名证书忽略安全检查方法

    当前系统环境:centos7 x64. dotnet 2.0. 不管是 ServicePointManager.ServerCertificateValidationCallback = (a, b, ...

  5. ubuntu google chrome 忽略证书错误 -- 解决自签名证书不支持的问题

    ubuntu chrome 打开自签名的证书的服务器的https时,提示 Your connection is not private. 错误代码:NET::ERR_CERT_AUTHORITY_IN ...

  6. 8.openssl req

    数字证书申请和生成工具.也可以为根CA自行签署证书. 该命令中很多值.属性.格式或默认值都在config文件openssl.cnf中指定. [root@xuexi ~]# man req NAME r ...

  7. (转)openssl 命令: openssl req 命令详解

                                      openssl req命令主要的功能有,生成证书请求文件, 查看验证证书请求文件,还有就是生成自签名证书.本文就主要记录一下open ...

  8. openssl req(生成证书请求和自建CA)

    伪命令req大致有3个功能:生成证书请求文件.验证证书请求文件和创建根CA.由于openssl req命令选项较多,所以先各举几个例子,再集中给出openssl req的选项说明.若已熟悉openss ...

  9. openssl req(生成证书请求和自建CA)(转)

    openssl req(生成证书请求和自建CA)     伪命令req大致有3个功能:生成证书请求文件.验证证书请求文件和创建根CA.由于openssl req命令选项较多,所以先各举几个例子,再集中 ...

随机推荐

  1. impala 导出CSV 或excel

    1.介绍 impala-shell导入导出 参数说明: • -q query (--query=query) 从命令行执行查询,不进入impala-shell • -d default_db (--d ...

  2. Java通信过程的中文乱码的解决

    J在基于Java的编程中,常常会碰到汉字的处里及显示的问题.比方一大堆乱码或问号. 这是由于JAVA中默认的编码方式是UNICODE.而中国人通常使用的文件和DB都是基于GB2312或者BIG5等编码 ...

  3. windows 使用 xxfpm 解决 php-cgi 进程自动关闭

    windows 下 php-cgi 进程处理一定数量的访问后,就会自动关闭,由于没办法直接让 php-cgi 进程支持更多的访问数量,所以只能启动多个进程来满足需求. xxfpm 是一个可执行程序,它 ...

  4. Android -- EventBus使用

    EventBus EventBus是一个Android端优化的publish/subscribe消息总线,简化了应用程序内各组件间.组件与后台线程间的通信.比如请求网络,等网络返回时通过Handler ...

  5. HDU 4059 The Boss on Mars(容斥原理 + 四次方求和)

    传送门 The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. HotSpot Java虚拟机中的“方法区”“持久代”“元数据区”的关系?

    Sun/Oracle JDK的HotSpot VM中,直到JDK7都有“持久代”(Permanent Generation,简称PermGen).也称为方法区.Oracle JDK8的HotSpot ...

  7. 去除Win10快捷图标小箭头

    有点强迫症,一看到操作系统上的快捷图标小箭头就想把它去除掉. 去除小箭头 reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Cur ...

  8. Go语言中Socket通信之Tcp客户端

    1.用法: (1)定义远程IP地址.使用net.ResolveTCPAddr()方法,定义一个TCP地址,做为目标连接地址. (2)调用net.DialTCP("tcp",nil, ...

  9. claim概念图示

  10. Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)

    B. Case of Fugitive time limit per test 3 seconds memory limit per test 256 megabytes input standard ...