Search in sources :

Example 66 with StringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project flink by apache.

the class NettyClientServerSslTest method testSslHandshakeError.

/**
 * Verify SSL handshake error when untrusted server certificate is used.
 */
@Test
public void testSslHandshakeError() throws Exception {
    NettyProtocol protocol = new NoOpProtocol();
    Configuration config = createSslConfig();
    // Use a server certificate which is not present in the truststore
    config.setString(SecurityOptions.SSL_INTERNAL_KEYSTORE, "src/test/resources/untrusted.keystore");
    NettyTestUtil.NettyServerAndClient serverAndClient;
    try (NetUtils.Port port = NetUtils.getAvailablePort()) {
        NettyConfig nettyConfig = createNettyConfig(config, port);
        serverAndClient = NettyTestUtil.initServerAndClient(protocol, nettyConfig);
    }
    Assert.assertNotNull("serverAndClient is null due to fail to get a free port", serverAndClient);
    Channel ch = NettyTestUtil.connect(serverAndClient);
    ch.pipeline().addLast(new StringDecoder()).addLast(new StringEncoder());
    // Attempting to write data over ssl should fail
    assertFalse(ch.writeAndFlush("test").await().isSuccess());
    NettyTestUtil.shutdown(serverAndClient);
}
Also used : StringEncoder(org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringEncoder) NetUtils(org.apache.flink.util.NetUtils) Configuration(org.apache.flink.configuration.Configuration) NettyServerAndClient(org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient) SocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.SocketChannel) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) StringDecoder(org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder) Test(org.junit.Test) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest)

Example 67 with StringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project flink by apache.

the class NettyClientServerSslTest method testClientUntrustedCertificate.

@Test
public void testClientUntrustedCertificate() throws Exception {
    final Configuration serverConfig = createSslConfig();
    final Configuration clientConfig = createSslConfig();
    // give the client a different keystore / certificate
    clientConfig.setString(SecurityOptions.SSL_INTERNAL_KEYSTORE, "src/test/resources/untrusted.keystore");
    NettyServerAndClient serverAndClient;
    try (NetUtils.Port serverPort = NetUtils.getAvailablePort();
        NetUtils.Port clientPort = NetUtils.getAvailablePort()) {
        final NettyConfig nettyServerConfig = createNettyConfig(serverConfig, serverPort);
        final NettyConfig nettyClientConfig = createNettyConfig(clientConfig, clientPort);
        final NettyBufferPool bufferPool = new NettyBufferPool(1);
        final NettyProtocol protocol = new NoOpProtocol();
        final NettyServer server = NettyTestUtil.initServer(nettyServerConfig, protocol, bufferPool);
        final NettyClient client = NettyTestUtil.initClient(nettyClientConfig, protocol, bufferPool);
        serverAndClient = new NettyServerAndClient(server, client);
    }
    Assert.assertNotNull("serverAndClient is null due to fail to get a free port", serverAndClient);
    final Channel ch = NettyTestUtil.connect(serverAndClient);
    ch.pipeline().addLast(new StringDecoder()).addLast(new StringEncoder());
    // Attempting to write data over ssl should fail
    assertFalse(ch.writeAndFlush("test").await().isSuccess());
    NettyTestUtil.shutdown(serverAndClient);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) SocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.SocketChannel) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) StringDecoder(org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder) StringEncoder(org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringEncoder) NetUtils(org.apache.flink.util.NetUtils) NettyServerAndClient(org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient) Test(org.junit.Test) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest)

Example 68 with StringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project apollo by apollo-rsps.

the class JagGrabChannelInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(MAX_REQUEST_LENGTH, DOUBLE_LINE_FEED_DELIMITER));
    pipeline.addLast("string-decoder", new StringDecoder(JAGGRAB_CHARSET));
    pipeline.addLast("jaggrab-decoder", new JagGrabRequestDecoder());
    pipeline.addLast("jaggrab-encoder", new JagGrabResponseEncoder());
    pipeline.addLast("timeout", new IdleStateHandler(NetworkConstants.IDLE_TIME, 0, 0));
    pipeline.addLast("handler", handler);
}
Also used : JagGrabResponseEncoder(org.apollo.net.codec.jaggrab.JagGrabResponseEncoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) DelimiterBasedFrameDecoder(io.netty.handler.codec.DelimiterBasedFrameDecoder) StringDecoder(io.netty.handler.codec.string.StringDecoder) JagGrabRequestDecoder(org.apollo.net.codec.jaggrab.JagGrabRequestDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

StringDecoder (io.netty.handler.codec.string.StringDecoder)63 StringEncoder (io.netty.handler.codec.string.StringEncoder)42 ChannelPipeline (io.netty.channel.ChannelPipeline)35 SocketChannel (io.netty.channel.socket.SocketChannel)27 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)21 ChannelFuture (io.netty.channel.ChannelFuture)18 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)16 DelimiterBasedFrameDecoder (io.netty.handler.codec.DelimiterBasedFrameDecoder)16 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)15 Bootstrap (io.netty.bootstrap.Bootstrap)14 EventLoopGroup (io.netty.channel.EventLoopGroup)14 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)14 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)13 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)12 Channel (io.netty.channel.Channel)11 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)11 LoggingHandler (io.netty.handler.logging.LoggingHandler)8 ChannelHandler (io.netty.channel.ChannelHandler)6 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)6 Test (org.junit.Test)6