测试主机:172.20.112.128(centos6.9:c6) 172.20.112.162(CA,centos7:c7)
[[email protected] ~]# vi /etc/pki/tls/openssl.cnf //一些配置固定的路径要注意
[[email protected] ~]# cd /etc/pki/CA/
[root CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
[root CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650 //生成自签名证书(相当于根证书)
CN --> beijing --> beijing --> magedu --> opt --> ca.magedu.com --> 默认 --> 自签名完成
[[email protected] CA]# cat cacert.pem
[[email protected] CA]# openssl x509 -in cacert.pem -noout -text //查看证书详情。也可传到windows查看,要改后缀,如改为cacert.pem.crt 方可查看
[[email protected] ~]# cd /data/ # (umask 066;openssl genrsa -out app.key 1024) //生成私钥 //在A主机操作
[[email protected] data]# openssl req -new -key app.key -out app.csr //生成证书申请文件,准备发给CA //在A主机操作
CN --> beijing --> beiging --> magedu --> devopt --> www.magedu.com ... //其中 CN beijing beijing 要和CA的一致
[[email protected] data]# scp app.csr 172.20.112.162:/etc/pki/CA //拷到CA主机进行签名 //在A主机操作
[[email protected] CA]# touch index.txt //不存在索引文件需要手工创建
[[email protected] CA]# echo 0F > serial //序列号
[[email protected] CA]# openssl ca -in app.csr -out certs/app.crt -days 100 //颁发证书。发现生成了文件index.txt.attr index.txt.old 0F.pem
[[email protected] CA]# diff certs/app.crt newcerts/0F.pem //比较发现一样
[[email protected] CA]# openssl x509 -in certs/app.crt -noout -text //查看证书详情
[[email protected] CA]# openssl verify -CAfile cacert.pem certs/app.crt //验证证书的有效期
[[email protected] CA]# sz certs/app.crt //把证书传到windows查看,但windows显示不信任
在windows操作:双击刚才生成的根证书cacert.pem.crt --> 安装证书 --> 当前用户 --> 将所有的证书都放入下列存储 --> 浏览 --> 受信任的根证书颁发机构 --> 完成;;;;然后点击app.crt发现受信任了,显示由ca.magedu.com颁发。
下面c7主机其它应用需要使用证书,如nginx
[[email protected] CA]# (umask 077;openssl genrsa -out app2.key 1024) //生成私钥
[[email protected] CA]# openssl req -new -key app2.key -out app2.csr //生成证书申请文件
CN --> henan --> zhengzhou --> mage --> opt --> app.magedu.com --> 默认...
[[email protected] CA]# cd /etc/pki/CA
[[email protected] CA]# openssl ca -in /data/app2.csr -out certs/app.crt -days 200 //颁发证书报错,因为申请文件和CA机构的省份和市不一致
[[email protected] CA]# vi /etc/pki/tls/openssl.cnf //改策略让上一步的不同省份和市也能颁发成功
policy = policy_match 改为 policy = policy_anything
[[email protected] CA]# openssl ca -in /data/app2.csr -out certs/app2.crt -days 200 //修改策略后发现重新颁发成功
[[email protected] CA]# cat index.txt.attr //同一份证书申请文件颁发多次证书限制修改
吊销证书:
[[email protected] CA]# openssl ca -revoke newcerts/11.pem
[[email protected] CA]# cat index.txt //发现被吊销的证书前面字母变成了 R
证书吊销列表(证书吊销后也要让用户知道):
淘宝的证书吊销列表:浏览器打开www.taobao.com --> 按F12 --> 点击Security --> 点击View certificate --> 点击 详细信息 --> 点击 ‘CRTL 分发点‘ ,复制 URL=http://crl.globalsign.com/gs/gsorganizationvalsha2g2.crl --> 浏览器把该url打开即可下载 --> 双击下载的文件即可查看
[[email protected] CA]# cat index.txt
V 181222013631Z 0F unknown /C=CN/ST=beijing/O=magedu/OU=devopt/CN=www.magedu.com
V 190401033124Z 10 unknown /C=CN/ST=henan/L=zhengzhou/O=mage/OU=opt/CN=app.magedu.com //newcerts/10.pem //证书
R 190401033700Z 180913034111Z 11 unknown /C=CN/ST=henan/L=zhengzhou/O=mage/OU=opt/CN=app.magedu.com //newcerts/11.pem //证书
[[email protected] CA]# openssl ca -gencrl -out /etc/pki/CA/crl.pem //发现生成吊销列表失败
[[email protected] CA]# echo 0F > crlnumber //创建吊销文件,用于记录序号
[[email protected] CA]# cat crl.pem //目前为空
[[email protected] CA]# openssl ca -gencrl -out /etc/pki/CA/crl.pem //重新生成吊销列表成功
[[email protected] CA]# cat crl.pem //发现该文件也有内容了。把crl.pem传到windows并改名为crl.pem.crl ,双击即可查看
[[email protected] CA]# openssl ca -revoke newcerts/10.pem //现在把10.pem证书也吊销
[[email protected] CA]# openssl ca -gencrl -out /etc/pki/CA/crl.pem //再次重新生成吊销列表
[[email protected] CA]# cat crlnumber //数字也递增了。现在再次把crl.pem传到windows查看即可。
[[email protected] CA]# openssl crl -in /etc/pki/CA/crl.pem -noout -text //查找证书吊销列表
原文地址:http://blog.51cto.com/12555197/2175534