做仿真的TLS网络的时候需要自己动手建立CA和颁发证书,下面是一些笔记:
生成 CA 私钥
1
| openssl genrsa -out ca.key 4096
|
此处用到的是 4096
位的RSA私钥,可以选择 2048
位,不建议使用 1024
位
生成 CA 证书请求
1
| openssl req -new -days 365 -key cb.key -out cb.csr
|
CA 自签名
1
| openssl ca -selfsign -in ca.csr -out ca.crt -keyfile ca.key -cert ca.crt
|
生成服务器私钥
1
| openssl genrsa -out server.key 2048
|
生成服务器证书请求
1
| openssl req -new -days 365 -key server.key -out server.csr
|
使用 CA 签名服务器证书
1
| openssl ca -in server.csr -out server.crt -keyfile ca.key -cert ca.crt
|
可能遇到的问题
I am unable to access the ./demoCA/newcerts directory
解决方法:
1 2 3 4
| mkdir -p ./demoCA/{private,newcerts} && \ touch ./demoCA/index.txt && \ touch ./demoCA/serial && \ echo 00 > ./demoCA/serial
|
The organizationName field needed to be the same in the CA certificate
解决方法:
到 /usr/lib/ssl/openssl.cnf
,搜索 policy_match
,将内容改为:
1 2 3 4 5 6 7
| [ policy_match ] countryName = supplied stateOrProvinceName = supplied organizationName = supplied organizationalUnitName = optional commonName = supplied emailAddress = optional
|
countryName
、stateOrProvinceName
、organizationName
都设置为 supplied
除非注明,麦麦小家文章均为原创,转载请以链接形式标明本文地址。
版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
本文地址:https://blog.micblo.com/2019/03/31/OpenSSL-自建CA-和-自颁证书/