[openssl] 使用openssl生成证书 [https][openssl] OpenSSL 公钥、私钥以及自签名证书 [ipsec][strongswan] 用strongswan pki工具生成自签名证书

使用openssl生成带域名的证书,SAN,subjectAltName, subject alternative name, DNS.

1. 生成私钥

openssl genrsa -out sni_test3.key 2048

2. 编写配置文件

默认会使用/etc/ssl/openssl.cnf

为了设置subject alternative name,所以需要写一个配置文件

[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req

[req_distinguished_name]
countryName = country
stateOrProvinceName = province
localityName = city
organizationName = company name
commonName = domain name or ip
 
[v3_req]
subjectAltName = @alt_names

[alt_names]
DNS.1=test1.www.local
DNS.2=test1.tls.local

3. 使用key和配置,生成证书请求

openssl req -new -key sni_test1.key -out sni_test1.csr -config test1.cnf  -subj '/C=CN/ST=BeiJing/L=BeiJing/O=tong.com/OU=tong/CN=caotong_test1/emailAddress=tong@local'

查看请求

openssl req -in sni_test1.csr -text -noout
。。。
        Attributes:
        Requested Extensions:
            X509v3 Subject Alternative Name: 
                DNS:test1.www.local, DNS:test1.tls.local
。。。

4 使用请求和根证书,签发新证书

openssl x509 -req -days 3650 -sha1 -CA ../root/root.cer -CAkey ../root/root.key -in sni_test1.csr -out sni_test1.cer \
--CAcreateserial --extensions v3_req --extfile ./test1.cnf

所以,签发的时候除了提供csr,还需要同时提供test1.cnf??

查看证书

openssl x509 -in sni_test1.cer -text -noout
。。。
        X509v3 extensions:
            X509v3 Subject Alternative Name: 
                DNS:test1.www.local, DNS:test1.tls.local
。。。

更多内容:

[https][openssl] OpenSSL 公钥、私钥以及自签名证书

[ipsec][strongswan] 用strongswan pki工具生成自签名证书

猜你喜欢

转载自www.cnblogs.com/hugetong/p/11579749.html