当前位置:   article > 正文

用Wireshark分析TLS(v1.2)_wireshark tlsv1.2协议解密

wireshark tlsv1.2协议解密

准备工作

Wireshark是一个非常强大的网络分析软件,下载地址: Wireshark · Download,目前最新版本是4.0.4。选择Windows的安装包下载安装,安装后以管理员身份运行Wireshark,打开页面如下:
选择自己联网的网卡,我这里是用WLAN,点击左上角工具栏中蓝色的鲨鱼鳍开始捕获分组,用postman调用一个https的接口捕获结果如下(过滤器ip.addr == 43.138.42.168 and tls):
Linux下可以使用tcpdump命令抓取网络包,并保存为pcap格式,在Windows上用Wireshark可以打开这种格式的文件。
  1. # linux下用tcpdump抓取网络包
  2. # -i是抓取的指定网卡,port和host指定抓取的端口和主机 -w是保存为文件
  3. tcpdump -s 0 -i eth1 port 443 and host 43.138.42.168 -w https.pcap
从上面抓取的网络包中可以看出客户端与服务器通信的TLS版本为1.2。选取第一个包,内容结构如下图:
上图的包结构从上到下依次是 物理层的数据帧,数据链路层的Ethernet帧,IP层的IP包头,TCP层的TCP包头,TLS层及负载的上层HTTP数据

ClientHello

展开TLS层,这个包是ClientHello消息,全部展开后如下
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: Client Hello
  3. Content Type: Handshake (22)
  4. Version: TLS 1.0 (0x0301)
  5. Length: 253
  6. Handshake Protocol: Client Hello
  7. Handshake Type: Client Hello (1)
  8. Length: 249
  9. Version: TLS 1.2 (0x0303)
  10. Random: 8f8f55540f230fdab368448a24b2e5182b7fef7830dafd315defcd114abc55be
  11. GMT Unix Time: Apr 28, 2046 21:36:20.000000000 中国标准时间
  12. Random Bytes: 0f230fdab368448a24b2e5182b7fef7830dafd315defcd114abc55be
  13. Session ID Length: 32
  14. Session ID: 8b0e809778170dfa75738b0b9399f23169b0ae1f83019fb878124b341d3a42d8
  15. Cipher Suites Length: 36
  16. Cipher Suites (18 suites)
  17. Cipher Suite: TLS_AES_128_GCM_SHA256 (0x1301)
  18. Cipher Suite: TLS_AES_256_GCM_SHA384 (0x1302)
  19. Cipher Suite: TLS_CHACHA20_POLY1305_SHA256 (0x1303)
  20. Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f)
  21. Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (0xc02b)
  22. Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030)
  23. Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (0xc02c)
  24. Cipher Suite: TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca9)
  25. Cipher Suite: TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca8)
  26. Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA (0xc009)
  27. Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (0xc013)
  28. Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (0xc00a)
  29. Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (0xc014)
  30. Cipher Suite: TLS_RSA_WITH_AES_128_GCM_SHA256 (0x009c)
  31. Cipher Suite: TLS_RSA_WITH_AES_256_GCM_SHA384 (0x009d)
  32. Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA (0x002f)
  33. Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA (0x0035)
  34. Cipher Suite: TLS_RSA_WITH_3DES_EDE_CBC_SHA (0x000a)
  35. Compression Methods Length: 1
  36. Compression Methods (1 method)
  37. Compression Method: null (0)
  38. Extensions Length: 140
  39. Extension: server_name (len=20)
  40. Type: server_name (0)
  41. Length: 20
  42. Server Name Indication extension
  43. Server Name list length: 18
  44. Server Name Type: host_name (0)
  45. Server Name length: 15
  46. Server Name: selflias.com.cn
  47. Extension: extended_master_secret (len=0)
  48. Type: extended_master_secret (23)
  49. Length: 0
  50. Extension: renegotiation_info (len=1)
  51. Type: renegotiation_info (65281)
  52. Length: 1
  53. Renegotiation Info extension
  54. Renegotiation info extension length: 0
  55. Extension: supported_groups (len=8)
  56. Type: supported_groups (10)
  57. Length: 8
  58. Supported Groups List Length: 6
  59. Supported Groups (3 groups)
  60. Supported Group: x25519 (0x001d)
  61. Supported Group: secp256r1 (0x0017)
  62. Supported Group: secp384r1 (0x0018)
  63. Extension: ec_point_formats (len=2)
  64. Type: ec_point_formats (11)
  65. Length: 2
  66. EC point formats Length: 1
  67. Elliptic curves point formats (1)
  68. EC point format: uncompressed (0)
  69. Extension: session_ticket (len=0)
  70. Type: session_ticket (35)
  71. Length: 0
  72. Data (0 bytes)
  73. Extension: signature_algorithms (len=20)
  74. Type: signature_algorithms (13)
  75. Length: 20
  76. Signature Hash Algorithms Length: 18
  77. Signature Hash Algorithms (9 algorithms)
  78. Signature Algorithm: ecdsa_secp256r1_sha256 (0x0403)
  79. Signature Hash Algorithm Hash: SHA256 (4)
  80. Signature Hash Algorithm Signature: ECDSA (3)
  81. Signature Algorithm: rsa_pss_rsae_sha256 (0x0804)
  82. Signature Hash Algorithm Hash: Unknown (8)
  83. Signature Hash Algorithm Signature: SM2 (4)
  84. Signature Algorithm: rsa_pkcs1_sha256 (0x0401)
  85. Signature Hash Algorithm Hash: SHA256 (4)
  86. Signature Hash Algorithm Signature: RSA (1)
  87. Signature Algorithm: ecdsa_secp384r1_sha384 (0x0503)
  88. Signature Hash Algorithm Hash: SHA384 (5)
  89. Signature Hash Algorithm Signature: ECDSA (3)
  90. Signature Algorithm: rsa_pss_rsae_sha384 (0x0805)
  91. Signature Hash Algorithm Hash: Unknown (8)
  92. Signature Hash Algorithm Signature: Unknown (5)
  93. Signature Algorithm: rsa_pkcs1_sha384 (0x0501)
  94. Signature Hash Algorithm Hash: SHA384 (5)
  95. Signature Hash Algorithm Signature: RSA (1)
  96. Signature Algorithm: rsa_pss_rsae_sha512 (0x0806)
  97. Signature Hash Algorithm Hash: Unknown (8)
  98. Signature Hash Algorithm Signature: Unknown (6)
  99. Signature Algorithm: rsa_pkcs1_sha512 (0x0601)
  100. Signature Hash Algorithm Hash: SHA512 (6)
  101. Signature Hash Algorithm Signature: RSA (1)
  102. Signature Algorithm: rsa_pkcs1_sha1 (0x0201)
  103. Signature Hash Algorithm Hash: SHA1 (2)
  104. Signature Hash Algorithm Signature: RSA (1)
  105. Extension: key_share (len=38)
  106. Type: key_share (51)
  107. Length: 38
  108. Key Share extension
  109. Client Key Share Length: 36
  110. Key Share Entry: Group: x25519, Key Exchange length: 32
  111. Group: x25519 (29)
  112. Key Exchange Length: 32
  113. Key Exchange: a61abd6c612929a731944317da01f71321bad1cb973895cfe8421c73e70fcd72
  114. Extension: psk_key_exchange_modes (len=2)
  115. Type: psk_key_exchange_modes (45)
  116. Length: 2
  117. PSK Key Exchange Modes Length: 1
  118. PSK Key Exchange Mode: PSK with (EC)DHE key establishment (psk_dhe_ke) (1)
  119. Extension: supported_versions (len=9)
  120. Type: supported_versions (43)
  121. Length: 9
  122. Supported Versions length: 8
  123. Supported Version: TLS 1.3 (0x0304)
  124. Supported Version: TLS 1.2 (0x0303)
  125. Supported Version: TLS 1.1 (0x0302)
  126. Supported Version: TLS 1.0 (0x0301)
  127. [JA3 Fullstring: 771,4865-4866-4867-49199-49195-49200-49196-52393-52392-49161-49171-49162-49172-156-157-47-53-10,0-23-65281-10-11-35-13-51-45-43,29-23-24,0]
  128. [JA3: dda262729e5413660ec0e6a8d4279860]
可以看出TLS的记录层总共253字节,Content Type为握手数据。
ClientHello消息共占249字节,最高支持TLS 1.2版本。
Random是客户端的随机数。
Session ID长度为32字节。
支持的密码套件(Cipher Suite)有18个,占36字节,优先支持TLS_AES_128_GCM_SHA256。Compression Methods压缩方法为null。
扩展占140字节,第一个扩展是SNI扩展,请求的主机名为 selflias.com.cn
supported_groups扩展,支持三个曲线x25519、secp256r1、secp384r1。
还支持SessionTicket扩展。
signature_algorithms签名算法支持9种。

ServerHello

接下来是服务器回应的SeverHello消息,展开如下
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: Server Hello
  3. Content Type: Handshake (22)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 69
  6. Handshake Protocol: Server Hello
  7. Handshake Type: Server Hello (2)
  8. Length: 65
  9. Version: TLS 1.2 (0x0303)
  10. Random: fbdf8dffb78c84c8923d6499ff957f595694009ec2a88dd451a12263e416df36
  11. GMT Unix Time: Nov 29, 2103 06:28:15.000000000 中国标准时间
  12. Random Bytes: b78c84c8923d6499ff957f595694009ec2a88dd451a12263e416df36
  13. Session ID Length: 0
  14. Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f)
  15. Compression Method: null (0)
  16. Extensions Length: 25
  17. Extension: renegotiation_info (len=1)
  18. Type: renegotiation_info (65281)
  19. Length: 1
  20. Renegotiation Info extension
  21. Renegotiation info extension length: 0
  22. Extension: server_name (len=0)
  23. Type: server_name (0)
  24. Length: 0
  25. Extension: ec_point_formats (len=4)
  26. Type: ec_point_formats (11)
  27. Length: 4
  28. EC point formats Length: 3
  29. Elliptic curves point formats (3)
  30. EC point format: uncompressed (0)
  31. EC point format: ansiX962_compressed_prime (1)
  32. EC point format: ansiX962_compressed_char2 (2)
  33. Extension: session_ticket (len=0)
  34. Type: session_ticket (35)
  35. Length: 0
  36. Data (0 bytes)
  37. Extension: extended_master_secret (len=0)
  38. Type: extended_master_secret (23)
  39. Length: 0
  40. [JA3S Fullstring: 771,49199,65281-0-11-35-23]
  41. [JA3S: 098e26e2609212ac1bfac552fbe04127]
ServerHello的消息说明服务器和客户端使用TLS v1.2处理本次会话,TLS记录层共占69字节,SeverHello消息占65字节。
Random是服务器生成的随机数。
Session ID为空,服务器不适用Session ID作为会话恢复,而是支持SessionTicket。
协商的密码套件为TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256。
不启用压缩。
扩展长度为25字节,共处理客户端的5个扩展。

Certificate

服务器在发送完ServerHello之后马上发送了Certificate子消息,展开结构如下
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: Certificate
  3. Content Type: Handshake (22)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 2972
  6. Handshake Protocol: Certificate
  7. Handshake Type: Certificate (11)
  8. Length: 2968
  9. Certificates Length: 2965
  10. Certificates (2965 bytes)
  11. Certificate Length: 1668
  12. Certificate: 30820680308204e8a003020102021100f0bb16defd41d3ba7cf205dccec0ae01300d0609… (id-at-commonName=selflias.com.cn)
  13. signedCertificate
  14. version: v3 (2)
  15. serialNumber: 0x00f0bb16defd41d3ba7cf205dccec0ae01
  16. signature (sha384WithRSAEncryption)
  17. issuer: rdnSequence (0)
  18. rdnSequence: 3 items (id-at-commonName=TrustAsia RSA DV TLS CA G2,id-at-organizationName=TrustAsia Technologies, Inc.,id-at-countryName=CN)
  19. validity
  20. subject: rdnSequence (0)
  21. rdnSequence: 1 item (id-at-commonName=selflias.com.cn)
  22. subjectPublicKeyInfo
  23. extensions: 9 items
  24. algorithmIdentifier (sha384WithRSAEncryption)
  25. Algorithm Id: 1.2.840.113549.1.1.12 (sha384WithRSAEncryption)
  26. Padding: 0
  27. encrypted: 3bebea7d478c774f6b636cc081dafd75507d70bc2f007be5fa75a4ee841265b8bf64e486…
  28. Certificate Length: 1291
  29. Certificate: 30820507308203efa003020102021100b20ced552e31a0bf343a7528743be9ab300d0609… (id-at-commonName=TrustAsia RSA DV TLS CA G2,id-at-organizationName=TrustAsia Technologies, Inc.,id-at-countryName=CN)
  30. signedCertificate
  31. version: v3 (2)
  32. serialNumber: 0x00b20ced552e31a0bf343a7528743be9ab
  33. signature (sha256WithRSAEncryption)
  34. issuer: rdnSequence (0)
  35. rdnSequence: 5 items (id-at-commonName=AAA Certificate Services,id-at-organizationName=Comodo CA Limited,id-at-localityName=Salford,id-at-stateOrProvinceName=Greater Manchester,id-at-countryName=GB)
  36. validity
  37. subject: rdnSequence (0)
  38. rdnSequence: 3 items (id-at-commonName=TrustAsia RSA DV TLS CA G2,id-at-organizationName=TrustAsia Technologies, Inc.,id-at-countryName=CN)
  39. subjectPublicKeyInfo
  40. extensions: 8 items
  41. algorithmIdentifier (sha256WithRSAEncryption)
  42. Algorithm Id: 1.2.840.113549.1.1.11 (sha256WithRSAEncryption)
  43. Padding: 0
  44. encrypted: 1cc5289b97312237b6222154ee6382b01af617a098794e5cc9f43f01ea7d9005d8503b96…
可以看出服务器发送了两张证书,一张是服务器自己的证书,一张是中间证书。
服务器自己的证书由TrustAsia RSA DV TLS CA G2颁发,中间证书由AAA Certificate Services颁发。两张证书都使用sha256WithRSA算法签名。

服务器证书的详细结构

  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: Certificate
  3. Content Type: Handshake (22)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 2972
  6. Handshake Protocol: Certificate
  7. Handshake Type: Certificate (11)
  8. Length: 2968
  9. Certificates Length: 2965
  10. Certificates (2965 bytes)
  11. Certificate Length: 1668
  12. Certificate: 30820680308204e8a003020102021100f0bb16defd41d3ba7cf205dccec0ae01300d0609… (id-at-commonName=selflias.com.cn)
  13. signedCertificate
  14. version: v3 (2)
  15. serialNumber: 0x00f0bb16defd41d3ba7cf205dccec0ae01
  16. signature (sha384WithRSAEncryption)
  17. Algorithm Id: 1.2.840.113549.1.1.12 (sha384WithRSAEncryption)
  18. issuer: rdnSequence (0)
  19. rdnSequence: 3 items (id-at-commonName=TrustAsia RSA DV TLS CA G2,id-at-organizationName=TrustAsia Technologies, Inc.,id-at-countryName=CN)
  20. RDNSequence item: 1 item (id-at-countryName=CN)
  21. RelativeDistinguishedName item (id-at-countryName=CN)
  22. Object Id: 2.5.4.6 (id-at-countryName)
  23. CountryName: CN
  24. RDNSequence item: 1 item (id-at-organizationName=TrustAsia Technologies, Inc.)
  25. RelativeDistinguishedName item (id-at-organizationName=TrustAsia Technologies, Inc.)
  26. Object Id: 2.5.4.10 (id-at-organizationName)
  27. DirectoryString: printableString (1)
  28. printableString: TrustAsia Technologies, Inc.
  29. RDNSequence item: 1 item (id-at-commonName=TrustAsia RSA DV TLS CA G2)
  30. RelativeDistinguishedName item (id-at-commonName=TrustAsia RSA DV TLS CA G2)
  31. Object Id: 2.5.4.3 (id-at-commonName)
  32. DirectoryString: printableString (1)
  33. printableString: TrustAsia RSA DV TLS CA G2
  34. validity
  35. notBefore: utcTime (0)
  36. utcTime: 2022-10-19 00:00:00 (UTC)
  37. notAfter: utcTime (0)
  38. utcTime: 2023-10-19 23:59:59 (UTC)
  39. subject: rdnSequence (0)
  40. rdnSequence: 1 item (id-at-commonName=selflias.com.cn)
  41. RDNSequence item: 1 item (id-at-commonName=selflias.com.cn)
  42. RelativeDistinguishedName item (id-at-commonName=selflias.com.cn)
  43. Object Id: 2.5.4.3 (id-at-commonName)
  44. DirectoryString: printableString (1)
  45. printableString: selflias.com.cn
  46. subjectPublicKeyInfo
  47. algorithm (rsaEncryption)
  48. Algorithm Id: 1.2.840.113549.1.1.1 (rsaEncryption)
  49. subjectPublicKey: 3082010a0282010100d0ec9a5b3c26dddf33b4303cdb4dc05b8297f1e539cc4ee095b9dc…
  50. modulus: 0x00d0ec9a5b3c26dddf33b4303cdb4dc05b8297f1e539cc4ee095b9dc790a4ebfc132f0c2…
  51. publicExponent: 65537
  52. extensions: 9 items
  53. Extension (id-ce-authorityKeyIdentifier)
  54. Extension (id-ce-subjectKeyIdentifier)
  55. Extension (id-ce-keyUsage)
  56. Extension (id-ce-basicConstraints)
  57. Extension (id-ce-extKeyUsage)
  58. Extension (id-ce-certificatePolicies)
  59. Extension (id-pe-authorityInfoAccess)
  60. Extension (id-ce-subjectAltName)
  61. Extension (SignedCertificateTimestampList)
  62. algorithmIdentifier (sha384WithRSAEncryption)
  63. Algorithm Id: 1.2.840.113549.1.1.12 (sha384WithRSAEncryption)
  64. Padding: 0
  65. encrypted: 3bebea7d478c774f6b636cc081dafd75507d70bc2f007be5fa75a4ee841265b8bf64e486…
