Speed

What a Failure Looks Like

A failed handshake can end in a readable alert, an encrypted alert, silence, or no failure at all. Which one you see depends on when the change happens, and a real peer shows more than this pair.

The question

The lessons so far ended with a readable 7-byte alert. Is that how every failure looks? And how does a program tell the four things apart that can happen when one end gives up, or does not notice?

Both ends are test endpoints in this tab's memory, made with ssl.tls_pair. You change one bit of one flight, as in the earlier lessons, and read what the loop sees. Nothing attacks anything, and the certificates and the key are public test material. This is the honesty lesson of the book: it says what these pictures do not show.

Work it by hand

There are four outcomes. A plaintext alert is a 7-byte flight that starts with 21: this build sends one in the clear until it has started to protect its own records, which includes the client's refusals in the earlier lessons although the client already holds handshake keys. An encrypted alert is sent once the sender protects its records: RFC 9846 section 6 says alerts are "encrypted as specified by the current connection state", so the record starts with 23 and only an end with the keys can read the number.

Silence is nobody answering. No failure is a handshake that finishes although a bit changed, because the end that would notice has not read it.

The demo makes silence. The first flight has 315 bytes; its handshake length is 306 = 00 01 32, bytes 6 to 8. Flip bit 0 of byte 8 and the length reads 307, one more than there are bytes: the server waits for a byte that never comes, and nobody sends anything.

Run it

Line 6 asks for bit 0 of byte offset of the next flight to be flipped. The loop of lines 8 to 15 takes turns and records each flight that carries bytes with its direction and size (lines 10 to 14). Lines 16 to 19 return the messages, the number of turns, the size of the last flight and error(). Line 20 returns the number of flights that carried bytes.

A message diagram between client and server with one arrow: the client sends flight 1 of 315 bytes, and nothing comes back.

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 flights = 0; let size = 0;
while (!pair.done() && pair.error() == "" && turns < 10) {
  let flight = pair.step(); turns = turns + 1;
  if (str_len(flight) > 0) {
    flights = flights + 1; size = str_len(flight);
    let way = "1>0|"; if (pair.from() == "client") { way = "0>1|"; }
    messages.add(way + "flight " + str(flights) + "|" + str(size) + " bytes");
  }
}
lmcode_return_put("messages", messages);
lmcode_return_put("turns", turns);
lmcode_return_put("last_flight_bytes", size);
lmcode_return_put("error", pair.error());
let answer = flights;
{
  "answer": 1,
  "messages": [
    "0>1|flight 1|315 bytes"
  ],
  "turns": 2,
  "last_flight_bytes": 315,
  "error": "handshake stalled: neither side has anything to send"
}

With offset 8 the answer is 1: one flight of 315 bytes and then nothing. The loop took 2 turns, the second returned 0 bytes, and the pair said handshake stalled: neither side has anything to send. That sentence is the pair's own, not OpenSSL's. 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 8x gives 2 flights where 8 gives 1. A negative number stops line 6 with "Line 6: TlsPair.tamper: negative tamper offset". An offset of 315 or more stops line 9 with "Line 9: TlsPair.step: tamper offset 315 is beyond the 315 bytes sent".

Try 9, which gives 2 flights and a 7-byte alert from the server, and 314, the last byte of the flight, which gives 3 flights. host can be changed 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 and should classify what happened as plaintext alert, encrypted alert, silence or no failure. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on six others.

The flight number 3 and the byte offset 20 of the case shown.

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 empty = false;
while (!pair.done() && pair.error() == "" && turns < 10) {
  if (turns + 1 == flight) { pair.tamper(offset); }
  let bytes = pair.step(); turns = turns + 1;
  empty = str_len(bytes) == 0;
  if (!empty) { last = str_hex_encode(bytes); }
}
let kind = hex_u8(last, 0); let answer = "silence";
if (pair.error() != "") { answer = "plaintext alert"; }
if (pair.done()) { answer = "no failure"; }
lmcode_return_put("turns", turns);
{
  "answer": "plaintext alert",
  "turns": 4
}

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 no failure if the pair is done. Otherwise return plaintext alert if the last flight with bytes is exactly 7 bytes long and starts with 21, encrypted alert if it starts with 23, and silence in every other case. Check runs each candidate on the data shown and on six others.

Read the result carefully

These are the messages of one OpenSSL build talking to itself, started fresh, in one tab. A real server may send another alert, a generic one or nothing, may close the connection or keep it open until a timeout, and middleboxes add failures of their own; that is stated here, not run. This page has no network, so it has no timeout, no reset and no retry: the stall is the pair's own sentence, and between real machines it would be a timeout.

Every failure here was made by you on your own two endpoints with test material, and nothing in this book is a way to make a correct client accept what it should refuse. An alert tells you what the other end chose to say, not always what went wrong. The certificates are valid from 2026-01-01 to 2036-01-01, so the results hold only between those years.

Recap

  • A readable alert is 7 bytes, starting 15 03 03 00 02; this build sends one until it protects its own records.
  • Once the sender protects its records an alert is encrypted (RFC 9846 section 6); its number cannot be read from outside.
  • A change can also end in silence, or in no failure at all, when the end that would notice has not read it.
  • A real peer shows more: other alerts, closed connections, timeouts.