TLSv1.2

news/2024/12/22 20:38:10/

文章目录

  • 简介
  • 6. The TLS Record Protocol
    • 6.1. Connection States
    • 6.2. Record Layer
    • 6.3. Key Calculation
  • 7. The TLS Handshaking Protocols
    • 7.1. Change Cipher Spec Protocol
    • 7.2. Alert Protocol
    • 7.3. Handshake Protocol Overview
    • 7.4. Handshake Protocol
  • 10. Application Data Protocol
  • Appendix A. Protocol Data Structures and Constant Values
  • OpenSSL示例
  • 参考资料

参考版本:TLS v1.2,因为该版本应用较多。部分参考v1.3

简介

SSL,Secure Socker Layer,1995年发布3.0版本,但2014年发现有Poodle安全漏洞(CVE-2014-3566)。

TLS,Transport Layer Security,TLS 1.0相当于SSL 3.1,由IETF设计。相关文档RFC 2246: TLS Version 1.0 ,更新历史:

  • RFC 4346: TLS Version 1.1 ,增加CBC攻击防御对策、AES;
  • RFC 5246: TLS Version 1.2,增加GCM, CCM HMAC-SHA256, 删除IDEA和DES,伪随机函数改用SHA256实现;
  • RFC 8446: TLS Version 1.3,握手协议相比1.2,精简了步骤,减少了风险。

每个版本的更新内容都可以在1.2小节里查看。双方通信时需要先商议使用哪个TLS版本。目前TLS 1.2应用较多,毕竟十年后才发布了1.3。

SSL可以承载各种协议,如发送邮件的SMTP和接收邮件的POP3,应用最广泛的就是HTTPS,HTTP over SecureSocket Layer,相当于HTTP+TLS,文档RFC 2818: HTTP Over TLS。

The protocol is composed of two layers:

  • the TLS Record Protocol
    • The connection is private - Symmetric cryptography
    • The connection is reliable - keyed MAC
  • the TLS Handshake Protocol
    • Authentication: The server side of the channel is always authenticated; the client side is optionally authenticated.
    • Confidentiality
    • Integrity

6. The TLS Record Protocol

V1.2: The TLS Record Protocol is used for encapsulation of various higher- level protocols.

V1.3: The record protocol uses the parameters established by the handshake protocol to protect traffic between the communicating peers.

The TLS Record Protocol is a layered protocol.

At each layer, messages may include

  • fields for length
  • description
  • and content.

The Record Protocol takes messages to

  • be transmitted
  • fragments the data into manageable blocks
  • optionally compresses the data
  • applies a MAC
  • encrypts
  • and transmits the result.

Received data is

  • decrypted
  • verified
  • decompressed
  • reassembled
  • and then delivered to higher-level clients.

Four protocols that use the record protocol are described in this document:

  • the handshake protocol
  • the alert protocol
  • the change cipher spec protocol
  • and the application data protocol.

6.1. Connection States

struct {ConnectionEnd entity;PRFAlgorithm prf_algorithm;BulkCipherAlgorithm bulk_cipher_algorithm;CipherType cipher_type;uint8 enc_key_length;uint8 block_length;uint8 fixed_iv_length;uint8 record_iv_length;MACAlgorithm mac_algorithm;uint8 mac_length;uint8 mac_key_length;CompressionMethod compression_algorithm;opaque master_secret[48];opaque client_random[32];opaque server_random[32];} SecurityParameters;

The record layer will use the security parameters to generate the following six items (some of which are not required by all ciphers, and are thus empty):

  • client write MAC key
  • server write MAC key
  • client write encryption key
  • server write encryption key
  • client write IV
  • server write IV

6.2. Record Layer

The TLS record layer receives uninterpreted data from higher layers in non-empty blocks of arbitrary size.

这一部分涉及多个结构,需要时再查。

6.3. Key Calculation

The Record Protocol requires an algorithm to generate keys required by the current connection state (see Appendix A.6) from the security parameters provided by the handshake protocol.

7. The TLS Handshaking Protocols

The Handshake Protocol is responsible for negotiating a session, which consists of the following items:

  • session identifier
  • peer certificate: X509v3 [PKIX]
  • compression method
  • cipher spec
    • the pseudorandom function (PRF)
    • data encryption algorithm
    • MAC algorithm (and mac_length)
  • 48-byte master secret
  • is resumable

证书就是带有CA数字签名的公钥。

X.509规范:RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile

7.1. Change Cipher Spec Protocol

struct {enum { change_cipher_spec(1), (255) } type;
} ChangeCipherSpec;

7.2. Alert Protocol

enum {warning(1), fatal(2), (255) 
}AlertLevel;
enum {close_notify(0),unexpected_message(10),bad_record_mac(20),decryption_failed_RESERVED(21),record_overflow(22),decompression_failure(30),handshake_failure(40),no_certificate_RESERVED(41),bad_certificate(42),unsupported_certificate(43),certificate_revoked(44),certificate_expired(45),certificate_unknown(46),illegal_parameter(47),unknown_ca(48),access_denied(49),decode_error(50),decrypt_error(51),export_restriction_RESERVED(60),protocol_version(70),insufficient_security(71),internal_error(80),user_canceled(90),no_renegotiation(100),unsupported_extension(110),(255)} AlertDescription;struct {AlertLevel level;AlertDescription description;} Alert;

7.3. Handshake Protocol Overview

When a TLS client and server first start communicating, they

  • agree on a protocol version
  • select cryptographic algorithms,
  • optionally authenticate each other,
  • use public-key encryption techniques to generate shared secrets.

