A Flipped Bit in the Handshake
One bit of one flight, changed on its way between two test endpoints, makes one end give up. Which end, and with which alert, depends on the field the bit sits in.
The question
A handshake is a few flights of bytes, and every byte has a job. What happens if one bit of one flight changes on its way to the other end, who notices, and what does it say?
Both ends are test endpoints in this tab's memory, made with ssl.tls_pair. Nothing attacks anything: you ask the pair to change bit 0 of one byte of the next flight with pair.tamper, and you read how the checks of the receiving end respond. The certificates and the key are public test material.
Work it by hand
The first flight is the ClientHello, 315 bytes in this lesson's pair. It starts with a record header of 5 bytes: the type 16 (handshake), a version, and the length, which is 315 - 5 = 310. Then comes the handshake header of 4 bytes: the type 01 and a length of 3 bytes, 306. Bytes 9 and 10 are the legacy_version field, 03 03.
Flip bit 0 of byte 9 and the field reads 02 03. RFC 9846 section 4.2.2 says that a server which receives a legacy_version that is not 0x0303 "MUST abort the handshake with a "protocol_version" alert". That alert is number 70, hex 46, so the server should answer with a 7-byte alert, and the handshake stops after two flights.
Run it
Line 6 asks for bit 0 of byte offset of the next transfer to be flipped, and the loop of lines 8 to 16 lets the ends take turns. Each flight that carries bytes adds a message with its direction and size (lines 10 to 14). Lines 17 and 18 return the last flight as hex if it is a 7-byte alert, and no plaintext alert otherwise. Lines 19 and 20 return the messages and what error() says.

Watch the steps (recorded video)
Public test material, generated for this lesson. Never use it for anything real.
let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem)); server.groups("X25519");
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.groups("X25519");
let pair = ssl.tls_pair(client, server, host);
pair.tamper(str_to_int(offset));
let messages = str_list(); let turns = 0; let last = "";
while (!pair.done() && pair.error() == "" && turns < 10) {
let flight = pair.step(); turns = turns + 1;
if (str_len(flight) > 0) {
last = str_hex_encode(flight);
let way = "1>0|"; if (pair.from() == "client") { way = "0>1|"; }
let size = str(str_len(flight)) + " bytes";
messages.add(way + "flight " + str(turns) + "|" + size);
}
}
let answer = "no plaintext alert";
if (hex_len(last) == 7 && hex_u8(last, 0) == 21) { answer = last; }
lmcode_return_put("messages", messages);
lmcode_return_put("error", pair.error());
{
"answer": "15020300020246",
"messages": [
"0>1|flight 1|315 bytes",
"1>0|flight 2|7 bytes"
],
"error": "server handshake: error:0A000124:SSL routines::bad legacy version"
}With offset 9 the answer is 15020300020246: the flights are 315 bytes from the client and 7 from the server, and the alert is 70. What this OpenSSL build says: server handshake: error:0A000124:SSL routines::bad legacy version. The alert record carries 02 03 where the others carry 03 03. These come from this run.
You can change offset, which is read as text: text that is not a whole number is read as 0, and a negative number stops line 6 with "Line 6: TlsPair.tamper: negative tamper offset". The first flight has 315 bytes, so an offset of 315 or more stops line 9 with "Line 9: TlsPair.step: tamper offset 315 is beyond the 315 bytes sent" (the number is the one you typed).
Other offsets give other alerts, sent by the client or by the server; try some. Some offsets give no alert at all.
You can also change host as in the first lesson: a name such as x stops line 5 with "Line 5: Ssl.tls_pair: set host to verify".
Your turn
The program below calls pair.tamper(offset) just before the flight-th step of the pair, and should return who gave up and the number of the plaintext alert in the last flight, as one text such as client 20 or server -1. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on six others.

Public test material, generated for this lesson. Never use it for anything real.
let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem)); server.groups("X25519");
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.groups("X25519");
let pair = ssl.tls_pair(client, server, "www.example.test");
let turns = 0; let last = ""; let sender = "";
while (!pair.done() && pair.error() == "" && turns < 10) {
if (turns + 1 == flight) { pair.tamper(offset); }
let bytes = pair.step(); turns = turns + 1;
if (turns == flight) { sender = pair.from(); }
if (str_len(bytes) > 0) { last = str_hex_encode(bytes); }
}
let code = 0 - 1;
if (hex_len(last) == 7 && hex_u8(last, 0) == 21) { code = hex_u8(last, 5); }
let answer = str_split(pair.error(), " ").at(0) + " " + str(code);
lmcode_return_put("turns", turns);
{
"answer": "client 2",
"turns": 3
}A client asks for www.example.test and trusts root_pem; the server holds leaf_pem, int_pem and leaf_key; both ends use the group X25519. Both ends are test endpoints in this tab's memory. Take turns while the pair is not done and has no error, at most ten times, and call pair.tamper(offset) just before the step numbered flight (counting steps from 1). Return a text of two words: the end that gave up, which is the first word of error(), then the number of the plaintext alert in the last flight with bytes (a flight of exactly 7 bytes starting with 21), or -1 if there is none. Check runs each candidate on the data shown and on six others.
Read the result carefully
Nobody attacked anything: one bit changed between two test endpoints, and the checks that caught it were the receiver's own, such as a field compared with what was sent, a version field and the tag of a protected record, which authenticated-encryption explains. The bytes of a ClientHello are listed in tls-13-handshake-trace.
The alert numbers are the ones this build sends, and a real server may send another, a generic one, or nothing. Only a plaintext alert can be read: once the sender protects its records the answer is encrypted, and its bytes differ on every run. The texts are what this OpenSSL build says. The certificates are valid from 2026-01-01 to 2036-01-01 and the results hold only between those years. They are test material.
Step through the live handshake to compare an undamaged exchange.
Recap
pair.tamper(n)flips bit 0 of byte n of the next flight on its way to the other end.- Where the bit sits decides who gives up and with which alert; a changed
legacy_versionis answered with alert 70,protocol_version(RFC 9846 section 4.2.2). - A plaintext alert is 7 bytes: 15 03 03 00 02, a level and a description.
- Only plaintext alerts are read here; an encrypted answer differs on every run.