diff --git a/core/java/src/net/i2p/client/datagram/I2PDatagramDissector.java b/core/java/src/net/i2p/client/datagram/I2PDatagramDissector.java index eb1e0af46b62981516419b6e01e750619076ffac..ae5e31c1d1270f50ba64598f92d379932ef20efa 100644 --- a/core/java/src/net/i2p/client/datagram/I2PDatagramDissector.java +++ b/core/java/src/net/i2p/client/datagram/I2PDatagramDissector.java @@ -59,20 +59,20 @@ public final class I2PDatagramDissector { */ public void loadI2PDatagram(byte[] dgram) throws DataFormatException { ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram); - byte[] hashedData; - + byte[] rxTrimmedPayload; try { + rxDest.readBytes(dgStream); + rxSign.readBytes(dgStream); - rxDest.readBytes(dgStream); rxPayloadLen = dgStream.read(rxPayload); + + // FIXME: hashGen.calculateHash(source, offset, len) would rock... + rxTrimmedPayload = new byte[rxPayloadLen]; + System.arraycopy(rxPayload, 0, rxTrimmedPayload, 0, rxPayloadLen); - hashedData = new byte[dgram.length - Signature.SIGNATURE_BYTES]; - System.arraycopy(dgram, Signature.SIGNATURE_BYTES, - hashedData, 0, - hashedData.length); - rxHashBytes = hashGen.calculateHash(hashedData).toByteArray(); + rxHashBytes =hashGen.calculateHash(rxTrimmedPayload).toByteArray(); } catch (IOException e) { _log.error("Caught IOException - INCONSISTENT STATE!", e); } diff --git a/core/java/src/net/i2p/client/datagram/I2PDatagramMaker.java b/core/java/src/net/i2p/client/datagram/I2PDatagramMaker.java index 600397948d129511e5c0825c360cce5696dce437..669818ac78f0f13cb9a87027c01317b56ab12dce 100644 --- a/core/java/src/net/i2p/client/datagram/I2PDatagramMaker.java +++ b/core/java/src/net/i2p/client/datagram/I2PDatagramMaker.java @@ -36,7 +36,6 @@ public final class I2PDatagramMaker { private SigningPrivateKey sxPrivKey = null; private byte[] sxDestBytes = null; - private ByteArrayOutputStream sxBuf = new ByteArrayOutputStream(DGRAM_BUFSIZE); private ByteArrayOutputStream sxDGram = new ByteArrayOutputStream(DGRAM_BUFSIZE); /** @@ -56,22 +55,16 @@ public final class I2PDatagramMaker { * @param payload Bytes to be contained in the I2P datagram. */ public byte[] makeI2PDatagram(byte[] payload) { - byte[] hashedData; - - sxBuf.reset(); sxDGram.reset(); try { - sxBuf.write(sxDestBytes); - sxBuf.write(payload); - - hashedData = sxBuf.toByteArray(); - - dsaEng.sign(hashGen.calculateHash(hashedData).toByteArray(), + sxDGram.write(sxDestBytes); + + dsaEng.sign(hashGen.calculateHash(payload).toByteArray(), sxPrivKey).writeBytes(sxDGram); - sxDGram.write(hashedData); - + sxDGram.write(payload); + return sxDGram.toByteArray(); } catch (IOException e) { _log.error("Caught IOException", e);