工作在应用层, 传输层 tcp 常用 80 443 port ; 继承 tcp 面向连接, 流量控制, 重传可靠;
http 可用但不够安全. 体现在明文交互; 可被中间环节监听, 更改;
上图:
三次握手--> HTTP-> TLS
客户端 服务器
| |
|-- SYN (Seq=X) ---------------------->|
|<-- SYN-ACK (Seq=Y, ACK=X+1) --------|
|-- ACK (Seq=X+1, ACK=Y+1) ----------->|
| | [TCP三次握手完成]
|-- Client Hello (TLS 1.3, SNI=example.com) -->|
|<-- Server Hello + Certificate + Server Key Exchange |
|-- Client Key Exchange + Change Cipher Spec -->|
|<-- Finished (加密) |
|-- Finished (加密) ------------------->|
| | [TLS握手完成]
|-- GET / HTTP/2 (加密) --------------->|
|<-- 200 OK (加密) |
握手报文作用:
client hello : 客户端发起握手,告知服务器自身支持的TLS版本、加密套件、随机数(Client Random)
server hello: 服务器响应客户端,选择双方支持的TLS版本、加密套件,并生成随机数(Server Random)
certificate, server key exchange, server hello done :服务器发送证书链,客户端通过验证证书确认服务器身份。
server key exchange: 服务器发送密钥交换参数(如ECDHE的公钥),用于生成预主密钥(Pre-Master Secret)
server hello done: 服务器告知客户端握手消息发送完毕
client key exchange: 客户端生成预主密钥(Pre-Master Secret),使用服务器公钥加密后发送
change cipher Spec: 客户端告知服务器后续报文将使用协商的加密参数加密
finished : 客户端发送加密的Finished报文,服务器解密后验证握手过程是否被篡改
服务器响应 change cipher spec 和 finished : 服务器完成密钥切换,发送加密的Finished报文,客户端验证后握手完成
挥手报文作用:
close_notify: 一方(客户端或服务器)发送close_notify
,告知对方不再发送数据, 另一方收到 后回复自己的 close_notify , 完成双向关闭。