温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用openssl为ssl证书增加“使用者备用名称(DNS)”

发布时间:2020-06-05 05:25:17 来源:网络 阅读:54392 作者:colinzhouyj 栏目:安全技术

上一片讲到了多CN的签署方式利用openssl签署多域名证书,在实际使用中遇到了一个问题,在android系统中,浏览器不识别多CN的域名,会报错“证书名称和服务器名称不符”,开始以为是自签署CA的问题,换成单个CN之后就正常了,没办法,只能换其他方法了,google N久之后,找到到了方法:


主要修改在openssl.cnf


# 确保req下存在以下2行(默认第一行是有的,第2行被注释了)
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req


# 确保req_distinguished_name下没有 0.xxx 的标签,有的话把0.xxx的0. 去掉
[ req_distinguished_name ]
countryName              = Country Name (2 letter code)
countryName_default = CN
stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default = ShangHai
localityName              = Locality Name (eg, city)
localityName_default = ShangHai
organizationalUnitName             = Organizational Unit Name (eg, section)
organizationalUnitName_default = Domain Control Validated
commonName         = Internet Widgits Ltd
commonName_max = 64


# 新增最后一行内容 subjectAltName = @alt_names(前2行默认存在)
[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names


# 新增 alt_names,注意括号前后的空格,DNS.x 的数量可以自己加
[ alt_names ]
DNS.1 = abc.example.com
DNS.2 = dfe.example.org
DNS.3 = ex.abcexpale.net


其他的步骤:

openssl.cnf中会要求部分文件及目录存在:

[root@localhost]#mkdir -p CA/{certs,crl,newcerts,private}

[root@localhost]# touch CA/index.txt

[root@localhost]#echo 00 > CA/serial


1.生成ca.key并自签署

openssl req -new -x509 -days 3650 -keyout ca.key -out ca.crt -config openssl.cnf


2.生成server.key(名字不重要)
openssl genrsa -out server.key 2048

3.生成证书签名请求
openssl req -new -key server.key -out server.csr -config openssl.cnf
Common Name 这个写主要域名就好了(注意:这个域名也要在openssl.cnf的DNS.x里)

4.查看请求文件
openssl req -text -noout -in server.csr 
应该可以看到这些内容:
    Certificate Request:
    Data:
    Version: 0 (0x0)
    Subject: C=US, ST=Texas, L=Fort Worth, O=My Company, OU=My Department,             CN=server.example
    Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public Key: (2048 bit)
    Modulus (2048 bit): blahblahblah
    Exponent: 65537 (0x10001)
    Attributes:
    Requested Extensions: X509v3
    Basic Constraints: CA:FALSE
    X509v3 Key Usage: Digital Signature, Non Repudiation, Key Encipherment
    X509v3 Subject Alternative Name: DNS:domain.example.com, DNS:xxx.example.com
    Signature Algorithm: sha1WithRSAEncryption
 

5.使用自签署的CA,签署server.scr
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -extensions v3_req -config openssl.cnf
#输入第一步设置的密码,一直按y就可以了


server.crt server.key就是web服务器中使用的文件。

NGINX 双向认证

如果要做NGINX客户端证书验证的话,重复2、3、4,并执行下面命令生成个人证书
5.生成个人证书
openssl  pkcs12 -export -inkey xxx.key -in xxx.crt -out  xxx.p12

将个人证书导入pc,同时在nginx ssl基础上增加设置:
ssl_verify_client on;
ssl_client_certificate ca.crt;


附件:http://down.51cto.com/data/2364976
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI