Post-quantum cryptography is breaking government censors
Huge ML-KEM public keys in TLS handshakes are accidentally exploiting dormant bugs in Turkish middleboxes
Ever since Discord got banned here in 2024, I've had my selfhosted Amnezia VPN turned on 24/7. It works great, but every once in a while, I'll have to turn off my VPN to do something with my real IP, and I'll forget to turn it back on. And somehow, if I wait long enough, Discord will MAGICALLY come back to life on its own!
For almost two years I attributed this to race conditions in middleboxes because I could replicate a similar behavior by going to a website like roblox.com (yes roblox too), and holding down refresh until it too magically loaded before breaking again on the next refresh. I didn't look into it much past that. I figured the censor was just getting overwhelmed and letting some requests it can't process through. Turns out the real explanation is far more interesting than anything I could've imagined. If you live in Turkey and your ISP isn't Superonline, you probably think I'm crazy because you've never experienced this before. But I promise I'll make it make sense.
How countries ban websites
Internet freedom around the world looks something like this:
- 94 Iceland, 94 out of 100
- 91 Estonia, 91 out of 100
- 85 Canada, 85 out of 100
- 78 Japan, 78 out of 100
- 74 Germany, 74 out of 100
- 73 United States, 73 out of 100
- 65 South Korea, 65 out of 100
- 51 India, 51 out of 100
- 48 Indonesia, 48 out of 100
- 37 Kazakhstan, 37 out of 100
- 31 Turkey Turkey, 31 out of 100
- 28 Egypt, 28 out of 100
- 25 Saudi Arabia, 25 out of 100
- 22 Vietnam, 22 out of 100
- 17 Russia, 17 out of 100
- 13 Iran, 13 out of 100
- 9 China, 9 out of 100
- n/a North Korea, not rated
Freedom on the Net 2025 scores out of 100 by Freedom House.
Literally every country on Earth has some level of network interference, and it correlates heavily with real-life freedoms. Countries on the left of the graph tend to focus more on security and copyright enforcement, while more authoritarian-leaning countries take drastic measures to interfere with any kind of traffic they don't like.
The cheapest and most common method is DNS poisoning, where your ISP returns you fake results to plaintext DNS queries. This works surprisingly well because every ISP has to run a DNS server, and very few people even know what that is or bother to change whatever DHCP hands out.
For a while, Turkey was in a weird spot where it was banning popular services left and right like Youtube and even Wikipedia, but did so with primitive methods that were so easy to bypass, even non-technical people like my mom knew how to change their DNS settings to unblock every website.

