GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Expose QuicSslContextBuilder::sni (#16178) · netty/netty@881b3fd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-classes-quic/src/main/java/io/netty/handler/codec/quic
    • QuicSslContextBuilder.java
  • codec-native-quic/src/test/java/io/netty/handler/codec/quic
    • QuicChannelConnectTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicSslContextBuilder.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicSslContextBuilder.java
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,27 @@ private QuicSslContextBuilder(boolean forServer) {
179179
this.forServer = forServer;
180180
}
181181

182-
private QuicSslContextBuilder sni(Mapping<? super String, ? extends QuicSslContext> mapping) {
182+
/**
183+
* Enables
184+
* <a href="https://quicwg.org/ops-drafts/draft-ietf-quic-manageability.html#name-server-name-indication-sni">
185+
* SNI</a> support on the server side.
186+
* <p>
187+
* The provided {@link Mapping} receives the hostname from the client and returns the
188+
* {@link QuicSslContext} to use for that connection. The returned context's settings
189+
* (such as {@link #clientAuth(ClientAuth)}, {@link #trustManager(TrustManagerFactory)}, etc.)
190+
* will be applied to the connection.
191+
* <p>
192+
* Use {@link io.netty.util.DomainWildcardMappingBuilder} to create the {@link Mapping} when
193+
* matching against domain patterns is needed.
194+
*
195+
* @param mapping the {@link Mapping} that maps hostnames to {@link QuicSslContext} instances
196+
* @return this builder
197+
* @throws NullPointerException if {@code mapping} is {@code null}
198+
*/
199+
public QuicSslContextBuilder sni(Mapping<? super String, ? extends QuicSslContext> mapping) {
200+
if (!forServer) {
201+
throw new UnsupportedOperationException("Only supported for server");
202+
}
183203
this.mapping = checkNotNull(mapping, "mapping");
184204
return this;
185205
}
Collapse file

‎codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicChannelConnectTest.java‎

Copy file name to clipboardExpand all lines: codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicChannelConnectTest.java
+72Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,78 @@ TestQuicTokenHandler.INSTANCE, new TestHandler(),
15401540
}
15411541
}
15421542

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+
15431615
@ParameterizedTest
15441616
@MethodSource("newSslTaskExecutors")
15451617
public void testConnectKeyless(Executor executor) throws Throwable {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.