实验环境:
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
CA:192.168.1.107
WEB:192.168.1.110
在CA:
# yum -y install openssl openssl-devel
# ls /etc/pki/CA/
# ls /etc/pki/tls/
# vim /etc/pki/tls/openssl.cnf
在CA的工作目录,创建相关文件:
# cd /etc/pki/CA/
# touch index.txt
# echo 01 > serial
CA自签证书
# cd /etc/pki/CA
生成私钥:
# (umask 077;openssl genrsa -out private/cakey.pem 2048)
# (umask 077;openssl genrsa > private/cakey.pem 2048)
CA用私钥生成证书: cakey.pem------>cacert.pem
# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 365 -out /etc/pki/CA/cacert.pem
在 WEB:
# yum -y install httpd
# systemctl start httpd
# systemctl enable httpd
创建存放Web证书的目录:
# ls /etc/httpd
# mkdir /etc/httpd/ssl
生成Web私钥:
# cd /etc/httpd/ssl
# (umask 077;openssl genrsa -out http.key 2048)
WEB用私钥生成证书请求文件:
# cd /etc/httpd/ssl
# openssl req -new -key httpd.key -days 365 -out httpd.csr
将httpd.csr传给CA服务器:
# scp httpd.csr root@192.168.1.107:/tmp
在CA:
# ls /tmp
CA用自己的私钥对Web的请求证书进行签名,生成签名证书:
# openssl ca -in /tmp/httpd.csr -days 365 -out /tmp/httpd.crt
# cp /tmp/httpd.crt /etc/pki/CA/certs
发还给Web客户端:
# scp /tmp/httpd.crt root@192.168.1.110:/etc/httpd/ssl
在 Web:
删除请求证书
# rm -rf /etc/httpd/ssl/httpd.csr
# ll /etc/httpd/ssl/
# yum -y install mod_ssl
# vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
# systemctl restart httpd
在其他测试机器
https://192.168.1.110
添加解析到测试机
vim /ets/hosts
192.168.1.110 www.magedu.com
在CA机(192.168.1.107)
用http共享出去自己的证书:
# yum -y install httpd
# systemctl start httpd
# systemctl enable httpd
# cp /etc/pki/CA/cacert.pem /var/www/html/
在测试机获取CA 的证书:
https://192.168.1.107/cacert.pem
https://192.168.1.110
https://www.magedu.com
数字签名中公钥和私钥是什么?
http://www.sohu.com/a/198919210_100027651