Speed

ClientHello, Fixed Fields

A hello message starts with fixed fields, but the session id length moves everything after byte 43; the recorded ServerHello puts its suite at byte 76 and the extensions length at byte 79.

The question

A ServerHello is the first thing the server says, and it is short. Where do its fields sit, byte by byte, and which of those places can move when the message changes?

The recording is one loopback connection between two test programs, made on 2026-11-20 and kept as test material; the ServerHello here is its second record, 127 bytes. The ClientHello is longer, and the exercise reads it. Both messages share the same first fields: a legacy version, a 32-byte random and a session id (RFC 9846, 4.2.2 for the ClientHello and 4.2.3 for the ServerHello).

Work it by hand

Count from the first byte of the record. The record header takes bytes 0 to 4, the handshake header (type 02 and a 3-byte length) bytes 5 to 8. So the field legacy_version starts at byte 9 and takes two bytes. The 32-byte random follows at byte 11 and ends at byte 42, which puts the session id length byte at byte 43.

In this ServerHello the length byte is 0x20, 32. The session id echo then takes bytes 44 to 75, the chosen cipher suite sits at 76 and 77, the compression method at 78 and the 2-byte extensions length at 79 and 80. A different session id length would move every field after byte 43 by the difference.

Run it

The program takes the record as hex in record. Line 4 reads the session id length at byte 43; line 6 turns it into the offset of the cipher suite, so that every later offset depends on it. Line 9 reads the extensions length, and each rows.add line (the first is line 2) builds one row of the table. Line 11 returns the rows.

A table of six rows: legacy_version at byte 9 with 0303, random at byte 11, session id length at byte 43 with 32, cipher suite at byte 76 with 1301, compression at byte 78 with 00 and extensions length at byte 79 with 46.
Watch the steps (recorded video)

Public test material, generated for this lesson. Never use it for anything real.

let rows = str_list();
rows.add("legacy_version|9|" + hex_slice(record, 9, 2));
rows.add("random|11|" + hex_slice(record, 11, 4) + " ... (32 bytes)");
let sid = hex_u8(record, 43);
rows.add("session id length|43|" + str(sid));
let at = 44 + sid;
rows.add("cipher suite|" + str(at) + "|" + hex_slice(record, at, 2));
rows.add("compression|" + str(at + 2) + "|" + hex_slice(record, at + 2, 1));
let ext = hex_u16(record, at + 3);
rows.add("extensions length|" + str(at + 3) + "|" + str(ext));
let answer = rows;
{
  "answer": [
    "legacy_version|9|0303",
    "random|11|234b2a9e ... (32 bytes)",
    "session id length|43|32",
    "cipher suite|76|1301",
    "compression|78|00",
    "extensions length|79|46"
  ]
}

You can change the record freely if it is a ServerHello long enough for its own session id length: the table reads up to byte 48 plus that length, so 81 bytes are enough for 32 and 49 bytes for an empty session id. A session id of another length moves the offsets in the table (measured with a constructed record whose session id is empty: the table then shows the suite at byte 44).

A record of 43 bytes stops the run with "byte 43 is past the end of the data" (measured), and a record of 44 bytes whose session id length says 32 stops it with "bytes 76 to 77 are past the end of the data" (measured).

Your turn

A parser reads a ClientHello record that arrives in one piece. After the session id come the cipher suites (a 2-byte length in bytes, then two bytes for each suite), the compression methods (a 1-byte length, then that many bytes) and the extensions (a 2-byte length).

The program below is meant to return a list of four integers: the length of the session id, the number of cipher suites, the offset of the 2-byte extensions length field counted from the first byte of the record, and the value of that field. The number of suites is the suite list length divided by two, rounded down.

Decide whether it does, and find the candidates that do. Check runs each candidate on the record shown and on four others. Records other than the recording's are built by hand; they are test material and not captures.

The first 16 bytes of a ClientHello record, shown in hex with the total number of bytes of the record.

Public test material, generated for this lesson. Never use it for anything real.

let sid = hex_u8(record, 43);
let at = 44 + sid;
let suite_bytes = hex_u16(record, at);
let comp_at = at + 2 + suite_bytes;
let ext_at = comp_at + 1 + hex_u8(record, comp_at);
let answer = int_list();
answer.add(sid); answer.add(suite_bytes);
answer.add(ext_at); answer.add(hex_u16(record, ext_at));
{
  "answer": [
    32,
    56,
    136,
    173
  ]
}

Return a list of four integers for a ClientHello record: the length of its session id, the number of cipher suites (the suite list length divided by two, rounded down), the byte offset of the 2-byte extensions length field counted from the first byte of the record, and the value of that field.

Read the result carefully

The offsets here are for this record and for any record laid out the same way; a parser must read lengths and cannot assume them. The session id is the field to watch: the ClientHello of this recording carries 32 bytes, an echo kept for compatibility with middleboxes (RFC 9846, 4.2.2), and the ServerHello repeats it.

The page reads one recorded ClientHello and some constructed ones. It does not show the extensions beyond their total length, it does not decrypt anything, and it shows nothing about any real client or server. A hand-built record is not a capture of a real connection.

Recap

  • A hello starts with a record header (5 bytes) and a handshake header (4 bytes), then legacy_version (2 bytes) and a 32-byte random.
  • The byte after the random is the session id length, so everything after it depends on that length.
  • A ClientHello continues with its cipher suites, its compression methods and the extensions with a 2-byte length.
  • The recorded hellos carry a 32-byte session id.