可以看出证书的版本是X.509 v3版本。
序列号是0x00f0bb16defd41d3ba7cf205dccec0ae01。
签名算法为sha384WithRSA。
颁发者是TrustAsia RSA DV TLS CA G2。
有效期是2022-10-19 00:00:00到2023-10-19 23:59:59
公钥值是3082010a0282010100d0ec9a5b3c26dddf33b4303cdb4dc05b8297f1e539cc4ee095b9dc…
包含了9个证书扩展。

服务器证书扩展的结构

  1. extensions: 9 items
  2. Extension (id-ce-authorityKeyIdentifier)
  3. Extension Id: 2.5.29.35 (id-ce-authorityKeyIdentifier)
  4. AuthorityKeyIdentifier
  5. keyIdentifier: 5f3a7c11107e0c677161dc8ba3b5000367f5571c
  6. Extension (id-ce-subjectKeyIdentifier)
  7. Extension Id: 2.5.29.14 (id-ce-subjectKeyIdentifier)
  8. SubjectKeyIdentifier: 116c594baff606c89c4c6f69b663ba08946c8a7b
  9. Extension (id-ce-keyUsage)
  10. Extension Id: 2.5.29.15 (id-ce-keyUsage)
  11. critical: True
  12. Padding: 5
  13. KeyUsage: a0
  14. 1... .... = digitalSignature: True
  15. .0.. .... = contentCommitment: False
  16. ..1. .... = keyEncipherment: True
  17. ...0 .... = dataEncipherment: False
  18. .... 0... = keyAgreement: False
  19. .... .0.. = keyCertSign: False
  20. .... ..0. = cRLSign: False
  21. .... ...0 = encipherOnly: False
  22. 0... .... = decipherOnly: False
  23. Extension (id-ce-basicConstraints)
  24. Extension Id: 2.5.29.19 (id-ce-basicConstraints)
  25. critical: True
  26. BasicConstraintsSyntax [0 length]
  27. Extension (id-ce-extKeyUsage)
  28. Extension Id: 2.5.29.37 (id-ce-extKeyUsage)
  29. KeyPurposeIDs: 2 items
  30. KeyPurposeId: 1.3.6.1.5.5.7.3.1 (id-kp-serverAuth)
  31. KeyPurposeId: 1.3.6.1.5.5.7.3.2 (id-kp-clientAuth)
  32. Extension (id-ce-certificatePolicies)
  33. Extension Id: 2.5.29.32 (id-ce-certificatePolicies)
  34. CertificatePoliciesSyntax: 2 items
  35. PolicyInformation
  36. policyIdentifier: 1.3.6.1.4.1.6449.1.2.2.49 (iso.3.6.1.4.1.6449.1.2.2.49)
  37. policyQualifiers: 1 item
  38. PolicyQualifierInfo
  39. Id: 1.3.6.1.5.5.7.2.1 (id-qt-cps)
  40. DirectoryString: https://sectigo.com/CPS
  41. PolicyInformation
  42. policyIdentifier: 2.23.140.1.2.1 (joint-iso-itu-t.23.140.1.2.1)
  43. Extension (id-pe-authorityInfoAccess)
  44. Extension Id: 1.3.6.1.5.5.7.1.1 (id-pe-authorityInfoAccess)
  45. AuthorityInfoAccessSyntax: 2 items
  46. AccessDescription
  47. accessMethod: 1.3.6.1.5.5.7.48.2 (id-ad-caIssuers)
  48. accessLocation: 6
  49. uniformResourceIdentifier: http://crt.trust-provider.cn/TrustAsiaRSADVTLSCAG2.crt
  50. AccessDescription
  51. accessMethod: 1.3.6.1.5.5.7.48.1 (id-ad-ocsp)
  52. accessLocation: 6
  53. uniformResourceIdentifier: http://ocsp.trust-provider.cn
  54. Extension (id-ce-subjectAltName)
  55. Extension Id: 2.5.29.17 (id-ce-subjectAltName)
  56. GeneralNames: 2 items
  57. GeneralName: dNSName (2)
  58. dNSName: selflias.com.cn
  59. GeneralName: dNSName (2)
  60. dNSName: www.selflias.com.cn
  61. Extension (SignedCertificateTimestampList)
  62. Extension Id: 1.3.6.1.4.1.11129.2.4.2 (SignedCertificateTimestampList)
  63. Serialized SCT List Length: 362
  64. Signed Certificate Timestamp (Google 'Xenon2023' log)
  65. Serialized SCT Length: 119
  66. SCT Version: 0
  67. Log ID: adf7befa7cff10c88b9d3d9c1e3e186ab467295dcfb10c24ca858634ebdc828a
  68. Timestamp: Oct 19, 2022 06:37:15.021000000 UTC
  69. Extensions length: 0
  70. Signature Algorithm: ecdsa_secp256r1_sha256 (0x0403)
  71. Signature Hash Algorithm Hash: SHA256 (4)
  72. Signature Hash Algorithm Signature: ECDSA (3)
  73. Signature Length: 72
  74. Signature: 3046022100d3ca45fe7bf14bb759de71a2b35f708b065dd968f8b30e78865721f8575974…
  75. Signed Certificate Timestamp (Cloudflare 'Nimbus2023' Log)
  76. Serialized SCT Length: 119
  77. SCT Version: 0
  78. Log ID: 7a328c54d8b72db620ea38e0521ee98416703213854d3bd22bc13a57a352eb52
  79. Timestamp: Oct 19, 2022 06:37:14.965000000 UTC
  80. Extensions length: 0
  81. Signature Algorithm: ecdsa_secp256r1_sha256 (0x0403)
  82. Signature Hash Algorithm Hash: SHA256 (4)
  83. Signature Hash Algorithm Signature: ECDSA (3)
  84. Signature Length: 72
  85. Signature: 30460221008b154b640290a4d0c7b8fd87254d0f2d0c342e55e918ffce866d92a546499d…
  86. Signed Certificate Timestamp (Google 'Argon2023' log)
  87. Serialized SCT Length: 118
  88. SCT Version: 0
  89. Log ID: e83ed0da3ef5063532e75728bc896bc903d3cbd1116beceb69e1777d6d06bd6e
  90. Timestamp: Oct 19, 2022 06:37:14.919000000 UTC
  91. Extensions length: 0
  92. Signature Algorithm: ecdsa_secp256r1_sha256 (0x0403)
  93. Signature Hash Algorithm Hash: SHA256 (4)
  94. Signature Hash Algorithm Signature: ECDSA (3)
  95. Signature Length: 71
  96. Signature: 304502204b602d371ffd3a0a247afb3c64c8f262b7c282c333047fa6a4f203758917d1fe…
其中重要的扩展,即critical=True的有:
id-ce-keyUsage,表示该证书可以用于密钥交换和数字签名。
id-ce-basicConstraints,表示该证书是一张普通证书,不能签发其他证书。

Server Key Exchange

密钥协商算法是TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,证书中没有包含ECDH参数等信息,所以服务器发送ServerKeyExchange消息。
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: Server Key Exchange
  3. Content Type: Handshake (22)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 300
  6. Handshake Protocol: Server Key Exchange
  7. Handshake Type: Server Key Exchange (12)
  8. Length: 296
  9. EC Diffie-Hellman Server Params
  10. Curve Type: named_curve (0x03)
  11. Named Curve: x25519 (0x001d)
  12. Pubkey Length: 32
  13. Pubkey: 37cb1755840758875116cb24435a7edb61228ce7d353b56ddaae691168c13176
  14. Signature Algorithm: rsa_pss_rsae_sha256 (0x0804)
  15. Signature Hash Algorithm Hash: Unknown (8)
  16. Signature Hash Algorithm Signature: SM2 (4)
  17. Signature Length: 256
  18. Signature: 37936b9ead1368308a601245cf01e35274774210b59fe3343f48f4e202c54a7df8ee1de4…
可以看出采用的是命名曲线x25519,公钥是37cb1755840758875116cb24435a7edb61228ce7d353b56ddaae691168c13176,签名算法是rsa_pss_rsae_sha256。

