为防止根证书被污染,通常使用根证书签发的中介证书为客户作数字签署,得到终端实体证书。
中介证书的有效期会较根证书为短,并可能对不同类别的客户有不同的中介证书作分工。
终端实体证书不会用作签发其他证书。
可以配置以下参数
$opensslgenrsa-aes256-outfd.key2048#根据提示输入密码创建CSRCSR:CertificateSigningRequest,aformatrequestaskingaCAtosignacertificate,包含请求者的publickey和一些身份信息
$opensslreq-new-keyfd.key-outfd.csr#输出如下,交互式输入证书需要的信息Youareabouttobeaskedtoenterinformationthatwillbeincorporatedintoyourcertificaterequest.WhatyouareabouttoenteriswhatiscalledaDistinguishedNameoraDN.TherearequiteafewfieldsbutyoucanleavesomeblankForsomefieldstherewillbeadefaultvalue,Ifyouenter'.',thefieldwillbeleftblank.-----CountryName(2lettercode)[AU]:CNStateorProvinceName(fullname)[Some-State]:JiangsuLocalityName(eg,city)[]:NanjingOrganizationName(eg,company)[InternetWidgitsPtyLtd]:DafuTestOrganizationalUnitName(eg,section)[]:ITCommonName(e.g.serverFQDNorYOURname)[]:www.dafu.comEmailAddress[]:Pleaseenterthefollowing'extra'attributestobesentwithyourcertificaterequestAchallengepassword[]:Anoptionalcompanyname[]:challengepassword,optional,在吊销证书时,用于验证证书原来申请者身份的方式,很少有CA使用,不增加CSR安全性,建议留空
可以使用配置文件指定CSR必要信息,而避免交互式输入
$opensllreq-new-configfd.cnf-keyfd.key-outfd.csr配置文件如下:
[req]prompt=nodistinguished_name=dnreq_extensions=extinput_password=PASSPHRASE[dn]CN=www.feistyduck.comemailAddress=webmaster@feistyduck.comO=FeistyDuckLtdL=LondonC=GB[ext]subjectAltName=DNS:www.feistyduck.com,DNS:feistyduck.com自签证书自己签发证书,而非向CA申请,但需要另外添加信任
$opensslx509-req-sha256-inyour-domain.com.csr-CAroot.crt-CAkeyroot.key-CAcreateserial-outyour-domain.com.crt-days365-extfileyour-domain.com.extCAcreateserial这个参数是比较有意思的,意思是如果证书没有serialnumber就创建一个,因为我们是签名,所以肯定会创建一个。序列号在这里的作用就是唯一标识一个证书,当有两个证书的时候,只有给这两个证书签名的CA和序列号都一样的情况下,我们才认为这两个证书是一致的。除了自定生成,还可以通过-set_serial手动指定一个序列号。
当使用-CAcreateserial参数之后,会自动创建一个和CA文件名相同的,但是后缀是.srl的文件。这里存储了上一次生成的序列号,每次调用的时候都会读取并+1。也就是说每一次生成的证书的序列号都比上一次的加了一。
$opensslverifyroot.crt该证书必须已被添加到系统中,且信任
$opensslverify-CAfileroot.crtintermediate.crtcert.pem:OK校验三级证书
#catfd.key-----BEGINRSAPRIVATEKEY-----[...]-----ENDRSAPRIVATEKEY-----查看密钥内容:
$opensslrsa-text-infd.key#输出形如RSAPrivate-Key:(2048bit,2primes)modulus:[...]publicExponent:65537(0x10001)privateExponent:[...]prime1:[...]prime2:[...]exponent1:[...]exponent2:[...]coefficient:[...]writingRSAkey-----BEGINRSAPRIVATEKEY-----[...]-----ENDRSAPRIVATEKEY-----提取公钥$opensslrsa-infd.key-pubout-outfd-public.key#catfd-public.key-----BEGINPUBLICKEY-----[...]-----ENDPUBLICKEY-----查看CSR内容$opensslreq-text-infd.csr-noout#输出类似CertificateRequest:Data:Version:1(0x0)Subject:C=CN,ST=Jiangsu,L=Nanjing,O=DafuTest,OU=IT,CN=www.dafu.comSubjectPublicKeyInfo:PublicKeyAlgorithm:rsaEncryptionRSAPublic-Key:(2048bit)Modulus:[...]Exponent:65537(0x10001)Attributes:a0:00SignatureAlgorithm:sha256WithRSAEncryption[...]签发过程根证书可以使用-aes256参数加密,会提示输入密码
交互输入信息
generatesanRSAprivatekey
ThersacommandprocessesRSAkeys.Theycanbeconvertedbetweenvariousformsandtheircomponentsprintedout.
ThereqcommandprimarilycreatesandprocessescertificaterequestsinPKCS#10format.ItcanadditionallycreateselfsignedcertificatesforuseasrootCAsforexample.
多用途证书工具
常用参数:
生成证书链(注意顺序)
$catwww.example.com.crtbundle.crt>www.example.com.chained.crt