生成 ssl 证书

作者: MrTricker | 来源:发表于2019-07-03 15:18 被阅读0次

首先,创建文件夹。

$ mkdir /etc/nginx/ssl

创建根配置文件并写入配置项。

$ touch ca.example.cnf
[ ca ]
default_ca = ca_example

[ ca_example ]
dir           = /etc/nginx/ssl
certs         = /etc/nginx/ssl
new_certs_dir = /etc/nginx/ssl

private_key   = /etc/nginx/ssl/ca.example.key
certificate   = /etc/nginx/ssl/ca.example.crt

default_md    = sha256

name_opt      = ca_default
cert_opt      = ca_default
default_days  = 365
preserve      = no
policy        = policy_loose

[ policy_loose ]
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ req ]
prompt              = no
encrypt_key         = no
default_bits        = 2048
distinguished_name  = req_distinguished_name
string_mask         = utf8only
default_md          = sha256
x509_extensions     = v3_ca

[ v3_ca ]
authorityKeyIdentifier = keyid,issuer
basicConstraints       = critical, CA:true, pathlen:0
keyUsage               = critical, digitalSignature, keyCertSign
subjectKeyIdentifier   = hash

[ server_cert ]
authorityKeyIdentifier = keyid,issuer:always
basicConstraints       = CA:FALSE
extendedKeyUsage       = serverAuth
keyUsage               = critical, digitalSignature, keyEncipherment
subjectAltName         = @alternate_names
subjectKeyIdentifier   = hash

[ req_distinguished_name ]
O  = Your Organization Name
OU = Your Organization Unit
C  = UN
CN = Example Root CA

生成根 key 和 crt

$ openssl genrsa -out "/etc/nginx/ssl/ca.example.key" 4096
$ openssl req -config "/etc/nginx/ssl/ca.example.cnf" -key "/etc/nginx/ssl/ca.example.key" -x509 -new -extensions v3_ca -days 3650 -sha256 -out "/etc/nginx/ssl/ca.example.crt"

复制未注释的全局 openssl 配置项。

$ sed -i '/copy_extensions\ = \ copy/s/^#\ //g' /etc/ssl/openssl.cnf

创建普通配置文件并写入配置项。

$ touch /etc/nginx/ssl/example.cnf
[ ca ]
default_ca = ca_example

[ ca_example ]
dir           = /etc/nginx/ssl
certs         = /etc/nginx/ssl
new_certs_dir = /etc/nginx/ssl

private_key   = /etc/nginx/ssl/ca.example.key
certificate   = /etc/nginx/ssl/ca.example.crt

default_md    = sha256

name_opt      = ca_default
cert_opt      = ca_default
default_days  = 365
preserve      = no
policy        = policy_loose

[ policy_loose ]
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ req ]
prompt              = no
encrypt_key         = no
default_bits        = 2048
distinguished_name  = req_distinguished_name
string_mask         = utf8only
default_md          = sha256
x509_extensions     = v3_ca

[ v3_ca ]
authorityKeyIdentifier = keyid,issuer
basicConstraints       = critical, CA:true, pathlen:0
keyUsage               = critical, digitalSignature, keyCertSign
subjectKeyIdentifier   = hash

[ server_cert ]
authorityKeyIdentifier = keyid,issuer:always
basicConstraints       = CA:FALSE
extendedKeyUsage       = serverAuth
keyUsage               = critical, digitalSignature, keyEncipherment
subjectAltName         = @alternate_names
subjectKeyIdentifier   = hash

[ req_distinguished_name ]
O  = Your Organization Name
OU = Your Organization Unit
C  = UN
CN = example.com

[ alternate_names ]
DNS.1 = example.com
DNS.2 = *.example.com

生成普通 key、csr 和 crt 及根 srl

$ openssl genrsa -out "/etc/nginx/ssl/example.key" 2048
$ openssl req -config "/etc/nginx/ssl/example.cnf" -key "/etc/nginx/ssl/example.key" -new -sha256 -out "/etc/nginx/example.csr"
$ openssl x509 -req -extfile "/etc/nginx/ssl/example.cnf" -extensions server_cert -days 365 -sha256 -in "/etc/nginx/ssl/example.csr" -CA "/etc/nginx/ssl/ca.example.crt" -CAkey "/etc/nginx/ssl/ca.example.key" -CAcreateserial -out "/etc/nginx/ssl/example.crt"

相关文章

  • beego启用https

    启用https的话,首先要生成ssl证书 生成ssl证书 SSL证书包括: CA证书: 也叫根证书或者中间级证书,...

  • Beego实现HTTPS访问

    用https的话,首先要生成ssl证书生成ssl证书SSL证书包括: CA证书: 也叫根证书或者中间级证书,如果是...

  • SpringBoot HTTPS配置

    1、获取SSL证书 正式项目可以购买或者申请免费ssl证书,测试项目可以使用cmd自行生成ssl证书。 输入密码和...

  • Apache配置https

    Apache Apache命令 Apache开启https SSL生成证书:步骤1:生成密钥 步骤2: 生成证书请...

  • Kubernetes | 二进制软件包方式部署 -- 生成SSL

    03 生成集群SSL证书 集群所需的 SSL 证书均通过 cfssl 工具包来生成。 以下内容均在本地主机上操作,...

  • https配置、双向验证、go代码实现

    原理 参照这里: 双向认证SSL原理,已经说的很详细了 证书生成 根证书生成 服务端证书生成 客户端证书生成 ng...

  • autocert 与 nginx的配合

    autocert 负责生成SSL证书, 生成的证书配置在nginx中, nginx负责处理https请求. 使用a...

  • Nginx环境下http和https(ssl)共存的方法

    给nginx配置SSL证书后(这里使用的是自己生成的测试证书,参见 nginx使用ssl模块配置HTTPS支持),...

  • 生成 ssl 证书

    首先,创建文件夹。 创建根配置文件并写入配置项。 生成根 key 和 crt 复制未注释的全局 openssl 配...

  • Httpd配置CA证书

    apache httpd配置ssl证书部分记录证书生成相关请参考此链接

网友评论

    本文标题:生成 ssl 证书

    本文链接:https://www.haomeiwen.com/subject/xtiqhctx.html