Server Hello Done

Server Hello Done是一条空消息,通知客户端服务器已准备好预备主密钥协商。
  1. TLSv1.2 Record Layer: Handshake Protocol: Server Hello Done
  2. Content Type: Handshake (22)
  3. Version: TLS 1.2 (0x0303)
  4. Length: 4
  5. Handshake Protocol: Server Hello Done
  6. Handshake Type: Server Hello Done (14)
  7. Length: 0

Client Key Exchange

客户端给服务器发送自己的ECDH公钥
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: Client Key Exchange
  3. Content Type: Handshake (22)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 37
  6. Handshake Protocol: Client Key Exchange
  7. Handshake Type: Client Key Exchange (16)
  8. Length: 33
  9. EC Diffie-Hellman Client Params
  10. Pubkey Length: 32
  11. Pubkey: 06b90ea70ed26d8c05756acb7b0f2d6cbd342f4dbad35cb1c1db8d219dc37d6a

客户端Change Cipher Spec

客户端发送该消息告诉服务器端,客户端可以使用TLS记录层协议进行密码学保护了,下一条消息就是加密的消息。
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Change Cipher Spec Protocol: Change Cipher Spec
  3. Content Type: Change Cipher Spec (20)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 1
  6. Change Cipher Spec Message

客户端Encrypted Handshake Message

加密过的Finished子消息。
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: Encrypted Handshake Message
  3. Content Type: Handshake (22)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 40
  6. Handshake Protocol: Encrypted Handshake Message

New Session Ticket

表示服务器支持Session Ticket会话恢复,发送给客户端Ticket值aa805373de67fa62d924e7725bdb987e83d8e432eabdb175042e960d1b99562bef99a234…。
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Handshake Protocol: New Session Ticket
  3. Content Type: Handshake (22)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 218
  6. Handshake Protocol: New Session Ticket
  7. Handshake Type: New Session Ticket (4)
  8. Length: 214
  9. TLS Session Ticket
  10. Session Ticket Lifetime Hint: 300 seconds (5 minutes)
  11. Session Ticket Length: 208
  12. Session Ticket: aa805373de67fa62d924e7725bdb987e83d8e432eabdb175042e960d1b99562bef99a234…

服务器的ChangeCipherSpec和EncryptedHandshakeMessage

和客户端的同类子消息类似。
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Change Cipher Spec Protocol: Change Cipher Spec
  3. Content Type: Change Cipher Spec (20)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 1
  6. Change Cipher Spec Message
  7. TLSv1.2 Record Layer: Handshake Protocol: Encrypted Handshake Message
  8. Content Type: Handshake (22)
  9. Version: TLS 1.2 (0x0303)
  10. Length: 40
  11. Handshake Protocol: Encrypted Handshake Message

Application Data

这个消息就是加密后的上层协议的内容了,客户端与服务器已经完成握手,展开如下
  1. Transport Layer Security
  2. TLSv1.2 Record Layer: Application Data Protocol: Hypertext Transfer Protocol
  3. Content Type: Application Data (23)
  4. Version: TLS 1.2 (0x0303)
  5. Length: 328
  6. Encrypted Application Data: 000000000000000129b0d62974ec77cb57c0a3eca6987622a8e9fd57bcfb5ca8a7e3fff7…
  7. [Application Data Protocol: Hypertext Transfer Protocol]
可以看到http的整个请求都被加密了。

总结

TLS握手对应多种情况,这里展示的是基于ECDHE密码套件的握手场景。其他还有基于会话恢复的简短握手的场景,有不同密码套件发送不一样的握手内容的场景,实际在分析时需要慢慢总结。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/842275
推荐阅读
相关标签
  

闽ICP备14008679号