1、statem.c write_state_machine()
读写状态机流程暂不考虑
客户端的构造函数:ossl_statem_client_construct_message()
根据状态,调用不用的构造函数
状态:TLS_ST_CW_CLNT_HELLO:调用tls_construct_client_hello()
状态:TLS_ST_CW_FINISHED:调用tls_construct_finished()
2、 statem_clnt.c tls_construct_client_hello()
其实就是构造:CLIENTHELLO_MSG结构体,接下来看看数据是如何组成的?
3、具体的数据。
记录层头:
Content Type:记录层子协议类型,22代表握手
Version:支持的版本最低为TLS1.0
Length:后续数据长度
握手协议消息:
Handshake Type:1代表ClientHello
Length:后续数据长度
Version:int legacy_version:03 03 (771 代表的是TLS1_2_VERSION)
Random:char random[SSL3_RANDOM_SIZE] 32位随机数 前4字节为时间戳,后28字节为安全随机数
Session ID:size_t session_id_len 20 TLS1.3以前的版本支持会话恢复,在TLS1.3已经用PSK替代,在兼容模式下,该字段必须非空。
size_t dtls_cookie_len 0
char dtls_cookie[DTLS1_COOKIE_LENGTH] 没有数据
PACKET ciphersuites
32:接下来的数据长度。
13 02:0x13,0x02 - TLS_AES_256_GCM_SHA384 TLSv1.3 Kx=any Au=any Enc=AESGCM(256) Mac=AEAD
13 03:0x13,0x03 - TLS_CHACHA20_POLY1305_SHA256 TLSv1.3 Kx=any Au=any Enc=CHACHA20/POLY1305(256) Mac=AEAD
13 01:0x13,0x01 - TLS_AES_128_GCM_SHA256 TLSv1.3 Kx=any Au=any Enc=AESGCM(128) Mac=AEAD
C0 2C:0xC0,0x2C - ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(256) Mac=AEAD
C0 30:0xC0,0x30 - ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
00 9F:0x00,0x9F - DHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=DH Au=RSA Enc=AESGCM(256) Mac=AEAD
CC A9:0xCC,0xA9 - ECDHE-ECDSA-CHACHA20-POLY1305 TLSv1.2 Kx=ECDH Au=ECDSA Enc=CHACHA20/POLY1305(256) Mac=AEAD
CC A8:0xCC,0xA8 - ECDHE-RSA-CHACHA20-POLY1305 TLSv1.2 Kx=ECDH Au=RSA Enc=CHACHA20/POLY1305(256) Mac=AEAD
CC AA:0xCC,0xAA - DHE-RSA-CHACHA20-POLY1305 TLSv1.2 Kx=DH Au=RSA Enc=CHACHA20/POLY1305(256) Mac=AEAD
C0 2B :0xC0,0x2B - ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(128) Mac=AEAD
C0 2F :0xC0,0x2F - ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(128) Mac=AEAD
00 9E :0x00,0x9E - DHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AESGCM(128) Mac=AEAD
C0 24 :0xC0,0x24 - ECDHE-ECDSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA384
C0 28 :0xC0,0x28 - ECDHE-RSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA384
00 6B :0x00,0x6B - DHE-RSA-AES256-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AES(256) Mac=SHA256
C0 23:0xC0,0x23 - ECDHE-ECDSA-AES128-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(128) Mac=SHA256
C0 27:0xC0,0x27 - ECDHE-RSA-AES128-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA256
00 67:0x00,0x67 - DHE-RSA-AES128-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AES(128) Mac=SHA256
C0 0A :0xC0,0x0A - ECDHE-ECDSA-AES256-SHA TLSv1 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA1
C0 14 :0xC0,0x14 - ECDHE-RSA-AES256-SHA TLSv1 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA1
00 39 :0x00,0x39 - DHE-RSA-AES256-SHA SSLv3 Kx=DH Au=RSA Enc=AES(256) Mac=SHA1
C0 09 :0xC0,0x09 - ECDHE-ECDSA-AES128-SHA TLSv1 Kx=ECDH Au=ECDSA Enc=AES(128) Mac=SHA1
C0 13 :0xC0,0x13 - ECDHE-RSA-AES128-SHA TLSv1 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA1
00 33:0x00,0x33 - DHE-RSA-AES128-SHA SSLv3 Kx=DH Au=RSA Enc=AES(128) Mac=SHA1
size_t compressions_len : 0
compressions[MAX_COMPRESSIONS_SIZE] 没有数据
PACKET extensions:
扩展supported_groups:客户端通知服务器自身支持的椭圆曲线列表,这里支持了五种曲线x25519、secp256r1、x448、secp521r1、secp284r1
扩展extended_master_secret:TLS1.2版本字段,不用关注
扩展signature_algorithms:签名算法,如ecdsa_secp256r1_sha256表示哈希算法为sha256,签名算法用ecdsa
扩展supported_versions:支持的版本,必须设置为0x0304,即TLS1.3版本
扩展key_share:客户端共享密钥,其实就是密钥协商交换的公钥,采用x25519曲线,公钥长度为32字节
size_t pre_proc_exts_len; 没有这个结构
RAW_EXTENSION *pre_proc_exts; 没有这个结构
00 |03 03 | C4 8C 4A C2 00 41 63 8C 86 E9 3D 20 CB 42 C2 B2 B3 6C C2 17 AA A1 A7 32 4A DE 00 B0 54 DC 1F 95 |
20 |
41 D9 82 3D 8E 2C 24 84 45 2D C8 4E 4F 2F 57 1D 33 D0 74 39 51 A0 B7 54 44 38 FA D3 74 B3 4D 09 |
00 |
32 | 数据长度
13 02 13 03 13 01 C0 2C C0 30 00 9F CC A9 CC A8 CC AA C0 2B C0 2F 00 9E C0 24 C0 28 00 6B C0 23 C0 27 00 67 C0 0A C0 14 00 39 C0 09 C0 13 00 33 |
00
FF 01 00 00 97 00
0B :TLSEXT_TYPE_ec_point_formats
00 04 (后面的长度)
03 00 01 02 00 (03代表长度,后面的是具体值)
0A :TLSEXT_TYPE_supported_groups
00 16 后面的长度
00 14 后面的长度
00 1D :X25519 (29)
00 17 :secp256r1 (23)
00 1E :X448 (30)
00 19 :secp521r1 (25)
00 18 :secp384r1 (24)
01 00 :ffdhe2048 (0x100)
01 01 :ffdhe3072 (0x101)
01 02:ffdhe4096 (0x102)
01 03 :ffdhe6144 (0x103)
01 04 :ffdhe8192 (0x104)
00
16 :TLSEXT_TYPE_encrypt_then_mac
00 00 00
17 :TLSEXT_TYPE_extended_master_secret
00 00 00
0D :TLSEXT_TYPE_signature_algorithms
00 30 00 2E 两个长度
04 03 :1027(0x0403) ecdsa_secp256r1_sha256
05 03 :1283 ecdsa_secp384r1_sha384
06 03 :1539 ecdsa_secp521r1_sha512
08 07 :2055 ed25519
08 08 :2056 ed448
08 1A :2074 ecdsa_brainpoolP256r1_sha256
08 1B :2075 ecdsa_brainpoolP384r1_sha384
08 1C :2076 ecdsa_brainpoolP512r1_sha512
08 09 :2057 rsa_pss_pss_sha256
08 0A :2059 rsa_pss_pss_sha512
08 0B
08 04 :2052 rsa_pss_rsae_sha256
08 05 :2053 rsa_pss_rsae_sha384
08 06 :2054 rsa_pss_rsae_sha512
04 01 :1025 rsa_pkcs1_sha256
05 01 :1281 rsa_pkcs1_sha384
06 01 :1537 rsa_pkcs1_sha512
03 03
03 01 :769 rsa_pkcs1_sha224
03 02
04 02
05 02
06 02
00
2B : TLSEXT_TYPE_supported_versions
00 05 04 03 04 03 03 00
2D :TLSEXT_TYPE_psk_kex_modes
00 02 01 01 00
33 :TLSEXT_TYPE_key_share (十进制的51)
00 26 00 24 | 后面加起来是24(十进制的36长度=下面两行的长度)
00 1D 00 20 | (1D=29) (20=32,代表公钥的长度)
28 29 52 D5 89 06 C5 5D C8 18 64 D3 F6 0D D6 26 F5 0F D4 49 6C 47 28 2E D2 91 35 59 11 E1 00 3A 代表公钥