diff --git a/src/main/java/cc/agentx/wrapper/RandomPaddingWrapper.java b/src/main/java/cc/agentx/wrapper/RandomPaddingWrapper.java index 96da777..09adf98 100644 --- a/src/main/java/cc/agentx/wrapper/RandomPaddingWrapper.java +++ b/src/main/java/cc/agentx/wrapper/RandomPaddingWrapper.java @@ -37,7 +37,7 @@ public byte[] wrap(byte[] bytes) { int randomLength = KeyHelper.generateRandomInteger( Math.max(paddingThreshold, bytes.length) , paddingThreshold + paddingRange - ) + 1; + ) + headerLength; byte[] wrapBytes = KeyHelper.generateRandomBytes(randomLength); byte[] headerBytes = KeyHelper.getBytes(headerLength, randomLength - bytes.length); System.arraycopy(bytes, 0, wrapBytes, wrapBytes.length - bytes.length, bytes.length); @@ -45,8 +45,8 @@ public byte[] wrap(byte[] bytes) { return wrapBytes; } else { byte[] wrapBytes = KeyHelper.generateRandomBytes(headerLength + bytes.length); - System.arraycopy(bytes, 0, wrapBytes, 1, bytes.length); - System.arraycopy(KeyHelper.getBytes(headerLength, 1), 0, wrapBytes, 0, headerLength); + System.arraycopy(bytes, 0, wrapBytes, headerLength, bytes.length); + System.arraycopy(KeyHelper.getBytes(headerLength, headerLength), 0, wrapBytes, 0, headerLength); return wrapBytes; } } diff --git a/src/main/java/cc/agentx/wrapper/WrapperFactory.java b/src/main/java/cc/agentx/wrapper/WrapperFactory.java index f18a9ae..c86f9bf 100644 --- a/src/main/java/cc/agentx/wrapper/WrapperFactory.java +++ b/src/main/java/cc/agentx/wrapper/WrapperFactory.java @@ -36,6 +36,12 @@ public static Wrapper getInstance(cc.agentx.server.Configuration config, String return getInstance(config.getEncryption(), config.getPassword(), id); } + /** + * Notice: + * The frame-based processes below cannot be configured simultaneously in this version of implementation + *

+ * compress, zero-padding, random-padding + */ public static Wrapper getInstance(String encryption, String password, String id) throws Exception { switch (id) { case "raw": @@ -83,9 +89,9 @@ public static Wrapper getInstance(String encryption, String password, String id) case "compress": return new FrameWrapper(262144, new CompressWrapper()); case "zero-padding": - return new FrameWrapper(262144, new ZeroPaddingWrapper(500, 500)); + return new FrameWrapper(262144, new ZeroPaddingWrapper(200, 56)); case "random-padding": - return new FrameWrapper(262144, new RandomPaddingWrapper(500, 500)); + return new FrameWrapper(262144, new RandomPaddingWrapper(200, 56)); default: throw new Exception("unknown process function"); } diff --git a/src/main/java/cc/agentx/wrapper/ZeroPaddingWrapper.java b/src/main/java/cc/agentx/wrapper/ZeroPaddingWrapper.java index f9dc772..6c60338 100644 --- a/src/main/java/cc/agentx/wrapper/ZeroPaddingWrapper.java +++ b/src/main/java/cc/agentx/wrapper/ZeroPaddingWrapper.java @@ -41,7 +41,7 @@ public byte[] wrap(byte[] bytes) { int randomLength = KeyHelper.generateRandomInteger( Math.max(paddingThreshold, bytes.length) , paddingThreshold + paddingRange - ) + 1; + ) + headerLength; byte[] wrapBytes = new byte[randomLength]; byte[] headerBytes = KeyHelper.getBytes(headerLength, randomLength - bytes.length); System.arraycopy(bytes, 0, wrapBytes, wrapBytes.length - bytes.length, bytes.length); @@ -49,8 +49,8 @@ public byte[] wrap(byte[] bytes) { return wrapBytes; } else { byte[] wrapBytes = new byte[headerLength + bytes.length]; - System.arraycopy(bytes, 0, wrapBytes, 1, bytes.length); - System.arraycopy(KeyHelper.getBytes(headerLength, 1), 0, wrapBytes, 0, headerLength); + System.arraycopy(bytes, 0, wrapBytes, headerLength, bytes.length); + System.arraycopy(KeyHelper.getBytes(headerLength, headerLength), 0, wrapBytes, 0, headerLength); return wrapBytes; } }