Skip to content

Handle ECH Retry - #9611

Open
yschimke wants to merge 9 commits into
lysine-dev:mainfrom
yschimke:retry_config
Open

Handle ECH Retry#9611
yschimke wants to merge 9 commits into
lysine-dev:mainfrom
yschimke:retry_config

Conversation

@yschimke

@yschimke yschimke commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

A few assorted changes

  • grab the ech retry config and use it to retry when we get a mismatch
  • avoid ech retry more than once
  • avoid downgrading from ech to non ech

@yschimke
yschimke requested a review from swankjesse July 26, 2026 17:18
@yschimke

Copy link
Copy Markdown
Collaborator Author

Comment thread android-test/src/androidTest/java/okhttp/android/test/EchTest.kt
@yschimke

Copy link
Copy Markdown
Collaborator Author

I'll ask at work tomorrow.

@yschimke
yschimke marked this pull request as draft July 26, 2026 17:38

@swankjesse swankjesse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to be particularly careful with landing this as it introduces new attack vectors and is not yet possible to test with MockWebServer + JVM Conscrypt.

I think it’s definitely good to have special recovery code for ECH handshake failures. But my first instinct is that special recovery code should mostly be about reducing the opportunity for downgrade attacks.

This is attempting to do something else, and I would like to understand the problem it solves before we land this.

Comment thread okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/dns/-DnsMessage.kt Outdated
Comment thread okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/connection/ConnectPlan.kt Outdated
Comment thread okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/connection/ConnectPlan.kt Outdated
Comment thread okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/connection/ConnectPlan.kt Outdated
@bjiang7

bjiang7 commented Jul 27, 2026

Copy link
Copy Markdown

Just chiming in here to state that the ECH recovery flow is a pretty important part of the spec, and so should be implemented if OkHttp is to say it supports ECH.

The reason why is because there's no other way to recover from a mismatch in ECH config between the client and server (i.e. synchronization issues). It's a performance hit to have to fall into this codepath (and shouldn't be happening in most cases), but it is needed so the consequences of things being out of sync is latency rather than outages.

I also asked BoringSSL a long time ago about this when doing the Android implementation, because I had the same question of how important the recovery flow was. Their stance was "This behavior is pretty crucial to allow servers to safely deploy ECH because DNS records can be stale and we need to make it possible for servers to recover from mismatches. The existence of any client that gets this wrong means a server now cannot deploy ECH in a rollback-safe way."

@swankjesse

Copy link
Copy Markdown
Collaborator

Making it safer for server operators to confidently deploy ECH is good.

@yschimke
yschimke marked this pull request as ready for review July 27, 2026 19:43
Comment thread okhttp/src/jvmTest/kotlin/okhttp3/InterceptorOverridesTest.kt

@swankjesse swankjesse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent. Some feedback and I’d like another look before merge. I promise to not make you wait so long on followups

val routePlanner = factory.newRoutePlanner(client, address)
val route = factory.newRoute(address)
val connectionSpecs = listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)
val socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one’s curious 'cause it’s missing TLS 1.3

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

fun staleEchConfigIsNotRetried() {
val rejection = client.echRejectionFrom("https://stale.tls-ech.dev/")
fun staleEchConfigIsRetried() {
val body = client.get("https://stale.tls-ech.dev/")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI stale.tls-ech.dev uses port 444 and wrong.tls-ech.dev uses port 445. Not sure if you're using the default port of 443, but if so that should probably be changed to make sure that you're not accidentally getting the default domain of plain tls-ech.dev.

Another option is adding an assertion that you're hitting the correct domain since it also appears on the page (stale.tls-ech.dev vs tls-ech.dev).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread android-test/src/androidTest/java/okhttp/android/test/EchTest.kt
return EchRetryConfig(
publicHostname = exception.publicHostname ?: return null,
// An absent retry config list is how a server securely disables ECH.
// TODO can Conscrypt hand us an empty list, and does it mean the same thing?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, Conscrypt would either hand you null or an actual EchConfigList obj. We do some minimal validation on the Conscrypt side to check that the list isn't empty or null and that its length matches up, before creating any EchConfigList object.

The rest of the validation is done by BoringSSL when we pass it the EchConfigList (that's where all the "exciting" validation logic comes in, e.g. version checking, etc.). That was a conscious design decision because we didn't want to duplicate this logic and have it become out of sync with BoringSSL.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import okio.ByteString

/**
* ECH Retry config. Generally sent by a server when there is a

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry config is normally sent by a server when the ECH configurations have become out of sync (e.g. the TTL on them expired, they rotated to a new ECH config), not from mismatched A/AAAA and HTTPS records, so I would update this KDoc.

For example, Cloudflare has 1 given ECH configuration at a time and rotates it every hour. They have a grace period of 4 hours after they've rotated it, so in theory if you got this old config (e.g. if you cached it past its TTL or something) and tried to use it after the grace period expired, this is where the server should be sending you a retry config.

https://datatracker.ietf.org/meeting/126/materials/slides-126-iepg-sessa-encrypted-client-hello-ech-an-active-measurement-perspective-00

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/dns/EchRetryConfig.kt Outdated
@yschimke
yschimke requested a review from swankjesse August 1, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants