生成CA证书

1
2
# 1 生成 CA 私钥
openssl genrsa -out ca.key 1024
1
2
# 2 X.509 Certificate Signing Request (CSR) Management.
openssl req -new -key ca.key -out ca.csr

➜ keys 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]:Zhejiang Locality Name (eg, city) []:Hangzhou Organization Name (eg, company) [Internet Widgits Pty Ltd]:My CA Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:localhost Email Address []:

  • Organization Name (eg, company) [Internet Widgits Pty Ltd]: 后面生成客户端和服务器端证书的时候也需要填写,不能相同,例如:My CA, My Server, My Client。

  • Common Name (e.g. server FQDN or YOUR name) []: 是可以访问的域名

    1
    2
    
    # 3 X.509 Certificate Data Management.
    openssl x509 -req -in ca.csr -signkey ca.key -out ca.crt

申请服务端证书

1 生成密钥

1
2
3
4
# 生成服务器端私钥
openssl genrsa -out server.key 1024
# 生成服务器端公钥
openssl rsa -in server.key -pubout -out server.pem

2 生成证书请求文件

1
2
# 服务器端需要向 CA 机构申请签名证书,在申请签名证书之前依然是创建自己的 CSR 文件
openssl req -new -key server.key -out server.csr

3 申请证书

1
2
# 向自己的CA机构申请证书,签名过程需要 CA 的证书和私钥参与,最终颁发一个带有CA签名的证书
openssl x509 -req -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt

申请客户端证书

1 生成密钥

1
2
3
4
# 生成客户端私钥
openssl genrsa -out client.key 1024
# 生成客户端公钥
openssl rsa -in client.key -pubout -out client.pem

2 生成证书请求文件

1
2
# client 端
openssl req -new -key client.key -out client.csr

3 申请证书

1
2
# client 端到 CA 签名
openssl x509 -req -CA ca.crt -CAkey ca.key -CAcreateserial -in client.csr -out client.crt

证书匹配方式

  • 主机名(在地址栏中)与证书主题(Subject)中的通用名称(Common Name)完全匹配。

“CN”: “app.binbean.xyz”,

  • 主机名称与通配符通用名称(Common Name)相匹配。例如,www.example.com匹配通用名称* .example.com。

“CN”: “*.binbean.xyz”,

  • 主机名 在主题备用名称(SAN: Subject Alternative Name)字段中列出

“hosts”: [ “app.binbean.xyz” ]