My SSH probe was reporting algorithm names that do not exist. The last entry in a server's list came back as …@openqu, cut off mid-word. The server was my own test box running an Open Quantum Safe build of OpenSSH, which offers 71 key exchange algorithms. My tool was reading that list from ssh -vv, and ssh -vv had quietly stopped printing it.

The cause is a fixed 1,024-byte buffer in OpenSSH's logging code. It truncates any log line longer than that, with no marker that anything is missing. This post shows where it happens in the source, who it affects, and how to read the server's list directly from the wire in about 20 lines of Python.

This is part 2 of a series on building pqc-probe. Part 1: Which post-quantum key exchanges does a server actually support?

Where the server's list shows up

Before any encryption starts, an SSH server sends its proposal: the key exchange algorithms, host key types, ciphers and MACs it accepts, each as a comma-separated list. Run the client with -vv and OpenSSH prints them:

debug2: peer server KEXINIT proposal debug2: KEX algorithms: mlkem768x25519-sha256,sntrup761x25519-sha512,curve25519-sha256,... debug2: host key algorithms: ssh-ed25519,ecdsa-sha2-nistp256,... 

If the client and server share no key exchange algorithm, the connection fails with the server's list in the error instead:

Unable to negotiate with 192.0.2.10 port 2222: no matching key exchange method found. Their offer: ... 

Both lines are easy to grep, and every OpenSSH client produces them, so scraping them is the obvious way to learn what a server offers. That is what my first version of pqc-probe did.

The cause: a 1,024-byte buffer

Every OpenSSH log message, debug or error, goes through one function, do_log in log.c. It formats the message into a fixed buffer on the stack:

#define MSGBUFSIZ 1024 ... char msgbuf[MSGBUFSIZ]; ... vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); 

vsnprintf never writes past the buffer. When the formatted text is longer, it keeps the first 1,023 bytes plus the terminating zero and drops the rest. Nothing is added to show the line was cut. That is safe, standard C, and exactly the right behaviour for a logger. It just means a log line is not a container for arbitrary-length data.

The server's list reaches that buffer from two places:

The buffer itself is at log.c, lines 327–392. Links point to OpenSSH portable as of 18 November 2026.

Who hits it

Stock OpenSSH servers do not. I measured the default lists compiled into OpenSSH portable: the server's key exchange list is 183 bytes and the longest default list, host key algorithms, is 605 bytes. Both fit with room to spare.

Post-quantum experiments do. The OQS fork of OpenSSH adds dozens of hybrid key exchanges with long names such as ecdh-nistp521-frodokem-1344-shaker2-sha512@openquantumsafe.org. Its default server list is 45 names and 1,577 bytes. As a debug2 line, OpenSSH keeps 1,023 of its 1,601 bytes, and the last name printed is ecdh-nis. My test server, configured with 71 names, lost even more.

So anything that learns a server's algorithms by scraping ssh -vv gets a silently incomplete answer from exactly the servers it most wants to inspect. That includes inventory scripts, compliance checks and scanners. In the fork's default list the classical algorithms come first, so the cut falls on the post-quantum ones: 26 names survive, and the 19 lost include every ML-KEM and sntrup761 variant at the end of the list.

The fix: read the packet yourself

The server's proposal is the first packet it sends, and it travels before any encryption, so you can read it with a plain TCP socket. RFC 4253 defines every byte:

  1. Both sides send an identification line such as SSH-2.0-OpenSSH_10.0. A server may send other text lines first (section 4.2), so skip lines until one starts with SSH-.
  2. The server then sends a binary packet (section 6) whose payload is SSH_MSG_KEXINIT (section 7.1).
Bytes Field
4 packet_length
1 padding_length
1 message type, 20 = SSH_MSG_KEXINIT
16 random cookie
4 + n kex_algorithms: length, then the comma-separated names
… nine more lists: host keys, ciphers, MACs, compression, languages (each in both directions where it applies)
1 + 4 first_kex_packet_follows, reserved

That is all it takes:

