/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }
/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }
/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }
new SaslEncryption.EncryptedMessage(backend, msg, 1024); long count = emsg.transferTo(channel, emsg.transfered()); assertTrue(count < data.length);
new SaslEncryption.EncryptedMessage(backend, msg, 1024); long count = emsg.transferTo(channel, emsg.transfered()); assertTrue(count < data.length);
@Test public void testEncryptedMessageChunking() throws Exception { File file = File.createTempFile("sasltest", ".txt"); try { TransportConf conf = new TransportConf("shuffle", MapConfigProvider.EMPTY); byte[] data = new byte[8 * 1024]; new Random().nextBytes(data); Files.write(data, file); SaslEncryptionBackend backend = mock(SaslEncryptionBackend.class); // It doesn't really matter what we return here, as long as it's not null. when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data); FileSegmentManagedBuffer msg = new FileSegmentManagedBuffer(conf, file, 0, file.length()); SaslEncryption.EncryptedMessage emsg = new SaslEncryption.EncryptedMessage(backend, msg.convertToNetty(), data.length / 8); ByteArrayWritableChannel channel = new ByteArrayWritableChannel(data.length); while (emsg.transfered() < emsg.count()) { channel.reset(); emsg.transferTo(channel, emsg.transfered()); } verify(backend, times(8)).wrap(any(byte[].class), anyInt(), anyInt()); } finally { file.delete(); } }
@Test public void testEncryptedMessageChunking() throws Exception { File file = File.createTempFile("sasltest", ".txt"); try { TransportConf conf = new TransportConf("shuffle", MapConfigProvider.EMPTY); byte[] data = new byte[8 * 1024]; new Random().nextBytes(data); Files.write(data, file); SaslEncryptionBackend backend = mock(SaslEncryptionBackend.class); // It doesn't really matter what we return here, as long as it's not null. when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data); FileSegmentManagedBuffer msg = new FileSegmentManagedBuffer(conf, file, 0, file.length()); SaslEncryption.EncryptedMessage emsg = new SaslEncryption.EncryptedMessage(backend, msg.convertToNetty(), data.length / 8); ByteArrayWritableChannel channel = new ByteArrayWritableChannel(data.length); while (emsg.transfered() < emsg.count()) { channel.reset(); emsg.transferTo(channel, emsg.transfered()); } verify(backend, times(8)).wrap(any(byte[].class), anyInt(), anyInt()); } finally { file.delete(); } }
/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }