Native cryptography support using mbed TLS

This commit is contained in:
Andrew Steinborn
2018-08-04 23:46:41 -04:00
parent 06a6493605
commit 8aa1fe524e
11 changed files with 252 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ public class MinecraftCipherDecoder extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
ByteBuf decrypted = ctx.alloc().buffer();
ByteBuf decrypted = ctx.alloc().buffer(in.readableBytes());
try {
cipher.process(in, decrypted);
out.add(decrypted);

View File

@@ -18,6 +18,11 @@ public class MinecraftCipherEncoder extends MessageToByteEncoder<ByteBuf> {
cipher.process(msg, out);
}
@Override
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception {
return ctx.alloc().directBuffer(msg.readableBytes());
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
cipher.dispose();