Skip to content

Enforce Endpoint Identification in Conscrypt TLS strategies - #1535

Merged
ok2c merged 1 commit into
apache:masterfrom
ok2c:conscript_endpoint_identification
Nov 27, 2026
Merged

ok2c merged 1 commit into
apache:masterfrom
ok2c:conscript_endpoint_identification

Conversation

@ok2c

@ok2c ok2c commented Nov 25, 2026

Copy link
Copy Markdown
Member

@arturobernalg Please double-check

@ok2c
ok2c requested a review from arturobernalg November 25, 2026 18:59
@arturobernalg

Copy link
Copy Markdown
Member

I think the client side fix is right - tested a hostname mismatch against a real TLS server, master accepts it (bad), this PR rejects it with SSLHandshakeException.
But I think there might be a side effect: since ConscryptSupport#initialize is shared with the server strategy, this may also enable endpoint identification server-side, and I think that breaks client-cert auth (tested
setNeedClientAuth with a valid client cert - works on master, fails with CERTIFICATE_UNKNOWN on this PR). Might be worth checking if the fix should apply to the client strategy only.

`
private static final Timeout TIMEOUT = Timeout.ofSeconds(30);

public static void main(final String[] args) throws Exception {
    final URL keyStoreURL = ConscryptServerClientAuthDemo.class.getResource("/test.p12");
    final char[] password = "nopassword".toCharArray();

    final SSLContext serverContext = SSLContextBuilder.create()
            .setKeyStoreType("pkcs12")
            .loadTrustMaterial(keyStoreURL, password)
            .loadKeyMaterial(keyStoreURL, password, password)
            .build();
    final SSLContext clientContext = SSLContextBuilder.create()
            .setKeyStoreType("pkcs12")
            .loadTrustMaterial(keyStoreURL, password)
            .loadKeyMaterial(keyStoreURL, password, password)
            .build();

    final HttpAsyncServer server = AsyncServerBootstrap.bootstrap()
            .setCanonicalHostName("localhost")
            .setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(TIMEOUT).build())
            .setTlsStrategy(new ConscryptServerTlsStrategy(
                    serverContext,
                    (endpoint, sslEngine) -> sslEngine.setNeedClientAuth(true),
                    null))
            .setRequestRouter(RequestRouter.<Supplier<AsyncServerExchangeHandler>>builder()
                    .addRoute(RequestRouter.LOCAL_AUTHORITY, "*", () -> new AsyncEchoStreamingHandler(2048))
                    .resolveAuthority(RequestRouter.LOCAL_AUTHORITY_RESOLVER)
                    .build())
            .create();
    server.start();

    final HttpAsyncRequester client = AsyncRequesterBootstrap.bootstrap()
            .setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(TIMEOUT).build())
            .setTlsStrategy(new ConscryptClientTlsStrategy(clientContext))
            .create();
    client.start();

    try {
        final Future<ListenerEndpoint> future = server.listen(
                new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
        final ListenerEndpoint listener = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
        final int port = ((InetSocketAddress) listener.getAddress()).getPort();

        final HttpHost target = new HttpHost(URIScheme.HTTPS.id,
                InetAddress.getLoopbackAddress(), "localhost", port);

        System.out.println("Connecting with a valid, trusted client certificate to a server "
                + "requiring client auth (setNeedClientAuth=true)...");
        final Message<HttpResponse, String> message = client.execute(
                target,
                new BasicRequestProducer(Method.POST, target, "/stuff",
                        new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null
        ).get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());

        System.out.println("Result: HTTP " + message.head().getCode()
                + " -- expected 200 on master, SSLHandshakeException/CERTIFICATE_UNKNOWN on the PR branch.");
    } finally {
        client.close(CloseMode.IMMEDIATE);
        server.close(CloseMode.IMMEDIATE);
    }
}

}
`

@ok2c

ok2c commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@arturobernalg I thought about it but was sure AlpnTests should have caught it. It looks like I was wrong. I will investigate.

@ok2c
ok2c force-pushed the conscript_endpoint_identification branch from 5e65da8 to e699e78 Compare November 27, 2026 10:31
@ok2c

ok2c commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

@arturobernalg Many thanks for catching the problem. It turned out there had been no integration test coverage for the Conscrypt Provider besides ALPN tests that solely tested the application protocol negotiation aspect of the TLS handshake. I improved our TLS integration tests with 06e863a.

Please do another pass.

@arturobernalg arturobernalg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ok2c nice. thank you. LGTM

@ok2c
ok2c merged commit 57f411a into apache:master Nov 27, 2026
12 checks passed
@ok2c ok2c added this to the 5.5.1 milestone Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants