When an Android application connects to a website using HTTPS, the communication is encrypted. However, some connection information can still be visible to network intermediaries during the initial TLS handshake.
One important example is the Server Name Indication (SNI). It tells the server which hostname the client wants to reach. Traditionally, this hostname is transmitted in the TLS ClientHello message without encryption. As a result, network operators and other intermediaries may be able to identify the domain an application is accessing, even when the actual HTTP communication is protected by HTTPS.
Android 17 introduces platform support for Encrypted Client Hello (ECH), a TLS extension that encrypts sensitive information in the initial handshake, including the real server name.
For developers, this means reviewing the networking libraries used by an application, configuring Android Network Security Configuration, and verifying that the remote server supports ECH.
In this article, you will learn how ECH works, what Android 17 changes, how to configure it for an Android application, and how to adopt it using OkHttp and custom networking implementations.
What Is Encrypted Client Hello?
Encrypted Client Hello is a TLS extension that protects sensitive information in the initial TLS handshake.
When a client establishes a secure connection with a server, it sends a ClientHello message. This message contains information needed to negotiate the TLS connection, including the server name in traditional TLS implementations.
The Server Name Indication extension allows multiple websites hosted on the same IP address to be served correctly. However, traditional SNI can expose the requested hostname to network observers.
ECH addresses this privacy limitation by separating the ClientHello into two parts:
ClientHelloOuter: Contains information needed to route the connection but does not expose the real hostname.
ClientHelloInner: Contains the actual connection details, including the real server name, protected through encryption.
The client encrypts the inner message using configuration information published by the server through DNS HTTPS records.
This prevents network intermediaries from easily identifying the specific hostname being accessed.
ECH does not encrypt the entire network connection by itself. TLS still protects application data, while ECH adds protection for sensitive handshake information.
Why Is ECH Important for Android Applications?
HTTPS protects application data from being read by unauthorized network observers. However, traditional TLS connections can still reveal the destination hostname through SNI.
Consider an Android application connecting to:
https://payments.example.com
Without ECH, a network observer may be able to identify payments.example.com during the TLS handshake.
With ECH, the actual hostname is included in the encrypted ClientHelloInner message.
This reduces the information available to network intermediaries.
ECH is especially useful for applications that handle sensitive activities, such as:
Banking and financial services.
Healthcare applications.
Authentication and identity management.
Enterprise applications.
Private communication services.
Applications connecting to multiple third-party APIs.
For example, a financial application may communicate with authentication, payment, analytics, and account services. ECH helps reduce the exposure of individual service hostnames during supported TLS connections.
It is important to understand that ECH does not hide every aspect of network communication. The destination IP address, connection timing, traffic volume, and other metadata may remain visible. ECH should be considered one part of a broader network privacy strategy.
What's New in Android 17?
Android 17 introduces platform support for ECH at API level 37.
For applications targeting API level 37 or higher, ECH is enabled by default through Android's network security policy.
However, enabling the platform feature does not automatically mean that every application connection uses ECH.
Three conditions are important:
The device must run Android 17 or higher.
The networking library must support Android's ECH implementation.
The remote server must publish valid ECH configuration information and support ECH negotiation.
If the server does not support ECH, the client can use ECH GREASE according to the configured policy. GREASE sends randomized ECH extension data to help prevent network infrastructure from becoming incompatible with future protocol extensions.
Android 17 also introduces the domainEncryption element in Network Security Configuration. Developers can use it to control ECH behavior globally or for specific domains.
Feature | Android 16 and earlier | Android 17 |
|---|
Platform ECH support | Not available | Available |
ECH default for target SDK | Not available | Enabled for API level 37 or higher |
Domain-level ECH configuration | Not available | Supported |
ECH GREASE | Not provided through this Android feature | Supported through compatible TLS implementations |
Networking library support | Depends on library and platform capabilities | Requires Android-compatible ECH support |
Server support | Required for successful ECH negotiation | Required for successful ECH negotiation |
Understanding the Android ECH Architecture
ECH involves several components working together.
The application uses an HTTP networking library to establish a connection. That library obtains the server's ECH configuration through DNS and passes the configuration to the platform TLS implementation.
The connection process can be represented as follows:
Android Application
|
v
HTTP Networking Library
|
v
DNS HTTPS Record Lookup
|
v
ECH Configuration Retrieval
|
v
Android TLS Implementation
|
v
Encrypted ClientHello
|
v
Remote Server
The main components are:
DNS HTTPS Records
ECH configuration information is published through DNS HTTPS resource records.
The client retrieves these records to obtain the information needed to encrypt the inner ClientHello.
Networking Library
The networking library coordinates DNS resolution, TLS configuration, and connection establishment.
For Android applications, the library must support the platform's ECH implementation.
Android TLS Implementation
Android provides platform APIs that allow compatible networking libraries to pass ECH configuration information into TLS connections.
Remote Server
The remote server must publish valid ECH configuration information and be configured to accept ECH connections.
If any required component is missing, ECH may not be negotiated successfully.
Updating the Android Application Configuration
The first step is to make sure that the application targets Android 17.
In the module-level build.gradle.kts file, update the SDK configuration:
android {
compileSdk = 37
defaultConfig {
targetSdk = 37
}
}
The compile SDK provides access to Android 17 APIs, while the target SDK enables the relevant target-specific behavior.
ECH is only available through Android's platform implementation on Android 17 and higher. An application targeting API level 37 does not make ECH available on older Android versions.
Configuring Network Security Configuration
Android 17 introduces the domainEncryption element in Network Security Configuration.
This element allows developers to enable or disable ECH globally or for selected domains.
First, create a file named network_security_config.xml inside the application's res/xml directory.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<domainEncryption mode="enabled"/>
</base-config>
</network-security-config>
The base-config applies the ECH policy to all domains handled by the application.
The enabled mode tells a compatible networking library to use ECH when the server provides an appropriate configuration. It also enables ECH GREASE when the server does not provide ECH support.
Registering the Configuration in AndroidManifest.xml
After creating the XML file, register it in the application manifest.
<application
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme"
android:label="@string/app_name">
<!-- Application components -->
</application>
The android:networkSecurityConfig attribute connects the application to the network security configuration file.
Once the application runs on Android 17, compatible networking libraries can follow the configured ECH policy.
The configuration does not automatically add ECH support to a networking library that does not implement it.
Enabling ECH With OkHttp
OkHttp is commonly used in Android applications for REST APIs, authentication, file uploads, and other HTTP operations.
Android's official ECH adoption guidance identifies OkHttp 5.5.0 as supporting ECH through AndroidDns or DnsOverHttps.
The library must use one of these DNS approaches to retrieve the HTTPS DNS records containing the server's ECH configuration.
Step 1: Add the OkHttp Dependency
Update the module-level build.gradle.kts file:
dependencies {
implementation("com.squareup.okhttp3:okhttp:5.5.0")
}
Use a compatible Android artifact and verify the dependency resolution in your project.
Step 2: Configure AndroidDns
AndroidDns retrieves the HTTPS DNS resource records required for ECH using Android's DNS capabilities.
Create an OkHttp client:
import okhttp3.OkHttpClient
import okhttp3.AndroidDns
val client = OkHttpClient.Builder()
.dns(AndroidDns())
.build()
This configures OkHttp to use AndroidDns for DNS resolution.
The library can retrieve the HTTPS records containing ECH configuration information and use Android's TLS support when establishing secure connections.
This is a straightforward approach when the application uses the system DNS infrastructure.
However, the DNS queries themselves are not necessarily encrypted. ECH protects the hostname inside the TLS handshake, but an observer may still learn information from DNS queries when ordinary unencrypted DNS is used.
Step 3: Configure DNS Over HTTPS
Applications that also want to protect DNS queries can use DNS over HTTPS (DoH).
OkHttp provides DnsOverHttps for this purpose.
import okhttp3.OkHttpClient
import okhttp3.DnsOverHttps
import okhttp3.HttpUrl.Companion.toHttpUrl
val bootstrapClient = OkHttpClient()
val client = bootstrapClient.newBuilder()
.dns(
DnsOverHttps.Builder()
.client(bootstrapClient)
.url("https://1.1.1.1/dns-query".toHttpUrl())
.build()
)
.build()
This example uses Cloudflare's DNS over HTTPS endpoint.
The bootstrap client is reused by DnsOverHttps so that the clients share the same connection pool and dispatcher.
DoH encrypts DNS queries between the application and the DNS resolver. This provides additional privacy beyond ECH.
The choice of DNS resolver should be based on the application's privacy requirements, operational policies, and user expectations.
Step 4: Make an HTTPS Request
After configuring the client, the application can make ordinary HTTPS requests.
import okhttp3.Request
val request = Request.Builder()
.url("https://example.com")
.build()
client.newCall(request).execute().use { response ->
println("HTTP status: ${response.code}")
println(response.body.string())
}
The request code does not need a special ECH header or manual TLS extension.
OkHttp manages the DNS and TLS integration according to its configuration and the capabilities of the Android platform.
For production applications, execute synchronous requests on a background thread or use OkHttp's asynchronous API. Do not perform blocking network operations on the Android main thread.
Configuring ECH for Specific Domains
Some applications communicate with multiple backend services. A developer may want ECH enabled for most domains while disabling it for a specific domain due to compatibility requirements.
Android 17 supports domain-level configuration.
For example:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<domainEncryption mode="enabled"/>
</base-config>
<domain-config>
<domain includeSubdomains="true">
legacy.example.com
</domain>
<domainEncryption mode="disabled"/>
</domain-config>
</network-security-config>
In this example:
ECH is enabled by default.
ECH is disabled for legacy.example.com.
The domain configuration also applies to its subdomains.
The disabled mode tells compatible networking libraries not to attempt ECH or ECH GREASE for the configured domain.
Use domain-specific exceptions only when there is a clear compatibility requirement. Disabling ECH reduces handshake privacy for those connections.
Understanding ECH GREASE
ECH GREASE is an important part of the ECH implementation.
GREASE stands for Generate Random Extensions And Sustain Extensibility. It is a technique used in TLS to help ensure that servers and network intermediaries correctly handle protocol extensions they may not fully understand.
When a server does not support ECH, a compatible client can send an ECH extension containing randomized data instead of a valid encrypted ClientHello.
This helps prevent network infrastructure from blocking connections simply because it encounters an ECH extension.
Android's default platform SSL implementation handles ECH GREASE when the networking library uses the platform SSLSocketFactory.
If a library implements its own TLS stack, it must handle GREASE itself according to the platform's domain encryption policy.
GREASE does not provide the same protection as successfully negotiated ECH. It is a compatibility mechanism, not a replacement for server-side ECH support.
Understanding ECH Support in Different Networking Libraries
Android applications use different networking libraries depending on their architecture.
ECH support must be evaluated separately for each library.
Networking library | Android 17 ECH support |
|---|
OkHttp | Supported starting with 5.5.0 through AndroidDns or DnsOverHttps |
HttpEngine | Support planned for Android 17 QPR2 (API level 37.2), according to the Android adoption documentation |
WebView | Support planned for a future release |
Custom TLS implementation | Must integrate Android's ECH platform APIs |
Platform SSLSocket | Provides the TLS-side integration when supplied with ECH configuration information |
Do not assume that upgrading the Android target SDK automatically enables ECH in every networking library.
For example, an application may use OkHttp for REST API requests and WebView for displaying web content. The two networking paths may have different ECH support depending on the library and platform version.
Review every networking component used by the application.
Implementing ECH in a Custom Networking Library
Developers building their own HTTP clients or networking libraries can integrate directly with Android's ECH platform APIs.
The implementation involves three main stages.
Stage 1: Check the Domain Encryption Policy
Before retrieving ECH configuration information, the library should check the application's configured policy using NetworkSecurityPolicy.getDomainEncryptionMode().
import android.security.NetworkSecurityPolicy
val policy = NetworkSecurityPolicy.getInstance()
val mode = policy.getDomainEncryptionMode("example.com")
The policy determines whether ECH should be disabled or enabled for the requested domain.
The main modes include:
Mode | Behavior |
|---|
DOMAIN_ENCRYPTION_MODE_DISABLED | Do not attempt ECH or GREASE |
DOMAIN_ENCRYPTION_MODE_ENABLED | Use ECH when supported and GREASE otherwise |
DOMAIN_ENCRYPTION_MODE_OPPORTUNISTIC | Older opportunistic mode, deprecated in API level 37.1 |
DOMAIN_ENCRYPTION_MODE_UNKNOWN | Do not attempt ECH |
For applications using Android 17.1 or later, the opportunistic mode is deprecated and does not need separate handling beyond that API level.
Stage 2: Retrieve the ECH Configuration
The library must obtain the server's HTTPS DNS record.
Android provides DnsResolver APIs for this operation.
The high-level DnsResolver.query() API can retrieve A, AAAA, and HTTPS records and combine the results into an HttpsEndpoint.
A simplified Kotlin example is:
val resolver = DnsResolver(context, looper)
resolver.query(
network,
hostname,
DnsResolver.TYPE_HTTPS,
executor,
DnsResolver.HTTPS_QUERY_WAIT_AUTO,
cancellationSignal,
object : DnsResolver.Callback<HttpsEndpoint> {
override fun onAnswer(
answer: HttpsEndpoint,
rcode: Int
) {
val record = answer.httpsRecords.firstOrNull()
?: return
val echConfigList = record.echConfigList
?: return
establishEchConnection(echConfigList)
}
override fun onError(
error: DnsResolver.DnsException
) {
// Handle DNS resolution failure.
}
}
)
The example shows the high-level flow. A production implementation must also handle DNS response codes, missing records, cancellation, network changes, and fallback behavior.
Stage 3: Configure the TLS Socket
After retrieving the ECH configuration, pass it to the platform TLS socket before starting the handshake.
fun establishEchConnection(
echConfigList: EchConfigList
) {
val socket = sslSocketFactory.createSocket(
ipAddress,
port
) as SSLSocket
SSLSockets.setEchConfigList(
socket,
echConfigList
)
socket.startHandshake()
}
The ECH configuration must be applied before the TLS handshake begins.
This example represents the core TLS integration. A complete implementation must also preserve certificate validation, hostname verification, socket cleanup, connection timeouts, and the application's normal error-handling behavior.
Handling ECH Configuration Changes and Retry
ECH configurations are published through DNS and can change over time.
For example, a server may rotate its ECH keys or replace its configuration. A client using an older configuration may fail to complete the TLS handshake.
Android provides EchConfigMismatchException for this situation.
The exception may contain an updated ECH configuration that the client can use to retry the connection.
A safe retry process should:
Catch EchConfigMismatchException.
Retrieve the public hostname using getPublicHostname().
Verify the public hostname using the application's HostnameVerifier.
Retrieve updated ECH configuration using getRetryConfigList().
Retry the connection only when valid updated configuration is available.
The following example illustrates the important checks:
try {
socket.startHandshake()
} catch (exception: EchConfigMismatchException) {
val publicName = exception.publicHostname
?: throw exception
if (hostnameVerifier.verify(publicName, socket.session)) {
val retryConfig = exception.retryConfigList
if (retryConfig != null) {
retryConnection(retryConfig)
} else {
throw exception
}
} else {
throw exception
}
}
The retry operation should create a new connection and apply the updated ECH configuration before starting the new handshake.
Do not bypass hostname verification or certificate validation to make an ECH connection succeed.
If the retry information is missing or invalid, report the connection failure to the calling application.
Testing ECH in Android Studio
Testing is important because ECH depends on the Android version, networking library, DNS records, and server configuration.
A successful HTTPS request does not automatically prove that ECH was negotiated.
Use the following testing process.
1. Run on Android 17
Install the application on an Android 17 emulator or a compatible physical device.
Verify the device API level and ensure that the application targets API level 37 or higher.
2. Verify the Networking Library
Confirm that the application uses an ECH-compatible networking library.
For OkHttp, use version 5.5.0 or later and configure AndroidDns or DnsOverHttps as appropriate.
3. Verify Server Support
Check whether the destination server publishes an HTTPS DNS record containing valid ECH configuration information.
A server that does not publish ECH configuration cannot complete normal ECH negotiation.
4. Test the DNS Configuration
If using DnsOverHttps, verify that the application can resolve the required HTTPS records through the configured resolver.
If using system DNS, verify that the system resolver returns the expected information.
5. Inspect the TLS Handshake
Use a controlled network test environment or suitable TLS diagnostic tools to verify whether the connection negotiated ECH.
Do not rely only on the HTTP response code. A successful HTTPS request may have used ordinary TLS without ECH.
6. Test Unsupported Servers
Test a destination that does not support ECH.
Verify that the connection follows the configured policy and that ECH GREASE or the expected fallback behavior does not break connectivity.
7. Test Older Android Versions
Run the same application on Android 16 or earlier.
ECH platform support described in this article is available only on Android 17 and higher. The application should continue using its normal HTTPS behavior on older versions.
Common ECH Problems and Troubleshooting
ECH Is Not Being Negotiated
A common mistake is assuming that targeting Android 17 is enough to enable ECH.
Check the following:
The device runs Android 17 or later.
The application targets API level 37 or higher.
The networking library supports ECH.
The library uses a supported DNS configuration.
The remote server publishes valid ECH configuration information.
The domain encryption policy is not disabled.
DNS Does Not Return ECH Configuration
ECH configuration information is published in HTTPS DNS records.
If the resolver does not return these records, the client may not have the information required for ECH negotiation.
Verify that the DNS resolver supports HTTPS record queries and that the server publishes the required configuration.
HTTPS Works but the Hostname Is Still Visible
An HTTPS connection does not automatically mean that ECH was used.
Check the networking library and server support. Also distinguish between DNS visibility and TLS SNI visibility.
If ordinary DNS is used, the queried hostname may still be visible to the DNS resolver or network observers, depending on the DNS transport.
Connection Fails After an ECH Configuration Change
The server may have rotated its ECH configuration.
Handle EchConfigMismatchException and use valid retry configuration when provided. Do not repeatedly retry with an outdated configuration.
OkHttp Does Not Use ECH
Check the OkHttp version and DNS configuration.
OkHttp 5.5.0 introduced ECH support through AndroidDns and DnsOverHttps. Using an older version or an unsupported DNS implementation may prevent ECH configuration retrieval.
WebView Does Not Use ECH
ECH support in WebView depends on the platform WebView implementation.
Android's ECH adoption documentation identifies WebView support as planned for a future release. Do not assume that configuring the application-level network security XML automatically enables ECH in every WebView version.
Best Practices for Android Developers
Upgrade Networking Libraries Carefully
Use networking library versions that explicitly support Android's ECH implementation.
Review release notes and test the exact library version used by the application.
Prefer Encrypted DNS Where Appropriate
ECH protects the hostname in the TLS handshake, but it does not automatically encrypt DNS queries.
Consider DNS over HTTPS or another suitable encrypted DNS solution when the application needs additional DNS privacy.
Keep Network Security Configuration Simple
Enable ECH globally when it is appropriate for the application.
Use domain-specific disabled policies only for verified compatibility requirements.
Preserve TLS Certificate Validation
ECH is not a replacement for HTTPS certificate validation.
Always preserve normal hostname verification and certificate-chain validation.
Handle DNS and TLS Failures Separately
A missing HTTPS DNS record, an invalid ECH configuration, a certificate failure, and a network timeout are different problems.
Use separate error handling so that troubleshooting and retry behavior remain predictable.
Test Every Networking Path
Applications may use multiple networking components, including OkHttp, WebView, native sockets, and third-party SDKs.
Check ECH support for each component rather than assuming that one successful integration covers the entire application.
Monitor Compatibility in Production
Track TLS failures, DNS errors, and connection retries.
This helps identify server-side configuration changes or resolver problems after deployment.
Advantages and Limitations of ECH
Advantages | Limitations |
|---|
Encrypts the real hostname in the TLS handshake | Requires Android 17 or later for this platform implementation |
Reduces hostname exposure to network intermediaries | Requires networking library support |
Helps reduce domain-based traffic profiling | Remote servers must support ECH for successful negotiation |
Integrates with Android Network Security Configuration | DNS queries may still reveal hostnames if ordinary DNS is used |
Supports global and domain-specific policies | Does not hide destination IP addresses |
Works alongside HTTPS encryption | Does not replace certificate validation |
Supports ECH GREASE for protocol compatibility | Custom TLS libraries require additional implementation work |
Conclusion
Android 17 introduces Encrypted Client Hello support to improve the privacy of secure network connections. By encrypting the real server name in the TLS handshake, ECH reduces the ability of network intermediaries to identify the specific hostname an application is accessing.
For Android developers, adopting ECH involves more than changing the target SDK. The application must use a compatible networking library, the remote server must publish valid ECH configuration, and the DNS and TLS components must work together.
OkHttp 5.5.0 provides a practical integration path through AndroidDns or DnsOverHttps. Developers building custom networking libraries can use Android's DnsResolver and SSLSockets APIs to retrieve ECH configuration and apply it to TLS connections.
For production applications, enable ECH where supported, consider encrypted DNS, preserve certificate verification, and test both supported and unsupported server scenarios. These steps help improve connection privacy without sacrificing application reliability.
Join the conversation! Your thoughts help the community grow.