forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixes quarkusio#8508] - missing documentation for HTTPS with 2way TL…
…S (aka mutual TLS, aka client cert auth)
- Loading branch information
Showing
6 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/ssl/MtlsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.quarkus.vertx.http.ssl; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.event.Observes; | ||
import javax.net.ssl.SSLPeerUnverifiedException; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.restassured.RestAssured; | ||
import io.vertx.ext.web.Router; | ||
|
||
public class MtlsTest { | ||
|
||
@TestHTTPResource(value = "/mtls", ssl = true) | ||
URL url; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MyBean.class) | ||
.addAsResource(new File("src/test/resources/conf/mtls-jks.conf"), "application.properties") | ||
.addAsResource(new File("src/test/resources/conf/server-keystore.jks"), "server-keystore.jks") | ||
.addAsResource(new File("src/test/resources/conf/server-truststore.jks"), "server-truststore.jks")); | ||
|
||
@Test | ||
public void testSslServerWithJKS() { | ||
RestAssured.given() | ||
.keyStore(new File("src/test/resources/conf/client-keystore.jks"), "password") | ||
.trustStore(new File("src/test/resources/conf/client-truststore.jks"), "password") | ||
.get(url).then().statusCode(200).body(is("CN=client,OU=cert,O=quarkus,L=city,ST=state,C=AU")); | ||
} | ||
|
||
@ApplicationScoped | ||
static class MyBean { | ||
|
||
public void register(@Observes Router router) { | ||
router.get("/mtls").handler(rc -> { | ||
Assertions.assertThat(rc.request().connection().isSsl()).isTrue(); | ||
Assertions.assertThat(rc.request().isSSL()).isTrue(); | ||
Assertions.assertThat(rc.request().connection().sslSession()).isNotNull(); | ||
try { | ||
rc.response().end(rc.request().connection().sslSession().getPeerPrincipal().getName()); | ||
} catch (SSLPeerUnverifiedException cause) { | ||
throw new RuntimeException("Failed to obtain peer principal", cause); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
} |
Binary file added
BIN
+2.16 KB
extensions/vertx-http/deployment/src/test/resources/conf/client-keystore.jks
Binary file not shown.
Binary file added
BIN
+1.63 KB
extensions/vertx-http/deployment/src/test/resources/conf/client-truststore.jks
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
extensions/vertx-http/deployment/src/test/resources/conf/mtls-jks.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
quarkus.http.ssl.certificate.key-store-file=server-keystore.jks | ||
quarkus.http.ssl.certificate.key-store-password=secret | ||
quarkus.http.ssl.certificate.trust-store-file=server-truststore.jks | ||
quarkus.http.ssl.certificate.trust-store-password=password | ||
quarkus.http.ssl.client-auth=REQUIRED |
Binary file added
BIN
+925 Bytes
extensions/vertx-http/deployment/src/test/resources/conf/server-truststore.jks
Binary file not shown.