openssl 关于CA的使用

第一步:创建目录结构

这些结构与config文件有关系

A创建目录结构:certs、client、crl、newcerts、private

B创建文件index.txt  serial

C echo "01" > /etc/pki/CA/serial

第二步:配置文件

配置config文件:openssl.cnf

/etc/ssl/openssl.cnf有系统的default文件;

但不能直接运行,需要修改成自己的路径和key

[ CA_default ]

dir             = .             # 定义路径变量

certs           = $dir/certs              # 已颁发证书的保存目录

database        = $dir/index.txt          # 数据库索引文件

new_certs_dir   = $dir/newcerts           # 新签署的证书保存目录

certificate     = $dir/cacert.pem         # CA证书路径名

serial          = $dir/serial             # 当前证书序列号

private_key     = $dir/private/ca.key.pem  # CA的私钥路径名

[ policy_loose ]

# Allow the interediate CA to sign a more diverse range of certificates.

# See the POLICY FORMAT section of the `ca` man page.

countryName             = optional

stateOrProvinceName     = optional

localityName            = optional

organizationName        = optional

organizationalUnitName  = optional

commonName              = supplied

emailAddress            = optional

config的介绍可以参考这个网址

https://www.cnblogs.com/f-ck-need-u/p/6091027.html

第三步:生成CA的私钥

签署证书请求时需要CA自己的私钥文件,存放这个上面config中的private_key位置:

openssl genrsa -out private/ca.key.pem

第四步:相关CA 创建

A 创建秘钥

cd /root/ca/

openssl genrsa -aes256 \

      -out client/private/www.xx.com.key.pem 2048

B 提取公钥

# Remove the client certificate passphrase so it can be included in the cert file unencrypted

openssl rsa -in client/private/www.xx.com.key.pem -out client/private/www.xx.com.key.pem

chmod 400 client/private/www.xx.com.key.pem

C 创建证书请求文件

cd /root/ca

openssl req -config openssl.cnf \

      -key client/private/www.xx.com.key.pem \

      -new -sha256 -out client/csr/www.xx.com.csr.pem

D 签署该请求

cd /root/ca

openssl ca -config openssl.cnf \

      -extensions usr_cert -days 9135 -notext -md sha256 -policy policy_loose \

      -in client/csr/www.xx.com.csr.pem \

      -out client/certs/www.xx.com.cert.pem

chmod 444 client/certs/www.xx.com.cert.pem

第五步:pem--p12

将pem转成p12 ----- pkcs12

需要签署的CA文件和私钥一块才能转成p12

sudo openssl pkcs12 -export -in www.xx.com.cert.pem -inkey ../private/www.xx.com.key.pem -out www.xx.com.cert.p12

第六步:提取p12

解析p12---- pkcs12

openssl pkcs12 -in xx.p12 -out xx.pem -nodes

https://www.ssl.com/how-to/export-certificates-private-key-from-pkcs12-file-with-openssl/

第七布:输出查看CA 文件

这样就可以使用x509解析该签署CA文件

Openssl x509 -noout -text -in xx.pem

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值