TLS 安全通信

第 15 课:TLS 安全通信 对应源文件: trantor/net/TLSPolicy.h — TLS 策略配置(证书、验证规则、ALPN 等) trantor/net/Certificate.h — 证书抽象接口 trantor/net/inner/TLSProvider.h — TLS 提供者抽象基类(策略模式) 具体实现(未深入):OpenSSLProvider.cc(OpenSSL 后端)、BotanTLSProvider.cc(Botan 后端) 一、TLS 在 trantor 中的架构 trantor 的 TLS 是完全透明的——插入到 TcpConnectionImpl 和用户代码之间,用户几乎感知不到加密的存在: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 用户代码(send/recvMsgCallback) │ ▲ │ 明文数据 │ 解密后的明文 ▼ │ ┌───────────────────────────┐ │ TLSProvider │ ← 透明加密/解密层 │ startEncryption() │ │ sendData(明文) → 密文 │ │ recvData(密文) → 明文 │ └───────────────────────────┘ │ ▲ │ TLS 密文 │ 从 socket 读到的密文 ▼ │ TcpConnectionImpl(writeRaw / readBuffer_) │ ▼ TCP socket(内核) 策略模式(Strategy Pattern) TLSProvider 是一个纯虚接口,具体的 TLS 实现(OpenSSL、Botan)是策略类: ...

April 1, 2025 · 9 min · 1902 words