import socket, struct, sys host = sys.argv[1] port = int(sys.argv[2]) if len(sys.argv) > 2 else 22 sock = socket.create_connection((host, port), timeout=10) f = sock.makefile("rb") line = f.readline(8192) # servers may send text lines before their banner while not line.startswith(b"SSH-"): if not line: sys.exit("connection closed before the SSH banner") line = f.readline(8192) print("server:", line.decode(errors="replace").strip()) sock.sendall(b"SSH-2.0-kexinit-peek\r\n") length, padding = struct.unpack(">IB", f.read(5)) # binary packet header payload = f.read(length - 1 - padding) if payload[0] != 20: sys.exit(f"first packet is message {payload[0]}, not KEXINIT (20)") size = struct.unpack(">I", payload[17:21])[0] # skip type byte + 16-byte cookie names = payload[21:21 + size].decode().split(",") print(f"kex_algorithms: {len(names)} names, {size} bytes") print("\n".join(names)) 

Run it as python3 kexinit_peek.py example.com 22. Against a test server configured with the OQS fork's default list, it prints all 45 names, including the ones ssh -vv dropped:

server: SSH-2.0-OpenSSH_10.4 kex_algorithms: 45 names, 1577 bytes curve25519-sha256 ... mlkem1024-sha384 mlkem1024nistp384-sha384 sntrup761-sha512 

Against github.com, a typical production server, the whole list is 249 bytes, well inside the limit (the banner is GitHub's deliberately randomised one):

$ python3 kexinit_peek.py github.com server: SSH-2.0-bdb6c72c kex_algorithms: 10 names, 249 bytes mlkem768x25519-sha256 sntrup761x25519-sha512 sntrup761x25519-sha512@openssh.com curve25519-sha256 curve25519-sha256@libssh.org ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group-exchange-sha256 kex-strict-s-v00@openssh.com 

It only reads; it never completes a key exchange or logs in, and the server simply sees a client that disconnected early. Run it against servers you are responsible for.

How pqc-probe does it

pqc-probe's reader is the same idea with the edges filed down, in kexinit.rs. A tool that connects to arbitrary servers has to assume some of them are hostile, so every length is bounded and checked:

  • packets larger than 35,000 bytes are refused (the size RFC 4253 requires implementations to handle);
  • at most 32 text lines and 8 KB are accepted before the banner;
  • a length field that points past the end of the packet is an error, not a crash.

The parsing step reads like the Python, with every slice checked:

let rest = p.get(17..).ok_or("payload shorter than type + cookie")?; let len_bytes: [u8; 4] = rest .get(..4) .ok_or("missing kex_algorithms length")? .try_into() .map_err(|_| "bad length field")?; let len = u32::from_be_bytes(len_bytes) as usize; let end = 4usize .checked_add(len) .ok_or("kex_algorithms length overflow")?; let body = rest .get(4..end) .ok_or_else(|| format!("kex_algorithms claims {len} bytes but the packet ends first"))?; 

A regression test pins the bug down: it builds a packet with 60 names, more than 2,000 bytes, and checks that all 60 come back, the last one intact. If the scraping approach ever crept back, that test would fail.

One more lesson came with it. My old code treated an empty or unreadable offer as "the server offers nothing", and then reported that both clients "negotiate identically", which was technically true and completely wrong. An offer that cannot be read is now an error with a reason, never an empty success.

Debug output is not an interface

Nothing here is a bug in OpenSSH. A logger with a fixed buffer is sensible design, and nobody promised that ssh -vv would print every byte the server sent. The mistake was mine: I used human-facing diagnostics as a data source.

If you parse a tool's debug output anywhere in your own scripts, two questions are worth asking:

  • Can the value be longer than a log line? Algorithm lists, certificate chains and headers usually can.
  • Would you notice if it were cut? Truncation by vsnprintf leaves no marker, so a short answer looks like a complete one.

When the honest answer is "maybe" and "no", go to the source of the data instead. For SSH, the server's proposal is right there in the first packet, unencrypted, and the format has not changed since 2006.

Next in the series: probing SSH without getting penalised, or how OpenSSH 9.8's PerSourcePenalties turned real support into false negatives.