Home / Function/ testAlertProducedAndSend() — netty Function Reference

testAlertProducedAndSend() — netty Function Reference

Architecture documentation for the testAlertProducedAndSend() function in ParameterizedSslHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  92d0ae6e_cc71_8410_b3eb_18399def41e7["testAlertProducedAndSend()"]
  4741a6a1_c002_17c2_c8d8_747d98eb437c["ParameterizedSslHandlerTest"]
  92d0ae6e_cc71_8410_b3eb_18399def41e7 -->|defined in| 4741a6a1_c002_17c2_c8d8_747d98eb437c
  8012c2ef_ec06_9bdf_064e_3c1e7ba7f4b8["exceptionCaught()"]
  92d0ae6e_cc71_8410_b3eb_18399def41e7 -->|calls| 8012c2ef_ec06_9bdf_064e_3c1e7ba7f4b8
  style 92d0ae6e_cc71_8410_b3eb_18399def41e7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java lines 276–374

    @ParameterizedTest(name = PARAMETERIZED_NAME)
    @MethodSource("data")
    @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
    public void testAlertProducedAndSend(SslProvider clientProvider, SslProvider serverProvider) throws Exception {
        SelfSignedCertificate ssc = CachedSelfSignedCertificate.getCachedCertificate();

        final SslContext sslServerCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
                .sslProvider(serverProvider)
                .trustManager(new SimpleTrustManagerFactory() {
                    @Override
                    protected void engineInit(KeyStore keyStore) { }
                    @Override
                    protected void engineInit(ManagerFactoryParameters managerFactoryParameters) { }

                    @Override
                    protected TrustManager[] engineGetTrustManagers() {
                        return new TrustManager[] { new X509TrustManager() {

                            @Override
                            public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
                                    throws CertificateException {
                                // Fail verification which should produce an alert that is send back to the client.
                                throw new CertificateException();
                            }

                            @Override
                            public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
                                // NOOP
                            }

                            @Override
                            public X509Certificate[] getAcceptedIssuers() {
                                return EmptyArrays.EMPTY_X509_CERTIFICATES;
                            }
                        } };
                    }
                }).clientAuth(ClientAuth.REQUIRE).build();

        final SslContext sslClientCtx = SslContextBuilder.forClient()
                .trustManager(InsecureTrustManagerFactory.INSTANCE)
                .keyManager(ResourcesUtil.getFile(getClass(),  "test.crt"),
                        ResourcesUtil.getFile(getClass(), "test_unencrypted.pem"))
                .sslProvider(clientProvider).build();

        EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
        Channel sc = null;
        Channel cc = null;
        try {
            final Promise<Void> promise = group.next().newPromise();
            sc = new ServerBootstrap()
                    .group(group)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ChannelInitializer<Channel>() {
                        @Override
                        protected void initChannel(Channel ch) throws Exception {
                            ch.pipeline().addLast(sslServerCtx.newHandler(ch.alloc()));
                            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                                @Override
                                public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
                                    // Just trigger a close
                                    ctx.close();
                                }
                            });
                        }
                    }).bind(new InetSocketAddress(0)).syncUninterruptibly().channel();

            cc = new Bootstrap()
                    .group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<Channel>() {
                        @Override
                        protected void initChannel(Channel ch) throws Exception {
                            ch.pipeline().addLast(sslClientCtx.newHandler(ch.alloc()));
                            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                                @Override
                                public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
                                    if (cause.getCause() instanceof SSLException) {
                                        // We received the alert and so produce an SSLException.
                                        promise.trySuccess(null);
                                    }
                                }

Domain

Subdomains

Frequently Asked Questions

What does testAlertProducedAndSend() do?
testAlertProducedAndSend() is a function in the netty codebase, defined in handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java.
Where is testAlertProducedAndSend() defined?
testAlertProducedAndSend() is defined in handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java at line 276.
What does testAlertProducedAndSend() call?
testAlertProducedAndSend() calls 1 function(s): exceptionCaught.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free