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);
}
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);
}
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);
}
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();
}
}
}
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);
}
}
Aggregations