简体   繁体   English

TLS 1.3 客户端问候结构。 在 Linux 用户空间支持的 C 语言中。 谁能告诉我什么结构应该代表客户你好

[英]Tls 1.3 client hello structure. in C supported on Linux Userspace. Can anyone please tell what struct should look like to represent client hello

I like to understand tls by code.我喜欢通过代码来理解 tls。 tls 1.3 and cipher suits so I started and at first I found in tls 1.3 handshake is client initiate the handshake with the server with hello message. tls 1.3 和密码套装,所以我开始了,起初我在 tls 1.3 中发现握手是客户端使用 hello 消息启动与服务器的握手。 On the documentation on this page https://datatracker.ietf.org/doc/html/rfc8446#section-4.1.2在此页面上的文档https://datatracker.ietf.org/doc/html/rfc8446#section-4.1.2

It says this它说这个

Structure of this message:此消息的结构:

  uint16 ProtocolVersion;
  opaque Random[32];

  uint8 CipherSuite[2];    /* Cryptographic suite selector */

  struct {
      ProtocolVersion legacy_version = 0x0303;    /* TLS v1.2 */
      Random random;
      opaque legacy_session_id<0..32>;
      CipherSuite cipher_suites<2..2^16-2>;
      opaque legacy_compression_methods<1..2^8-1>;
      Extension extensions<8..2^16-1>;
  } ClientHello;

And so I never seen in C's types called opaque is it supported by gcc or do I need to include any glibc header .h file or what do I need?所以我从来没有在 C 的类型中看到opaque是 gcc 支持的还是我需要包含任何 glibc 头 .h 文件或者我需要什么?

So I believe there should be another structure struct CipherSuite how to represent this struct what fileds this struct contains.所以我相信应该有另一个结构struct CipherSuite如何表示这个结构这个结构包含什么文件。 do u know this?你知道吗? Searching about how to represent this on google I found some library I could not understand what it is.在谷歌上搜索如何表示这个我发现了一些我不明白它是什么的库。 wasnt in C. and other search result II could not understand, but what I understood is wasnt in C.和其他搜索结果II无法理解,但我理解的是

Put simply, a cipher suite is a collection of different algorithms, protocols, and all the other good stuff that encrypts and decrypts data between two communicating parties 

so struct CipherSuite contains algorithon(s) means multiple algorithms so array of some algorithms whats the size of this two D array means leaght and breath of array so所以struct CipherSuite包含算法意味着多个算法所以一些算法的数组这两个 D 数组的大小意味着数组的长度和呼吸所以

struct CipherSuite { char some_algorithms[unknow][unknow] struct CipherSuite { char some_algorithms[unknow][unknow]

so how many algorithms and what is the size of each of these algorithms in bytes or are there any other struct included to also represent CipherSuite?那么有多少算法,每个算法的字节大小是多少,或者是否包含任何其他结构也代表 CipherSuite? can anyone please tell me this?谁能告诉我这个? thanks谢谢

and what is Extension in struct Clienthello whats this Extension extensions<8..2^16-1>;什么是struct Clienthello中的 Extensions 这个Extension extensions<8..2^16-1>; ? ?

This structure is defined in RFC 8446 and it is pseudo code, it does not map as is directly to any kind of programming language, so it is not C.这个结构在 RFC 8446 中定义,它是伪代码,它不直接映射到任何类型的编程语言,所以它不是 C。

See https://datatracker.ietf.org/doc/html/rfc8446#section-3 that explains the model used and the vocabulary.请参阅https://datatracker.ietf.org/doc/html/rfc8446#section-3 ,其中解释了使用的模型和词汇。

And so I never seen in C's types called opaque所以我从来没有在 C 的类型中看到过不透明的

opaque here means that for the TLS "engine", the content does not matter, it can be considered gibberish (random).这里的opaque表示对于 TLS“引擎”,内容无关紧要,可以认为是胡言乱语(随机)。 It certainly makes sense for other parts, but not for TLS.这对其他部分当然有意义,但对 TLS 则不然。 Take for example this sentence in the specification:以规范中的这句话为例:

Application Data messages contain data that is opaque to TLS.应用程序数据消息包含对 TLS 不透明的数据。

So opaque means "unstructured" at this level.所以opaque在这个级别意味着“非结构化”。

So I believe there should be another structure struct CipherSuite how to represent this struct what fileds this struct contains.所以我相信应该有另一个结构 struct CipherSuite 如何表示这个结构这个结构包含什么文件。 do u know this?你知道吗?

cipherSuite appears like that: cipherSuite看起来像这样:

      uint8 CipherSuite[2];    /* Cryptographic suite selector */

      struct {
          ProtocolVersion legacy_version = 0x0303;    /* TLS v1.2 */
          Random random;
          opaque legacy_session_id<0..32>;
          CipherSuite cipher_suites<2..2^16-2>;
          opaque legacy_compression_methods<1..2^8-1>;
          Extension extensions<8..2^16-1>;
      } ClientHello;

in ClientHello message defined in §4.1.2在 §4.1.2 中定义的ClientHello消息中

uint8 CipherSuite[2] means that a ciphersuite is 2 items, each one being an unsigned byte (uint8). uint8 CipherSuite[2]表示一个密码套件有 2 个项目,每个项目都是一个无符号字节 (uint8)。

You can see values at "B.4. Cipher Suites" which is:您可以在“B.4. Cipher Suites”中看到值,即:

              +------------------------------+-------------+
              | Description                  | Value       |
              +------------------------------+-------------+
              | TLS_AES_128_GCM_SHA256       | {0x13,0x01} |
              |                              |             |
              | TLS_AES_256_GCM_SHA384       | {0x13,0x02} |
              |                              |             |
              | TLS_CHACHA20_POLY1305_SHA256 | {0x13,0x03} |
              |                              |             |
              | TLS_AES_128_CCM_SHA256       | {0x13,0x04} |
              |                              |             |
              | TLS_AES_128_CCM_8_SHA256     | {0x13,0x05} |
              +------------------------------+-------------+

So each of the 5 defined cipher suite in TLS 1.3 is mapped to 2 bytes, first one always being with value 0x13 for all 5 cases.因此,TLS 1.3 中定义的 5 个密码套件中的每一个都映射到 2 个字节,对于所有 5 种情况,第一个始终具有值0x13

so how many algorithms and what is the size of each of these algorithms in bytes or are there any other struct included to also represent CipherSuite?那么有多少算法,每个算法的字节大小是多少,或者是否包含任何其他结构也代表 CipherSuite?

If you really want to implement TLS 1.3 at a low level you really need to read RFC 8446 fully.如果您真的想在低级别实现 TLS 1.3,您确实需要完整阅读 RFC 8446。 Multiple times.多次。 From top to bottom and bottom to top.从上到下,从下到上。 There are even sections specifically with advices on implementation.甚至还有一些专门提供实施建议的部分。 BUT do this only if you want to learn, otherwise any language today should have already a proper library handling all the low level details of TLS 1.3 and you should use that library in your code, not reinvent it.但是只有在您想学习时才这样做,否则今天的任何语言都应该已经有一个适当的库来处理 TLS 1.3 的所有低级细节,并且您应该在代码中使用该库,而不是重新发明它。

and what is Extension in struct Clienthello whats this Extension extensions<8..2^16-1>;?什么是 struct Clienthello 中的 Extension,这个 Extension extensions<8..2^16-1>; 是什么?

It is explained later on in the text:稍后在正文中解释:

extensions: Clients request extended functionality from servers by sending data in the extensions field.扩展:客户端通过在扩展字段中发送数据向服务器请求扩展功能。 The actual "Extension" format is defined in Section 4.2.实际的“扩展”格式在第 4.2 节中定义。 In TLS 1.3, the use of certain extensions is mandatory, as functionality has moved into extensions to preserve ClientHello compatibility with previous versions of TLS.在 TLS 1.3 中,某些扩展的使用是强制性的,因为功能已转移到扩展中以保持 ClientHello 与先前版本的 TLS 的兼容性。 Servers MUST ignore unrecognized extensions.服务器必须忽略无法识别的扩展。

With the syntax explained in Section 3, Extension extensions<8..2^16-1> is a variable length vector which means the "extensions" field is a content whose size is from 8 to 2^16-1 bytes, and the content is of type Extension defined elsewhere in the document in section 4.2 as such:使用第 3 节中解释的语法, Extension extensions<8..2^16-1>是一个可变长度向量,这意味着“扩展”字段是大小为82^16-1字节的内容,并且内容是第 4.2 节文档中其他地方定义的Extension类型,如下所示:

    struct {
        ExtensionType extension_type;
        opaque extension_data<0..2^16-1>;
    } Extension;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM