使用openssl为ssl证书增加“使用者备用名称(DNS)”-创新互联

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

创新互联建站主营金台网站建设的网络公司,主营网站建设方案,成都app软件开发公司,金台h5成都微信小程序搭建,金台网站营销推广欢迎金台等地区企业咨询

主要修改在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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

网站标题:使用openssl为ssl证书增加“使用者备用名称(DNS)”-创新互联
文章来源:https://www.cdcxhl.com/article32/pphpc.html

成都网站建设公司_创新互联,为您提供用户体验电子商务网站收录网站设计外贸网站建设关键词优化

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网页设计公司