如何利用openssl工具生成自签名证书
需求
通过自签名的CA证书,模拟CA机构签发服务端证书和客户端证书,为设备提供双向认证功能。
涉及的文件如下:
文件 | 用途 |
---|---|
ca.key | CA私钥,用于生成自签名CA证书 |
ca.pem | PEM格式的自签名CA证书,用于签发服务端证书和客户端证书,并需要提供给服务端和客户端用于https双向认证 |
server.key | 服务端私钥,需要提供给服务端 |
server.pem | PEM格式的服务端证书,使用ca.pem签发,需要提供给服务端 |
thirdapp.key | 客户端私钥,需要提供给第三方应用,作为第三方应用的客户端私钥 |
thirdapp.pem | PEM格式的客户端证书,需要提供给第三方应用,作为第三方应用的客户端证书 |
client.p12 | PCKS12格式客户端证书,用于windows客户端使用浏览器访问服务端。 |
制作过程
1. 生成CA证书
执行命令如下:
-
随机生成CA私钥,并进行查看
root@root:~/cert# openssl genrsa -out ca.key 2048 Generating RSA private key, 2048 bit long modulus .....................................................+++ ......................................................................................................................................................................................................................+++ e is 65537 (0x010001) root@root:~/cert# ls -l total 4 -rw------- 1 root root 1679 Jun 10 04:19 ca.key
-
生成证书请求,根据提示输入国家码、省市信息、公司部门信息等
root@root:~/cert# openssl req -new -key ca.key -out ca.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:Beijing Locality Name (eg, city) []:Beijing Organization Name (eg, company) [Internet Widgits Pty Ltd]:Fortigate Organizational Unit Name (eg, section) [<