Graffiti showing Google's public DNS workaround after the
Twitter
ban in
2014
captioned "let your bird sing."
Unsurprisingly, this quickly escalated into an arms race, where Turk Telekom was caught hijacking 8.8.8.8 traffic and returning poisoned responses to Google's DNS queries as if they were being made to the ISP resolvers.
By 2018 latest, government controlled ISPs reportedly obtained PacketLogic DPI devices to step up their censorship game and crack down on DNS workarounds, which became ever more important as TLS reached near complete adoption. Superonline today is almost certainly running the same gear. Every RST it injects carries the 32120 TCP window Citizen Lab fingerprinted on PacketLogic boxes. † The 2018 report also found a hardcoded IP ID of 13330 on injected packets. They've all been random in my tests, so there's likely been a firmware update to change that.
Deep Packet Inspection
The next level in censorship is looking at and vetting specific packets passing through your infrastructure, which is way more computationally expensive and difficult to pull off. The machines doing this have to be fast enough to not slow down customer traffic, they have to be correct without letting requests slip through, and they have to be resilient without ossifying any specific protocol. It's a very difficult task to get a perfect score on.
For some context, your device connects to websites by wrapping its requests in multiple different layers. For HTTP/2 (the most common HTTP protocol at the moment), it layers TLS on TCP on IP. Middleboxes that do deep packet inspection have to understand every protocol under the one they care about (in this case it's all of them) and be able to unwrap messages they were never meant to read. That's where the "deep" part of DPI comes from.
Click a payload to expand its contents.
The TLS protocol has a field on the ClientHello record your client sends when initiating its connection called Server Name Indication (SNI), that tells the server which domain it's trying to connect to. Sadly this gets sent in plaintext † ECH (Encrypted Client Hello) allows encrypting this entire process ahead of time, but it's only a meaningful improvement for infrastructure that fronts many websites like Cloudflare and Cloudfront where 1 ip != 1 domain. China and Iran already block this. as the machine you're connecting to might be hosting multiple websites and will need to know which site's certificate to respond with. Censors take advantage of this to drop or reset connections to blocked domains without having to care about DNS or encrypted traffic.
Let's take a closer look at that ClientHello record:
- headers
- fixed fields
- extensions
- server_name
- key_share
- GREASE
It has a few fixed fields and a cleverly designed extension system that allows the protocol to evolve without requiring brand new proposals. Each extension has a 2 byte identifier, a 2 byte length, and arbitrary data following it. Most middleboxes only care about the SNI field and will use that length prefix to skip everything they don't recognize.
Observant readers will have noticed there's a maximum size to what the IP packet can fit. For many reasons, there is a cap to how much data you can put on a single Ethernet or Wi-Fi frame. Many layers on top of the physical / link layer have their own solution to split their payloads to not exceed that mostly universal 1500 byte cap. Even though TLS and ClientHello in specific have evolved many times over the years, it's never really come close to exceeding that cap until recently. Let's see how big that same packet gets when the client supports a post-quantum algorithm like X25519MLKEM768.
- headers
- fixed fields
- extensions
- server_name
- key_share
- GREASE
That's a more than 3x increase in size just to offer the server the possibility of a different algorithm! By the way, notice how the post-quantum key exchange bundles in two X25519 public keys, both for the hybrid exchange, and the old school key exchange. It would almost annoy me if that redundancy made any difference in size at all.
I'm going to be honest, I don't have a good understanding of why this key is so big. I know that an X25519 public key represents a point on an elliptic curve, and that lattice cryptography isn't as compact with a neat input like that. But a 35x+ increase in key size is far beyond anything I would've expected.
Most importantly, this packet no longer fits our MTU, and has to be split in some way. For the purposes of ClientHello, this is done the exact same way any generic large payload is split, by sending the rest in a different TCP segment.
Click a payload to expand its contents.
There's no TLS header on the second packet, because it's simply the continuation of the previous payload. You may already see where this is going. Because middleboxes are not used to seeing this message get segmented, the way they detect/handle reassembly is poorly tested if not outright broken. That's a problem people have known about for a while, but in our case, the middlebox breaking is a good thing because they tend to fail open and let traffic through when they do 😄.
How middleboxes break
After doing some probing, I came up with a hypothesis that I thought was plausible. The censor was probably letting through packets that split perfectly between two extensions without checking whether there's more on the way if it hadn't already seen the SNI, with logic that could look something like this:
if (is_client_hello(&packet)) {
tls_ch* hello = parse_hello(&packet);
if (is_blocked(hello))
return block();
else if (is_packet_valid(hello))
return ok();
else
return wait_for_more();
}
Where the packet split would happen right at the end of one extension and the start of the next one.
Because the censor hadn't seen an offending SNI record yet, and there was no incomplete extension indicating it had to wait for more bytes, it might blindly be letting the request through after seeing packet 1. And to my surprise this worked! But there was a problem. In my tests (pressing cmd + r until Discord comes back online) I was seeing ~5-6% success rate, not the near-100% success rate I would expect from the same client contacting the same server, since there's almost nothing variably sized in a ClientHello.
I later remembered that Chromium - which Discord uses (for now) - had pushed out a TLS extension randomization update a couple years ago to fight TLS fingerprinting by shuffling the list of extensions it sends. That would explain why I was getting a low success rate, but if that were the case, I should've been seeing a much lower success rate. The chances of the SNI field being in the second packet while the cut happens exactly between 2 extensions should be astronomically low; well below 1%.
I looked at the packet capture of a passing request, and this is where the two packets happened to be segmented:
Not at the end of key_share like I thought it would be, but 3 bytes after it. Somehow, forcing a +2 split on the same packets also worked consistently, though not +4, +5 or onwards.
These +2 and +3 byte offsets also seem to work for almost every other extension. I think what's going on here is that this specific part of the length processing codebase was never updated to account for multiple TCP packets, and fails open for what it thinks are malformed packets that end abruptly. Even though the part of the codebase for skipping the rest of the body waits for the next packet as expected.
if (pointer + 2 > end) {
// broken packet, don't read past the end
return ok();
}
uint16_t ext_len = read_u16(pointer);
This begs the question, what happens if we split at +1, where the parser doesn't know what it's parsing yet, and saved the first byte of the extension while it waits for the second byte?
The request goes through! But not because it thinks the packet is broken. After reading the second byte 0x2d, the DPI forgets what it was doing!! And it goes through the extension parsing code from the top, reading 0x0002 (extension length) as an unknown extension type, and 0x0101 (extension body) as a 257 byte long extension it has to skip.
Even crazier yet, the buggy parser manages to re-synchronize for certain extensions that contain an inner length field like signature_algorithms.
It reads 0x0012 (extension length) as an unknown extension type, then 0x0010 (list_len) as the extension length. By pure chance, that extension's inner length happens to equal how much more of that extension has to be read, and lands on the start of whatever the next extension is. They probably use these kinds of extensions in their test suite.
To figure this out, I crafted a request to wattpad.com (yes even wattpad 😭) with a fake extension 0x0099 split across the middle, and a valid SNI extension immediately afterwards. This is now a completely broken ClientHello, but because the parser forgot what it was doing after receiving the second byte of the extension, it goes back to parsing the SNI successfully, and blocks the request after seeing what it thinks is a new SNI extension.
Simply replacing the blocked host lets the (broken) request through, though we get a TLS alert back from the recipient since it can't decipher the nonsense we just sent it.
These offset tricks don't work for every extension though. When the censor sees SNI, supported_groups, GREASE, ECH and even the ESNI draft proposal, it does wait for the next bytes correctly, meaning there's something "special" about those extensions that just happen to parse the length correctly.
if (is_special(packet)) {
process_packet_v2(packet);
} else {
process_packet_v1(packet);
}
As a sidenote, it's a little bit ironic this happens with GREASE as well, since the whole point of it is to get ignored, yet it's specifically being detected here, and detected poorly. GREASE values are supposed to be repeating bytes ending with a, like 0x1a1a or 0xfafa, but it seems they've implemented their check lazily like:
if ((t & 0x0f0f) == 0x0a0a) {
// ❌
}
// as opposed to
if ((t & 0x0f0f) == 0x0a0a && (t >> 8) == (t & 0xff)) {
// ✅
}
because an invalid GREASE extension like 0x1a2a also triggers their GREASE special-path despite not being real GREASE.
Now all of this would be understandable for SNI, since that's the main thing they're looking for, and it really is "special." But why would a censorship middlebox have a different code branch for supported_groups?
It's not just about censorship
To check if those extensions are being treated differently, I took a capture of a failing 1 TCP segment request, and updated the body of supported_groups by setting the list_len field that immediately follows the extension length to an invalid length.
The request went through the censor and got a TLS alert response! Which means the censor does read the body of that extension, and through some more experimentation, I found out that it fails open for any case where the extension length isn't validated to be exactly list_len + 2, unlike every other extension where the body is completely skipped.
The same body-validation behavior exists for ALPN as well. We also see a repetition of the earlier extension length parser bug there, but now with the list_length fields. Splitting the packet in the middle of the length of the protocol list also fails open, similar to how splitting the extension length breaks the parser. They must be calling the same length parsing function here. These are such mind-blowing revelations to me, I'm like Levent Alpöge if he dropped out of uni and was unemployed.
At first I thought all this special-casing and body extraction was a sign of proprietary TLS fingerprinting to detect TLS based VPNs like OpenVPN or VLESS because it's specifically looking for GREASE. Not something off-the-shelf like JA3/JA4, because the boxes don't seem to care about important extensions like ec_point_formats, but a proprietary AppLogic (formerly Sandvine) algorithm. But thinking over it some more, I'm almost certain they do this to collect data on usage trends for some dashboard somewhere, and it makes sense when you think about why each one would be special:
SNI
If there was ever going to be a special case, it would make sense for it to be this one.
ALPN
This contains important information about protocol usage. Based on my research, Superonline started censoring QUIC traffic sometime this year, so they are probably keeping an eye on HTTP/2 and HTTP/3 client support with this.
Supported Groups
As funny as it might seem, I think they're looking at post-quantum crypto adoption here. It's possible AppLogic might end up fixing some of these bugs as PQC adoption continues to get closer to 100%, but I honestly doubt it.
ECH
This is the main danger to their censorship efforts that they
probably want to be on the lookout for. It probably doesn't help that Chrome
sends fake ECH extensions even when the server can't support it.
Legacy ESNI
This is what makes me sure this whole thing is not about fingerprinting.
These guys have been monitoring workarounds for a long time, and still treat
the exact 2 draft extensions that saw real-world deployment (0xffce,
0xfe0a) before ECH was called ECH differently from everything else.
It's also possible Superonline doesn't care about or see any of this information at all, and it's just that the generic extraction function that runs for every customer touches those fields before being discarded. We simply have no way to know, it's not like we're recompiling the GTA VI binary here.
Winning the lottery
Putting it all together, my connection to Cloudflare for Discord has a maximum TCP segment size of 1,388 bytes. The ClientHello header plus the leading GREASE extension BoringSSL always prepends take up 118 bytes, and key_share alone is 1,267 bytes, coming in at 1,385 bytes total. Since even an empty extension is 4 bytes, if any other extension gets shuffled in front of key_share, the 1,388-byte cut lands inside key_share's body and the censor blocks it.
The only way through is if BoringSSL shuffles key_share into the very first slot, leaving exactly 3 bytes before the TCP segment splits and landing the cut at +3 into whatever extension comes next. That triggers the length bug for 11 of the remaining 14 extensions (everything except SNI, supported_groups, and ECH):
That 5.24% chance matches the behavior I was seeing exactly! I use Discord as my example here, because connecting to the gateway is the one thing that stops you from chatting after you get disconnected.
Annoyingly though, updates.discord.gg uses a different TLS stack that doesn't include PQC algorithms at all, so if you fully restart Discord and get stuck on the update gate, you can never win that 5% lottery on my ISP. @advaith pls fix with Discord Phoenix, literally unusable.
Other ISPs
Earlier, I mentioned that other ISPs don't have this problem. I tested the same thing on Vodafone's network and yes, they don't seem to have these specific problems, but they still have problems of their own.
| Edge case | Superonline | Vodafone |
|---|---|---|
| IP fragmentation | ✅ Reassembles perfectly | ✅ Reassembles perfectly |
| TCP segmentation | ❌ Held together with duct tape and prayers | ✅ Reassembles perfectly |
| Small packet handling | ✅ No confusion | ❌ Lets any TCP segment <10 bytes through |
| TLS record splitting | ❌ Split records ignored completely | ❌ Split records ignored completely |
| QUIC censorship | ✅ Inspects Initial packets | ❌ Ignores QUIC |
Both ISPs have no idea a ClientHello packet can be split into multiple records in a single TCP segment. But if you do use a different ISP like Vodafone, you've likely never run into this bug, because not all of them have problems reassembling larger TCP packets the way Superonline does.
Every time the web evolves to become more secure or private, it pokes holes in brittle middleboxes and makes authoritarians play another round of wack-a-mole using hard-earned taxpayer money. What's the point of even having internet access if we end up turning into China and Iran to block everything?
Once I have a little bit more time, I want to use my findings - along with this research paper Finding Deep Packet Inspection Devices by Their Ambiguities - to build a tool that can turn these behaviors into a fingerprint we can use to match software deployed in different countries across every possible dimension.
Enjoyed reading?
Feel free to follow or reach out to me on Twitter 1 before it dies and I have to move to a different Twitter.