2.4. 使用 OpenSSL 为 TLS 客户端证书创建私钥和 CSR
您只有有了来自证书颁发机构(CA)的有效 TLS 证书时才可以使用 TLS 加密的通信频道。要获取证书,您必须首先为您的客户端创建私钥和证书签名请求(CSR)。
流程
在客户端系统上生成私钥,例如:
openssl genpkey -algorithm ec -pkeyopt ec_paramgen_curve:P-256 -out <client-private.key>
$ openssl genpkey -algorithm ec -pkeyopt ec_paramgen_curve:P-256 -out <client-private.key>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 可选:使用您选择的文本编辑器,来准备一个简化创建 CSR 的配置文件,例如:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow extendedKeyUsage = clientAuth
选项限制证书的使用。使用之前创建的私钥创建 CSR:
openssl req -key <client-private.key> -config <example_client.cnf> -new -out <client-cert.csr>
$ openssl req -key <client-private.key> -config <example_client.cnf> -new -out <client-cert.csr>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果省略了
-config
选项,req
工具会提示您额外的信息,例如:You are about to be asked to enter information that will be incorporated into your certificate request. … Common Name (eg, your name or your server's hostname) []: <client.example.com> Email Address []: <client@example.com>
You are about to be asked to enter information that will be incorporated into your certificate request. … Common Name (eg, your name or your server's hostname) []: <client.example.com> Email Address []: <client@example.com>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
后续步骤
- 将 CSR 提交给您选择的 CA 进行签名。或者,对于可信网络中的内部使用场景,请使用您的私有 CA 进行签名。如需更多信息,请参阅使用私有 CA 为带有 OpenSSL 的 CSR 发布证书 部分。
验证
检查证书的人类可读部分是否与您的要求匹配,例如:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow