openssl用来创建证书和私钥

创建证书和私钥:

为了单元测试而“伪造”的密钥和证书
以下一律使用password 或者passphrase 的地方都使用 123456

这里有两对证书私钥:

  1. ca CA角色的(校验、信任证书)
  2. keypair 一个普通用户的密钥/证书 对. 这个_keypair-signed_ certificate由上面这个 ca 签名

证书的CN值设置为 CN=tuans-mbp-2.raleigh.ibm.com.

这两组密钥对, 一个使用RSA密钥算法创建,另一个使用椭圆曲线密钥算法创建. 我在单元测试中使用的是EC密钥对. RSA密钥对位于后缀为“-rsa”的文件中.

所有的都由 openssl 创建.

对于椭圆曲线,使用 secp384r1 这个曲线. 注意GO的tls包只支持这3个曲线 secp256r1, secp384r1, secp521r1 对于 openssl and keytool 支持 更多. secp384r1 是最常用的一个.

  1. 创建CA 证书:
  2. 对于 RSA
- openssl req -new -x509 -keyout ca.key -out ca.crt  -days 3650
  1. 对于 EC
- openssl ecparam -name _secp384r1_ -out _secp384r1.pem_ (do this once only so *openssl* has an ec param file. It's possible to combine this with the genkey command but then Go cannot read the key file.)
- openssl ecparam -in secp384r1.pem -genkey -noout -out ca.key
- openssl req -x509 -new -key ca.key -out ca.crt -outform PEM -days 3650
  1. 创建被 CA 证书签名的密钥对
  2. for RSA
- openssl genrsa -out orderer.key 2048
  1. for EC
- openssl ecparam -in secp384r1.pem -genkey -noout -out orderer.key
  1. sign with CA certificate
- openssl req -new -key orderer.key -out orderer.csr -outform PEM
- openssl x509 -req -CA ca.crt -CAkey ca.key -in orderer.csr -out  orderer-signed.crt  -days 3650  -CAcreateserial -passin pass:123456

公用的命令

  • 查看已签名的证书:

    • openssl x509 -noout -text -in cert-file (should have an Issuer and a Subject sections)
  • 校验一个可用于签名的证书

    • openssl x509 -purpose -in ca_cert_file -inform PEM
    • check output for any purpose CA: YES
  • 验证信任链:

    • openssl verify -CAfile ca-cert-file cert-file
  • keystore explorer can read keystores and truststores

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
s

以上翻译自这里

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值