HTTPS原理、应用

HTTPS基本原理

                                           CA验证中心(颁发/吊销证书)
                                             /                          
                         CA 证书(CA公钥)    /            CA下发       WEB证书请求
                                           /                  证书    
                                    client <--------数字证书------ WEB
                             (CA私钥(签名))、WEB身份信息、WEB公钥)  
                                      
1.web服务器,生成非对称加密密钥对(web公钥,web私钥)
2.web服务器使用 web身份信息+web公钥 生成 web服务器的证书请求 ,并将证书请求发给CA服务器
3.CA服务器使用 CA的私钥 对 web 服务器的证书请求 进行数字签名,得到web服务器的数字证书,并将web服务器的数字证书颁发给web服务器。
4.client访问web服务器,请求https连接,下载web数字证书
5.client下载 CA数字证书(CA身份信息+CA公钥,由上一级CA颁发,也可自签名颁发),验证 web数字证书(CA数字证书中有CA公钥,web数字证书是使用CA私钥签名的)
6.client与web协商对称加密算法,client生成对称加密密钥并使用web公钥加密,发送给web服务器,web服务器使用web私钥解密
7.使用对称加密密钥传输数据,并校验数据的完整性

我们来模拟client与server之间的这种认证模式;

实验前的准备:我们用两台虚拟机来进行试验;CA服务器与server为一台;client;

先来对CA+server进行配置;

1.配置CA,生成CA自己的公钥、私钥;CA都对自己进行证书签名

[root@host4 ~]# vim /etc/pki/tls/openssl.cnf

 2.生成自签名证书

[root@host4 ~]# /etc/pki/tls/misc/CA -newca

 

/etc/pki/CA/private/cakey.pem  CA私钥

/etc/pki/CA/cacert.pem       CA自签数字证书

/etc/pki/CA/careq.pem       CA证书请求

3.配置WEB服务器

[root@sxb-1 httpd]# openssl genrsa -des3 -out /etc/httpd/conf.d/server.key
Generating RSA private key, 2048 bit long modulus
........................+++
.......+++
e is 65537 (0x10001)
Enter pass phrase for /etc/httpd/conf.d/server.key:
Verifying - Enter pass phrase for /etc/httpd/conf.d/server.key:

4.生成证书请求(使用身份表示+公钥)

[root@host4 ~]# openssl req -new -key /etc/httpd/conf.d/server.key -out /etc/httpd/conf.d/server.csr

5.将证书请求发给CA(这里我们用的私同一台虚拟机),CA服务器对证书进行数字签名;将签字后数字证书颁发给WEB

[root@host4 ~]# openssl ca -keyfile /etc/pki/CA/private/cakey.pem -cert /etc/pki/CA/cacert.pem -in /etc/httpd/conf.d/server.csr -out /etc/httpd/conf.d/server.crt

6.配置WEB支持ssl实现https

[root@host4 ~]# yum install mod_ssl
[root@host4 ~]# vim /etc/httpd/conf.d/ssl.conf

7.重启服务

[root@sxb-1 CA]# systemctl restart httpd
Enter SSL pass phrase for fe80::20c:29ff:fe88:9d40:443 (RSA) : ******
[root@sxb-1 CA]# ss -anplt | grep 443
LISTEN     0      128         :::443                     :::*                   users:(("httpd",pid=20066,fd=6),("httpd",pid=20065,fd=6),("httpd",pid=20064,fd=6),("httpd",pid=20063,fd=6),("httpd",pid=20062,fd=6),("httpd",pid=20060,fd=6))

8.client下载CA证书并导入到浏览器,然后访问www服务器;

原文地址:https://www.cnblogs.com/loganSxb/p/11266083.html