Steps:

  1. Exchange hello messages
  2. Exchange the necessary cryptographic parameters to agree on a premaster secret.
  3. Exchange certificates and cryptographic information
  4. Generate a master secret from the premaster secret and exchanged random values.
  5. Provide security parameters to the record layer
  6. Allow the client and server to verify that their peer has calculated the same security parameters and that the handshake occurred without tampering by an attacker.

注意,以上步骤并不能防止中间人攻击。

The ClientHello and ServerHello establish the following attributes:

  • Protocol Version
  • Session ID, Cipher Suite
  • Compression Method
  • exchange: ClientHello.random and ServerHello.random.

The actual key exchange uses up to four messages:

  • the server Certificate
  • the ServerKeyExchange
  • the client Certificate
  • the ClientKeyExchange
client server ClientHello ServerHello Certificate* ServerKeyExchange* CertificateRequest* ServerHelloDone Certificate* ClientKeyExchange CertificateVerify* [ChangeCipherSpec] Finished [ChangeCipherSpec] Finished Application Data client server

星号代表可选。

ChangeCipherSpec并不是握手协议,而是一个单独的TLS子协议。

如果双方要续用之前的会话,则握手如下:

client server ClientHello ServerHello [ChangeCipherSpec] Finished [ChangeCipherSpec] Finished Application Data client server

7.4. Handshake Protocol

这一部分这列出消息类型,至于每种消息的格式,这里就不搬运了。

 enum {hello_request(0), client_hello(1), server_hello(2),certificate(11), server_key_exchange (12),certificate_request(13), server_hello_done(14),certificate_verify(15), client_key_exchange(16),finished(20), (255)} HandshakeType;struct {HandshakeType msg_type; /* handshake type */uint24 length; /* bytes in message */select (HandshakeType) {case hello_request: HelloRequest;case client_hello: ClientHello;case server_hello: ServerHello;case certificate: Certificate;case server_key_exchange: ServerKeyExchange;case certificate_request: CertificateRequest;case server_hello_done: ServerHelloDone;case certificate_verify: CertificateVerify;case client_key_exchange: ClientKeyExchange;case finished: Finished;} body;} Handshake;

10. Application Data Protocol

Application data messages are carried by the record layer and are fragmented, compressed, and encrypted based on the current connection state.

The messages are treated as transparent data to the record layer.

Appendix A. Protocol Data Structures and Constant Values

附录A定义了各个子协议的枚举类型,抓包分析时可以对照一下,当然wireshark都自动标注了。

A.1. Record Layer

A.2. Change Cipher Specs Message

A.3. Alert Messages

A.4. Handshake Protocol

A.5. The Cipher Suite

A.6. The Security Parameters

OpenSSL示例

https://github.com/C0deStarr/TestOpenSSL/tree/master/tls

参考资料

RFC 5246: TLS Version 1.2

RFC 8446: TLS Version 1.3


http://www.ppmy.cn/news/336686.html

相关文章

世界大洲地图中如何把太平洋移到地图的中心

在layers下点击属性,选择coordinate system,找到modify,把原始经度平移180度,也就是格林威治零点定在180度,然后在transfomation选择一种方法,x平移给定一个数如0,就可以激活。 如没有转换之前…

按几大洲或国家,访问指定服务器

针对前一片文章,我们只是解决国内访问国内服务器,国外访问国外服务器; 问题来了,如果境外的用户离国内服务器近,离境外服务器远怎么实现? 解决方案: 域名解析,需购买企业标准版,价…

世界地图各大洲鼠标移入切换显示

需求&#xff1a; 做到世界地图各大洲鼠标移入切换显示对应数据和样式&#xff1b; 移入对应大洲版本&#xff0c;对应洲板块地图颜色改变&#xff1b;对应对应大洲信息 代码&#xff1a; html代码&#xff1a; <section class"contact2-section"><div c…

主板供电电压

内存供电&#xff1a;SDRAM是3.3v。DDR是2.5v供电和上拉电压1.25v。DDR2是1.8v和上拉0.9v&#xff01;DDR3和DDR2的一样吧&#xff01;cpu供电1.2v3南桥是5v&#xff0c;3.3v&#xff0c;1.8v&#xff0c;1.2v&#xff0c;1.5v4&#xff0c;I/O是3.3v5&#xff0c;时钟是3.3v或…

CPU低功耗设计

2021-07-16 1、 设备第一次给电源&#xff0c;1.8V电源一直给VRTC&#xff0c;CPU_VMEM&#xff0c;WKUP&#xff0c;BOOT和RESET供电&#xff0c;其他电源通过按键通断电&#xff0c;给设备供电&#xff0c;设备不启动。需要按一下RESET设备才启动。设备睡眠之后可以正常通过按…

功耗结构设计

功耗结构设计 在COMS技术中,动态功耗与门和金属引线的寄生电容充放电有关。 因此,为了减少驱动电流,必须减少这三个关键的参数。在FPGA设置中,电压通常是固定的,只留下电容C和频率f对电流的操纵。电容C直接与随时被触发的门的数量以及连接这些门的布线长度有关,频率f直…

电脑主板的BIOS参数为何要使用电池来存储?

也许很多人都还不知道&#xff0c;其实在每一块电脑主板上都安装有一颗纽扣电池&#xff08;CMOS电池&#xff09;&#xff0c;是专门为了保存电脑硬件配置信息参数用的&#xff0c;但目前存储技术已经非常成熟&#xff0c;完全不需要电池就可以实现存储&#xff0c;为什么这些…

【低功耗】CMOS基础,功耗分类,低功耗方法

学习资料 &#x1f517;百度网盘 密码&#xff1a;csdn 学习路线&#xff0c;以Synopsys Flow举例&#xff1a; 中文文档&#xff0c;建立低功耗相关概念 IEEE Std 1801™ UPF3.0协议&#xff0c;根据标准协议查缺补漏。EDA工具还没有完全支持。 Low Power Methodology Manual,…