@@ -1540,6 +1540,78 @@ TestQuicTokenHandler.INSTANCE, new TestHandler(), |
1540 | 1540 | } |
1541 | 1541 | } |
1542 | 1542 |
|
| 1543 | + @ParameterizedTest |
| 1544 | + @MethodSource("newSslTaskExecutors") |
| 1545 | + public void testSniWithClientAuth(Executor executor) throws Throwable { |
| 1546 | + String hostname = "quic.netty.io"; |
| 1547 | + |
| 1548 | + QuicSslContext sniServerSslContext = QuicSslContextBuilder.forServer( |
| 1549 | + QuicTestUtils.SELF_SIGNED_CERTIFICATE.privateKey(), null, |
| 1550 | + QuicTestUtils.SELF_SIGNED_CERTIFICATE.certificate()) |
| 1551 | + .trustManager(InsecureTrustManagerFactory.INSTANCE) |
| 1552 | + .clientAuth(ClientAuth.REQUIRE) |
| 1553 | + .applicationProtocols(QuicTestUtils.PROTOS).build(); |
| 1554 | + |
| 1555 | + QuicSslContext serverSslContext = QuicSslContextBuilder.forServer( |
| 1556 | + QuicTestUtils.SELF_SIGNED_CERTIFICATE.privateKey(), null, |
| 1557 | + QuicTestUtils.SELF_SIGNED_CERTIFICATE.certificate()) |
| 1558 | + .sni(new DomainWildcardMappingBuilder<>(sniServerSslContext) |
| 1559 | + .add(hostname, sniServerSslContext).build()) |
| 1560 | + .applicationProtocols(QuicTestUtils.PROTOS).build(); |
| 1561 | + |
| 1562 | + CountDownLatch sniEventLatch = new CountDownLatch(1); |
| 1563 | + CountDownLatch sslEventLatch = new CountDownLatch(1); |
| 1564 | + Channel server = QuicTestUtils.newServer(QuicTestUtils.newQuicServerBuilder(executor, serverSslContext), |
| 1565 | + TestQuicTokenHandler.INSTANCE, new ChannelInboundHandlerAdapter() { |
| 1566 | + @Override |
| 1567 | + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { |
| 1568 | + if (evt instanceof SniCompletionEvent) { |
| 1569 | + if (hostname.equals(((SniCompletionEvent) evt).hostname())) { |
| 1570 | + sniEventLatch.countDown(); |
| 1571 | + } |
| 1572 | + } else if (evt instanceof SslHandshakeCompletionEvent) { |
| 1573 | + if (((SslHandshakeCompletionEvent) evt).isSuccess()) { |
| 1574 | + sslEventLatch.countDown(); |
| 1575 | + } |
| 1576 | + } |
| 1577 | + super.userEventTriggered(ctx, evt); |
| 1578 | + } |
| 1579 | + }, |
| 1580 | + new ChannelInboundHandlerAdapter()); |
| 1581 | + |
| 1582 | + InetSocketAddress address = (InetSocketAddress) server.localAddress(); |
| 1583 | + |
| 1584 | + QuicSslContext clientSslContext = QuicSslContextBuilder.forClient() |
| 1585 | + .trustManager(InsecureTrustManagerFactory.INSTANCE) |
| 1586 | + .keyManager(QuicTestUtils.SELF_SIGNED_CERTIFICATE.privateKey(), null, |
| 1587 | + QuicTestUtils.SELF_SIGNED_CERTIFICATE.certificate()) |
| 1588 | + .applicationProtocols(QuicTestUtils.PROTOS).build(); |
| 1589 | + |
| 1590 | + Channel channel = QuicTestUtils.newClient(QuicTestUtils.newQuicClientBuilder(executor) |
| 1591 | + .sslEngineProvider(c -> clientSslContext.newEngine(c.alloc(), hostname, 8080))); |
| 1592 | + try { |
| 1593 | + ChannelActiveVerifyHandler clientQuicChannelHandler = new ChannelActiveVerifyHandler(); |
| 1594 | + QuicChannel quicChannel = QuicTestUtils.newQuicChannelBootstrap(channel) |
| 1595 | + .handler(clientQuicChannelHandler) |
| 1596 | + .streamHandler(new ChannelInboundHandlerAdapter()) |
| 1597 | + .remoteAddress(address) |
| 1598 | + .connect() |
| 1599 | + .get(); |
| 1600 | + |
| 1601 | + quicChannel.close().sync(); |
| 1602 | + ChannelFuture closeFuture = quicChannel.closeFuture().await(); |
| 1603 | + assertTrue(closeFuture.isSuccess()); |
| 1604 | + clientQuicChannelHandler.assertState(); |
| 1605 | + sniEventLatch.await(); |
| 1606 | + sslEventLatch.await(); |
| 1607 | + } finally { |
| 1608 | + server.close().sync(); |
| 1609 | + channel.close().sync(); |
| 1610 | + |
| 1611 | + shutdown(executor); |
| 1612 | + } |
| 1613 | + } |
| 1614 | + |
1543 | 1615 | @ParameterizedTest |
1544 | 1616 | @MethodSource("newSslTaskExecutors") |
1545 | 1617 | public void testConnectKeyless(Executor executor) throws Throwable { |
|