第一步:创建目录结构
这些结构与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