给定证书 (ca-cert.pem) 及其私钥 (ca-key.pem),使用 OpenSSL 签署提供的 CSR (csr.pem) 并为其生成证书 (cert.pem) -
openssl x509 -req -in csr.pem -out cert.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -days 365 -sha256
选项的含义 -
-
-CA创建串行- 证书的序列号将随机生成(并在将来的激活中增加)。
-
-第365天- 证书的有效期为 365 天。
-
-sha256- 证书将使用 SHA256 作为其签名算法(这是默认值)。
要生成具有“证书签名”密钥用法(以及您可能需要的 CA 基本约束)的此类证书,请创建一个配置文件 (config.txt) -
[extensions]
keyUsage = keyCertSign
basicConstraints = CA:TRUE
并将其提供给 OpenSSL(指向“扩展”部分)-
openssl x509 -req -in csr.pem -out cert.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -days 365 -sha256 -extfile config.txt -extensions extensions
检查生成的证书 -
openssl x509 -in cert.pem -noout -text
It has -
X509v3 extensions:
X509v3 Key Usage:
Certificate Sign
X509v3 Basic Constraints:
CA:TRUE
为了完整起见,以下是如何创建“提供的”CA 密钥、CA 自签名证书、主题密钥和 CSR(此处使用 RSA 密钥,可以相同地使用 EC 密钥) -
CA key -
openssl genpkey -algorithm RSA -out ca-key.pem -pkeyopt rsa_keygen_bits:2048
CA 自签名证书 -
openssl req -key ca-key.pem -new -x509 -days 365 -out ca-cert.pem -sha256 -subj /CN=CACert
主题键 -
openssl genpkey -algorithm RSA -out key.pem -pkeyopt rsa_keygen_bits:2048
主题密钥的 CSR -
openssl req -new -key key.pem -out csr.pem -sha256 -subj /CN=SubjectCert