1. 修改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
2.openssl.cnf 中会要求部分文件及目录存在:
[root@localhost]#mkdir -p CA/{certs,crl,newcerts,private}
[root@localhost]# touch CA/index.txt
[root@localhost]#echo 00 > CA/serial
3.生成ca.key并自签署
openssl req -new -x509 -days 3650 -keyout ca.key -out ca.crt -config openssl.cnf
4.生成server.key
openssl genrsa -out server.key 2048
5.生成证书签名请求
openssl req -new -key server.key -out server.csr -config openssl.cnf
Common Name 这个写主要域名就好了(注意:这个域名也要在openssl.cnf的DNS.x里)
6.查看证书请求文件
openssl req -text -noout -in server.csr
7. 使用自签署的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服务器中使用的文件。
8.配置客户端互信
将ca.crt导入浏览器受信任的根证书颁发机构