Search in sources :

Example 16 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class Socks5PasswordAuthResponseDecoder method fail.

private void fail(List<Object> out, Exception cause) {
    if (!(cause instanceof DecoderException)) {
        cause = new DecoderException(cause);
    }
    checkpoint(State.FAILURE);
    Socks5Message m = new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE);
    m.setDecoderResult(DecoderResult.failure(cause));
    out.add(m);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException)

Example 17 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class Socks5InitialRequestDecoder method fail.

private void fail(List<Object> out, Exception cause) {
    if (!(cause instanceof DecoderException)) {
        cause = new DecoderException(cause);
    }
    checkpoint(State.FAILURE);
    Socks5Message m = new DefaultSocks5InitialRequest(Socks5AuthMethod.NO_AUTH);
    m.setDecoderResult(DecoderResult.failure(cause));
    out.add(m);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException)

Example 18 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class Socks5InitialResponseDecoder method fail.

private void fail(List<Object> out, Exception cause) {
    if (!(cause instanceof DecoderException)) {
        cause = new DecoderException(cause);
    }
    checkpoint(State.FAILURE);
    Socks5Message m = new DefaultSocks5InitialResponse(Socks5AuthMethod.UNACCEPTED);
    m.setDecoderResult(DecoderResult.failure(cause));
    out.add(m);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException)

Example 19 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class SocketSslClientRenegotiateTest method testSslRenegotiationRejected.

public void testSslRenegotiationRejected(ServerBootstrap sb, Bootstrap cb, final SslContext serverCtx, final SslContext clientCtx, boolean delegate) throws Throwable {
    reset();
    final ExecutorService executorService = delegate ? Executors.newCachedThreadPool() : null;
    try {
        sb.childHandler(new ChannelInitializer<Channel>() {

            @Override
            @SuppressWarnings("deprecation")
            public void initChannel(Channel sch) throws Exception {
                serverChannel = sch;
                serverSslHandler = newSslHandler(serverCtx, sch.alloc(), executorService);
                // As we test renegotiation we should use a protocol that support it.
                serverSslHandler.engine().setEnabledProtocols(new String[] { "TLSv1.2" });
                sch.pipeline().addLast("ssl", serverSslHandler);
                sch.pipeline().addLast("handler", serverHandler);
            }
        });
        cb.handler(new ChannelInitializer<Channel>() {

            @Override
            @SuppressWarnings("deprecation")
            public void initChannel(Channel sch) throws Exception {
                clientChannel = sch;
                clientSslHandler = newSslHandler(clientCtx, sch.alloc(), executorService);
                // As we test renegotiation we should use a protocol that support it.
                clientSslHandler.engine().setEnabledProtocols(new String[] { "TLSv1.2" });
                sch.pipeline().addLast("ssl", clientSslHandler);
                sch.pipeline().addLast("handler", clientHandler);
            }
        });
        Channel sc = sb.bind().sync().channel();
        cb.connect(sc.localAddress()).sync();
        Future<Channel> clientHandshakeFuture = clientSslHandler.handshakeFuture();
        clientHandshakeFuture.sync();
        String renegotiation = clientSslHandler.engine().getEnabledCipherSuites()[0];
        // Use the first previous enabled ciphersuite and try to renegotiate.
        clientSslHandler.engine().setEnabledCipherSuites(new String[] { renegotiation });
        clientSslHandler.renegotiate().await();
        serverChannel.close().awaitUninterruptibly();
        clientChannel.close().awaitUninterruptibly();
        sc.close().awaitUninterruptibly();
        try {
            if (serverException.get() != null) {
                throw serverException.get();
            }
            fail();
        } catch (DecoderException e) {
            assertTrue(e.getCause() instanceof SSLHandshakeException);
        }
        if (clientException.get() != null) {
            throw clientException.get();
        }
    } finally {
        if (executorService != null) {
            executorService.shutdown();
        }
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) Channel(io.netty.channel.Channel) ExecutorService(java.util.concurrent.ExecutorService) DecoderException(io.netty.handler.codec.DecoderException) ClosedChannelException(java.nio.channels.ClosedChannelException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) CertificateException(java.security.cert.CertificateException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 20 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class SniHandlerTest method testNonSslRecord.

@ParameterizedTest(name = "{index}: sslProvider={0}")
@MethodSource("data")
public void testNonSslRecord(SslProvider provider) throws Exception {
    SslContext nettyContext = makeSslContext(provider, false);
    try {
        final AtomicReference<SslHandshakeCompletionEvent> evtRef = new AtomicReference<SslHandshakeCompletionEvent>();
        SniHandler handler = new SniHandler(new DomainNameMappingBuilder<SslContext>(nettyContext).build());
        final EmbeddedChannel ch = new EmbeddedChannel(handler, new ChannelInboundHandlerAdapter() {

            @Override
            public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
                if (evt instanceof SslHandshakeCompletionEvent) {
                    assertTrue(evtRef.compareAndSet(null, (SslHandshakeCompletionEvent) evt));
                }
            }
        });
        try {
            final byte[] bytes = new byte[1024];
            bytes[0] = SslUtils.SSL_CONTENT_TYPE_ALERT;
            DecoderException e = assertThrows(DecoderException.class, new Executable() {

                @Override
                public void execute() throws Throwable {
                    ch.writeInbound(Unpooled.wrappedBuffer(bytes));
                }
            });
            assertThat(e.getCause(), CoreMatchers.instanceOf(NotSslRecordException.class));
            assertFalse(ch.finish());
        } finally {
            ch.finishAndReleaseAll();
        }
        assertThat(evtRef.get().cause(), CoreMatchers.instanceOf(NotSslRecordException.class));
    } finally {
        releaseAll(nettyContext);
    }
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) AtomicReference(java.util.concurrent.atomic.AtomicReference) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) DecoderException(io.netty.handler.codec.DecoderException) SSLException(javax.net.ssl.SSLException) DecoderException(io.netty.handler.codec.DecoderException) Executable(org.junit.jupiter.api.function.Executable) DomainNameMappingBuilder(io.netty.util.DomainNameMappingBuilder) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

DecoderException (io.netty.handler.codec.DecoderException)46 ByteBuf (io.netty.buffer.ByteBuf)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 ClosedChannelException (java.nio.channels.ClosedChannelException)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 Test (org.junit.jupiter.api.Test)3 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)2 DomainNameMappingBuilder (io.netty.util.DomainNameMappingBuilder)2 IOException (java.io.IOException)2 SSLException (javax.net.ssl.SSLException)2 Test (org.junit.Test)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 ApiError (com.nike.backstopper.apierror.ApiError)1 ApiErrorWithMetadata (com.nike.backstopper.apierror.ApiErrorWithMetadata)1 CircuitBreakerException (com.nike.fastbreak.exception.CircuitBreakerException)1 Pair (com.nike.internal.util.Pair)1