# Post-quantum cryptography is breaking government censors

Ever since [Discord got banned](https://explorer.ooni.org/findings/2025-turkiye-blocked-discord) here in 2024, I've had my selfhosted [Amnezia VPN](https://github.com/amnezia-vpn/amneziawg-go) 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:

Free Partly free Not free

1.  94
2.  91
3.  85
4.  78
5.  74
6.  73
7.  65
8.  51
9.  48
10.  37
11.  31 Turkey
12.  28
13.  25
14.  22
15.  17
16.  13
17.  9
18.  n/a

_[Freedom on the Net 2025](https://freedomhouse.org/report/freedom-net/2025/uncertain-future-global-internet) 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.

1/5

For a while, Turkey was in a weird spot where it was banning popular services left and right like [Youtube](https://en.wikipedia.org/wiki/Censorship_of_YouTube#Turkey) and even [Wikipedia](https://en.wikipedia.org/wiki/Block_of_Wikipedia_in_Turkey), 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.

![8.8.8.8 spray-painted on a wall](https://xetera.dev/_astro/dns_ban.5uWTHTOu.webp)

_Graffiti showing Google's public DNS workaround after the  
[Twitter ban in 2014](https://www.newsweek.com/turkeys-erdogan-blocks-twitter-dissidents-use-graffiti-spread-work-around-232649) captioned "let your bird sing."_

Unsurprisingly, this quickly escalated into an arms race, where Turk Telekom was caught [hijacking 8.8.8.8 traffic](https://www.internetsociety.org/blog/2014/04/turkish-hijacking-of-dns-providers-shows-clear-need-for-deploying-bgp-and-dns-security/) and returning poisoned responses to Google's DNS queries as if they were being made to the ISP resolvers.

1/5

By 2018 latest, government controlled ISPs reportedly [obtained PacketLogic DPI devices](https://citizenlab.ca/2018/03/bad-traffic-sandvines-packetlogic-devices-deploy-government-spyware-turkey-syria/) 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](https://citizenlab.ca/2023/09/predator-in-the-wires-ahmed-eltantawy-targeted-with-predator-spyware-after-announcing-presidential-ambitions/) 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](https://en.wikipedia.org/wiki/Protocol_ossification) 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.

››

packet 1 · 637 B · payload 617 BMTU · 1500 B

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)](https://blog.cloudflare.com/announcing-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:

SNI499 bytes

-   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`.

SNIML-KEM key share1,721 bytes

-   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.

Classic key\_share (X25519)47 B

Post-quantum key\_share (X25519MLKEM768)1,267 B · 27× larger

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.

Either way, 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.

››

packet 1 · 1500 B · payload 1480 BMTU · 1500 B

packet 2 · 402 B · payload 382 B

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](https://tldr.fail/) 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.

key\_sharesupported\_versions⋯660d454c522b002b0007064a

⋯type0x002blength7 B

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](https://chromestatus.com/feature/5124606246518784) 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:

key\_sharepsk\_key\_exchange\_modes⋯660d454c522b002d00020101

⋯type0x002dlength2 B

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.

key\_sharepsk\_key\_exchange\_modes⋯660d454c522b002d00020101

⋯

⋯660d454c522b002d00020101

⋯

⋯660d454c522b002d00020101

⋯type0x002dlength2 B

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?

key\_sharepsk\_key\_exchange\_modes⋯660d454c522b002d00020101

⋯type0x002dlength2 B

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`.

key\_sharesignature\_algorithms⋯660d454c522b000d00120010

⋯type0x000dlength18 Blist\_len16 B

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.

Broken!server\_name⋯009900000010000e00000b776174747061642e636f6d

⋯type0x0099type0x0000length16 Blist\_len14 Bname\_type0x00name\_len11 Bhost\_namewattpad.com

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.

Broken!server\_name⋯009900000010000e00000b6578616d706c652e636f6d

⋯type0x0099type0x0000length16 Blist\_len14 Bname\_type0x00name\_len11 Bhost\_nameexample.com

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`](https://datatracker.ietf.org/doc/html/draft-ietf-tls-esni-06), 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](https://datatracker.ietf.org/doc/rfc8701/) 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.

![I can't believe it's not real GREASE](https://xetera.dev/_astro/i_cant_believe_its_not_grease.e4Am2pHS.png)

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.

supported\_groups⋯000a000c000a2a2a11ec001d00170018⋯

⋯000a000cffff2a2a11ec001d00170018⋯type0x000alength12 Blist\_len65535 BgroupGREASEgroupX25519MLKEM768groupx25519groupsecp256r1groupsecp384r1

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, as well as splitting cleanly after one protocol. 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.

application\_layer\_protocol\_negotiation⋯0010000e000c02683208687474702f312e31

⋯

⋯0010000e000c02683208687474702f312e31

⋯type0x0010length14 Blist\_len12 Blen2 Bprotocolh2len8 Bprotocolhttp/1.1

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 earlier draft codepoints that saw real-world deployment (`0xffce` from ESNI and `0xfe0a` from early 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 because CF asks for a max size of 1400 bytes - 12 bytes of TCP options. 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`):

1 15

key\_share first

11 14

buggy extension next

11 210

exact odds

5.24% bypass rate

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 whac-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 [Fingerprinting Deep Packet Inspection Devices by Their Ambiguities](https://arxiv.org/html/2509.09081v1) - 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.