Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UNDERTOW-2347] Always specify at least http/1.1 in application_layer_protocol_negotiation ALPN extension when doing TLS #1561

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions core/src/main/java/io/undertow/client/http/HttpClientProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.xnio.ssl.SslConnection;
import org.xnio.ssl.XnioSsl;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.AccessController;
Expand All @@ -52,6 +51,8 @@
*/
public class HttpClientProvider implements ClientProvider {

private static final String HTTP_1_1 = "http/1.1";

public static final String DISABLE_HTTPS_ENDPOINT_IDENTIFICATION_PROPERTY = "io.undertow.client.https.disableEndpointIdentification";
public static final boolean DISABLE_HTTPS_ENDPOINT_IDENTIFICATION;

Expand Down Expand Up @@ -154,6 +155,14 @@ public void handleEvent(StreamConnection connection) {
};
}

public static ALPNClientSelector.ALPNProtocol alpnProtocol(final ClientCallback<ClientConnection> listener, URI uri, ByteBufferPool bufferPool, OptionMap options) {
return new ALPNClientSelector.ALPNProtocol(new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
}, HTTP_1_1);
}

private void handleConnected(final StreamConnection connection, final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, URI uri) {

Expand All @@ -163,7 +172,7 @@ private void handleConnected(final StreamConnection connection, final ClientCall
if(h2) {
protocolList.add(Http2ClientProvider.alpnProtocol(listener, uri, bufferPool, options));
}

protocolList.add(alpnProtocol(listener, uri, bufferPool, options));
ALPNClientSelector.runAlpn((SslConnection) connection, new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
Expand All @@ -172,11 +181,14 @@ public void handleEvent(SslConnection connection) {
}, listener, protocolList.toArray(new ALPNClientSelector.ALPNProtocol[protocolList.size()]));
} else {
if(connection instanceof SslConnection) {
try {
((SslConnection) connection).startHandshake();
} catch (Throwable t) {
listener.failed((t instanceof IOException) ? (IOException) t : new IOException(t));
}
List<ALPNClientSelector.ALPNProtocol> protocolList = new ArrayList<>();
protocolList.add(alpnProtocol(listener, uri, bufferPool, options));
ALPNClientSelector.runAlpn((SslConnection) connection, new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
}, listener, protocolList.toArray(new ALPNClientSelector.ALPNProtocol[protocolList.size()]));
}
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
public class Http2ClientProvider implements ClientProvider {

private static final String HTTP2 = "h2";
private static final String HTTP_1_1 = "http/1.1";

private static final ChannelListener<SslConnection> FAILED = new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
Expand Down
Loading