一、证书
原版PFX证书
openssl pkcs12 -in myssl.pfx -nodes -out client.pem (使用这步骤就ok了,因为pem格式可以打开了)(-nodes表示导出时不对私钥进行加密。单词是no DES)
提取私钥
openssl rsa -in client.pem -out client.key
提出公钥
openssl x509 -in client.pem -out client.crt
常用命令补充:
#从pfx文件导出ca证书链(这样导出的ca.crt文件是root根证书和sub子证书合在一起的)
openssl pkcs12 -in myssl.pfx -cacerts -nokeys -out ca.crt
#openssl用公钥(即证书)crt+私钥key合并生成pfx
openssl pkcs12 -export -out client.pfx -inkey client.key -in client.crt -password pass:xxxxxxxx
注意:
windows的git bash for windows需要每条命令前加上使用winpty,否则不提示输入密码
二、curl命令访问
windows下
curl --key c:\t\client.key --cert c:\t\client.crt --cacert c:\t\ca.crt -F file=@abc.json https://aaa.abc.com/
linux下(--cacert 可以跟随多个证书。这里证书链有子证书。crt与cer一样)
curl --key ./client.key --cert ./client.crt --cacert ./"ca.cer" ./"caSubCAp.cer" -F file=@aaa.txt https://aaa.abc.com/