创建证书和私钥:
为了单元测试而“伪造”的密钥和证书
以下一律使用password 或者passphrase 的地方都使用 123456
这里有两对证书私钥:
- ca CA角色的(校验、信任证书)
- 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 是最常用的一个.
- 创建CA 证书:
- 对于 RSA
- openssl req -new -x509 -keyout ca.key -out ca.crt -days 3650
- 对于 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
- 创建被 CA 证书签名的密钥对
- for RSA
- openssl genrsa -out orderer.key 2048
- for EC
- openssl ecparam -in secp384r1.pem -genkey -noout -out orderer.key
- 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
This work is licensed under a Creative Commons Attribution 4.0 International License.
s