自签文档签名证书
因为文档签名证书的密钥用法有:nonRepudiation, digitalSignature
所以可以在openssl.cnf文件中设置keyUsage = nonRepudiation, digitalSignature, keyEncipherment
1.生成根证书及自签名证书
-
1.创建根证书私钥
openssl genrsa -out root.key 1024
-
2.创建根证书请求文件
openssl req -new -out root-req.csr -key root.key -keyform PEM
-
3.自签根证书
openssl x509 -req -extfile openssl.cnf -extensions v3_req -in root-req.csr -out root-cert.cer -signkey root-key.key -CAcreateserial -days 3650
重要说明: -extfile openssl.cnf -extensions v3_req 参数是生成 X509 V3 版本的证书的必要条件。 openssl.cnf 是系统自带的OpenSSL配置文件,该配置文件默认开启 X509 V3 格式。下同。
-
4.导出P12格式证书
openssl pkcs12 -export -clcerts -in root-cert.cer -inkey root-key.key -out root.p12
2.使用根证书颁发证书
-
1.生成证书Key
openssl genrsa -out client-key.key 1024
-
2.生成证书请求文件
openssl req -new -out client-req.csr -key client-key.key
-
3.生成证书,并使用根证书签名
openssl x509 -req -extfile /etc/pki/tls/openssl.cnf -extensions v3_req -in client-req.csr -out client-cert.cer -signkey client-key.key -CA root-cert.cer -CAkey root-key.key -CAcreateserial -days 3650
-
4.生成客户端P12格式的证书
openssl pkcs12 -export -clcerts -in client-cert.cer -inkey client-key.key -out client.p12
3.查看证书信息
openssl x509 -in client-cert.cer -text -noout
**注意:**因为是自签证书,所以不在计算机的可信根证书列表中,所以需要我们将根证书添加到可信根证书中。