Skip to content

Commit f66af2e

Browse files
committed
fix: disable HTTP/2 clear text when quarkus.http.http2 is false
Signed-off-by: Michael Edgar <[email protected]>
1 parent bef486d commit f66af2e

File tree

3 files changed

+112
-10
lines changed

3 files changed

+112
-10
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package io.quarkus.vertx.http.http2;
2+
3+
import java.io.File;
4+
import java.net.URL;
5+
import java.util.concurrent.CompletableFuture;
6+
import java.util.concurrent.ExecutionException;
7+
8+
import jakarta.enterprise.context.ApplicationScoped;
9+
import jakarta.enterprise.event.Observes;
10+
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.extension.RegisterExtension;
14+
15+
import io.quarkus.test.QuarkusUnitTest;
16+
import io.quarkus.test.common.http.TestHTTPResource;
17+
import io.quarkus.vertx.core.runtime.VertxCoreRecorder;
18+
import io.smallrye.certs.Format;
19+
import io.smallrye.certs.junit5.Certificate;
20+
import io.smallrye.certs.junit5.Certificates;
21+
import io.vertx.core.buffer.Buffer;
22+
import io.vertx.core.http.HttpVersion;
23+
import io.vertx.core.net.JksOptions;
24+
import io.vertx.ext.web.Router;
25+
import io.vertx.ext.web.client.HttpResponse;
26+
import io.vertx.ext.web.client.WebClient;
27+
import io.vertx.ext.web.client.WebClientOptions;
28+
29+
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "ssl-test", password = "secret", formats = {
30+
Format.JKS, Format.PKCS12, Format.PEM }))
31+
class Http2DisabledTest {
32+
33+
protected static final String PING_DATA = "12345678";
34+
35+
@TestHTTPResource(value = "/ping", tls = true)
36+
URL sslUrl;
37+
38+
@TestHTTPResource(value = "/ping")
39+
URL plainUrl;
40+
41+
@RegisterExtension
42+
static final QuarkusUnitTest config = new QuarkusUnitTest()
43+
.withApplicationRoot(jar -> jar
44+
.addClasses(MyBean.class)
45+
.addAsResource(new File("target/certs/ssl-test-keystore.jks"), "server-keystore.jks"))
46+
.overrideConfigKey("quarkus.http.ssl.certificate.key-store-file", "server-keystore.jks")
47+
.overrideConfigKey("quarkus.http.ssl.certificate.key-store-password", "secret")
48+
.overrideConfigKey("quarkus.http.http2", "false");
49+
50+
@Test
51+
void testHttp2EnabledSsl() throws ExecutionException, InterruptedException {
52+
WebClientOptions options = new WebClientOptions()
53+
.setUseAlpn(true)
54+
.setProtocolVersion(HttpVersion.HTTP_2)
55+
.setSsl(true)
56+
.setTrustOptions(new JksOptions().setPath("target/certs/ssl-test-truststore.jks").setPassword("secret"));
57+
WebClient client = WebClient.create(VertxCoreRecorder.getVertx().get(), options);
58+
int port = sslUrl.getPort();
59+
60+
runTest(client, port);
61+
}
62+
63+
@Test
64+
void testHttp2EnabledPlain() throws ExecutionException, InterruptedException {
65+
WebClientOptions options = new WebClientOptions()
66+
.setProtocolVersion(HttpVersion.HTTP_2)
67+
.setHttp2ClearTextUpgrade(true);
68+
WebClient client = WebClient.create(VertxCoreRecorder.getVertx().get(), options);
69+
runTest(client, plainUrl.getPort());
70+
}
71+
72+
private void runTest(WebClient client, int port) throws InterruptedException, ExecutionException {
73+
CompletableFuture<HttpResponse<Buffer>> result = new CompletableFuture<>();
74+
75+
client
76+
.get(port, "localhost", "/ping")
77+
.send(ar -> {
78+
if (ar.succeeded()) {
79+
result.complete(ar.result());
80+
} else {
81+
result.completeExceptionally(ar.cause());
82+
}
83+
});
84+
85+
HttpResponse<Buffer> response = result.get();
86+
Assertions.assertNotEquals(HttpVersion.HTTP_2, response.version());
87+
Assertions.assertEquals(PING_DATA, response.bodyAsString());
88+
}
89+
90+
@ApplicationScoped
91+
static class MyBean {
92+
public void register(@Observes Router router) {
93+
router.get("/ping").handler(rc -> {
94+
rc.response().end(PING_DATA);
95+
});
96+
}
97+
}
98+
}

extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/http2/Http2Test.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@
3030

3131
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "ssl-test", password = "secret", formats = {
3232
Format.JKS, Format.PKCS12, Format.PEM }))
33-
public class Http2Test {
33+
class Http2Test {
3434

3535
protected static final String PING_DATA = "12345678";
3636

37-
@TestHTTPResource(value = "/ping", ssl = true)
37+
@TestHTTPResource(value = "/ping", tls = true)
3838
URL sslUrl;
3939

4040
@TestHTTPResource(value = "/ping")
4141
URL plainUrl;
4242

4343
@RegisterExtension
4444
static final QuarkusUnitTest config = new QuarkusUnitTest()
45-
.withApplicationRoot((jar) -> jar
45+
.withApplicationRoot(jar -> jar
4646
.addClasses(MyBean.class)
4747
.addAsResource(new File("target/certs/ssl-test-keystore.jks"), "server-keystore.jks"))
4848
.overrideConfigKey("quarkus.http.ssl.certificate.key-store-file", "server-keystore.jks")
4949
.overrideConfigKey("quarkus.http.ssl.certificate.key-store-password", "secret");
5050

5151
@Test
52-
public void testHttp2EnabledSsl() throws ExecutionException, InterruptedException {
52+
void testHttp2EnabledSsl() throws ExecutionException, InterruptedException {
5353
WebClientOptions options = new WebClientOptions()
5454
.setUseAlpn(true)
5555
.setProtocolVersion(HttpVersion.HTTP_2)
@@ -62,7 +62,7 @@ public void testHttp2EnabledSsl() throws ExecutionException, InterruptedExceptio
6262
}
6363

6464
@Test
65-
public void testHttp2EnabledPlain() throws ExecutionException, InterruptedException {
65+
void testHttp2EnabledPlain() throws ExecutionException, InterruptedException {
6666
WebClientOptions options = new WebClientOptions()
6767
.setProtocolVersion(HttpVersion.HTTP_2)
6868
.setHttp2ClearTextUpgrade(true);
@@ -71,19 +71,22 @@ public void testHttp2EnabledPlain() throws ExecutionException, InterruptedExcept
7171
}
7272

7373
private void runTest(WebClient client, int port) throws InterruptedException, ExecutionException {
74-
CompletableFuture<String> result = new CompletableFuture<>();
74+
CompletableFuture<HttpResponse<Buffer>> result = new CompletableFuture<>();
75+
7576
client
7677
.get(port, "localhost", "/ping")
7778
.send(ar -> {
7879
if (ar.succeeded()) {
7980
// Obtain response
80-
HttpResponse<Buffer> response = ar.result();
81-
result.complete(response.bodyAsString());
81+
result.complete(ar.result());
8282
} else {
8383
result.completeExceptionally(ar.cause());
8484
}
8585
});
86-
Assertions.assertEquals(PING_DATA, result.get());
86+
87+
HttpResponse<Buffer> response = result.get();
88+
Assertions.assertEquals(HttpVersion.HTTP_2, response.version());
89+
Assertions.assertEquals(PING_DATA, response.bodyAsString());
8790
}
8891

8992
@ApplicationScoped

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/options/HttpServerOptionsUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ public static void applyCommonOptions(
368368
(int) httpConfig.limits().rstFloodWindowDuration().get().toSeconds());
369369
httpServerOptions.setHttp2RstFloodWindowDurationTimeUnit(TimeUnit.SECONDS);
370370
}
371-
371+
} else {
372+
httpServerOptions.setHttp2ClearTextEnabled(false);
372373
}
373374

374375
httpServerOptions.setUseProxyProtocol(httpConfig.proxy().useProxyProtocol());

0 commit comments

Comments
 (0)