介绍如何使用openssl生成 CSR 文件。
介绍
多域名证书,简单说是一个证书中包含多个域名,一说为SAN certificater(SubjectAltName Certificater),一说为Unified Communications Certificater(这个是微软的说法),已经迅速成为一种深受大家欢迎的证书,通过这种证书,可以方便部署Exchange, OCS 等经常有多个服务名的应用系统,此外也便于企业的网络管理人员对证书管理。
如果是申请Geotrust 的多域名证书,只需要按普通的CSR生成方法,取最重要的域名做CSR文件即可,下面我们仅就技术角度介绍一下,如何生成包含多个域名的CSR文件:
制作CSR文件制作
制作多域名的CSR文件,首先我们先要准备好OPENSSL工具,可以去http://www.openssl.org/下载,然后我们做配置一个conf文件,如下:
[ req ]
default_bits = 2048
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
req_extensions = req_ext
[ req_distinguished_name ]
# Minimum of 4 bytes are needed for common name
commonName = xiexianbin
commonName_default = *.xiexianbin.cn
commonName_max = 64
# ISO2 country code only
countryName = China
countryName_default = CN
# State is optional, no minimum limit
stateOrProvinceName = State
stateOrProvinceName_default = HeNan
# City is required
localityName = City
localityName_default = Zheng Zhou
# Organization is optional
organizationName = Organization
organizationName_default = xiexianbin
# Organization Unit is optional
organizationalUnitName = Department
organizationalUnitName_default = IT
# Email is optional
emailAddress = Email
emailAddress_default = me@xiexianbin.cn
[ req_ext ]
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.ymall.xyz
DNS.2 = *.ycloud.xyz
DNS.3 = *.scloud.xyz
DNS.4 = *.521.xyz
DNS.5 = *.166.xyz
其中:
- commonName_default: 证书的主域名
- organizationName_default: 企业/单位名称
- organizationalUnitName_default: 企业部门
- localityName_default: 城市
- stateOrProvinceName_default: 省份
- countryName_default: 国家代码,一般都是CN(大写)
- [alt_names]: 后面为备用名称列表
配置好该文件后,保存为san.conf,然后运行下面命令:
openssl req -new -nodes -out myreq.csr -config san.conf -batch
或
openssl req -new -newkey rsa:4096 -nodes -sha256 -subj "/C=CN/ST=He Nan/L=Zheng Zhou/O=xiexianbin/OU=IT/CN=*.xiexianbin.cn/emailAddress=me@xiexianbin.cn" -config <(
cat <<-EOF
[req]
default_bits = 4096
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
[ dn ]
[ req_ext ]
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.ymall.xyz
DNS.2 = *.zcloud.xyz
DNS.3 = *.ycloud.xyz
DNS.4 = *.166.xyz
DNS.5 = *.521.xyz
EOF
)
查看证书
openssl s_client -showcerts -servername xiexianbin.cn -connect xiexianbin.cn:443
openssl s_client -showcerts -connect xiexianbin.cn:443