openssl的配置文件:/etc/pki/tls/openssl.cnf
(1) 创建所需要的文件
# touch index.txt
# echo 01 > serial
(2) CA自签证书
# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
# openssl req -new -x509 -key /etc/pki/CA/private/cakey.epm -days 7300 -out /etc/pki/CA/cacert.pem
-new: 生成新证书签署请求;
-x509: 专用于CA生成自签证书;
-key: 生成请求时用到的私钥文件;
-days n:证书的有效期限;
-out /PATH/TO/SOMECERTFILE: 证书的保存路径;
Country Name (2 letter code) [XX]:CN //国家名称(2个字母代码)[XX]:CN
State or Province Name (full name) []:JS //州或省名(全名)[]:JS
Locality Name (eg, city) [Default City]:KS //地点名称(如城市)[默认城市]:KS
Organization Name (eg, company) [Default Company Ltd]:test.com // 组织名称(如公司)[Default Company Ltd]:test.com
Organizational Unit Name (eg, section) []:ops// 组织单位名称(例如,部分)[]:ops
Common Name (eg, your name or your server's hostname) []:CA.test.com // 通用名称(例如,您的姓名或服务器的主机名)[]:CA.test.com
Email Address []:admin@ca.test.com // 电子邮件地址[]:admin@ca.test.com
(3) 发证
(a) 用到证书的主机生成证书请求;
#(umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
# openssl req -new -key /etc/httpd/ssl/httpd.key -days 365 -out /etc/httpd/ssl/httpd.csr
Country Name (2 letter code) [XX]:CN // 国家名称(2个字母代码)[XX]:CN
State or Province Name (full name) []:JS //州或省名(全名)[]:JS
Locality Name (eg, city) [Default City]:KS // 地点名称(如城市)[默认城市]:KS
Organization Name (eg, company) [Default Company Ltd]:test.com // 组织名称(如公司)[Default Company Ltd]:test.com
Organizational Unit Name (eg, section) []:ops // 组织单位名称(例如,部分)[]:操作
Common Name (eg, your name or your server's hostname) []:nginx.test.com // 通用名称(例如,您的姓名或服务器的主机名)[]:nginx.test.com
Email Address []:admin@nginx.test.com // 电子邮件地址[]:admin@nginx.test.com
Please enter the following 'extra' attributes // 请输入以下“extra”属性
to be sent with your certificate request // 与您的证书请求一起发送
A challenge password []: // 可选密码[]:
An optional company name []: // 可选公司名称[]:
Sign the certificate? [y/n]:y // 签证? [y / n]:y
(b) 把请求文件传输给CA;
(c) CA签署证书,并将证书发还给请求者;
# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
查看证书中的信息:
#openssl x509 -in /PATH/FROM/CERT_FILE -noout -text|-subject|-serial
(4) 吊销证书
(a) 客户端获取要吊销的证书的serial
# openssl x509 -in /PATH/FROM/CERT_FILE -noout -serial -subject
(b) CA先根据客户提交的serial与subject信息,对比检验是否与index.txt文件中的信息一致;
吊销证书:
# openssl ca -revoke /etc/pki/CA/newcerts/SERIAL.pem
(c) 生成吊销证书的编号(第一次吊销一个证书)
# echo 01 > /etc/pki/CA/crlnumber
(d) 更新证书吊销列表
# openssl ca -gencrl -out thisca.crl
查看crl文件:
# openssl crl -in /PATH/FROM/CRL_FILE.crl -noout -text