forked from I2P_Developers/i2p.i2p
Further simplified I2P repliable datagram format: they now contain
senderPubDest + S(H(payload)) + payload (human)
This commit is contained in:
@ -59,20 +59,20 @@ public final class I2PDatagramDissector {
|
|||||||
*/
|
*/
|
||||||
public void loadI2PDatagram(byte[] dgram) throws DataFormatException {
|
public void loadI2PDatagram(byte[] dgram) throws DataFormatException {
|
||||||
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
|
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
|
||||||
byte[] hashedData;
|
byte[] rxTrimmedPayload;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
rxDest.readBytes(dgStream);
|
||||||
|
|
||||||
rxSign.readBytes(dgStream);
|
rxSign.readBytes(dgStream);
|
||||||
|
|
||||||
rxDest.readBytes(dgStream);
|
|
||||||
rxPayloadLen = dgStream.read(rxPayload);
|
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];
|
rxHashBytes =hashGen.calculateHash(rxTrimmedPayload).toByteArray();
|
||||||
System.arraycopy(dgram, Signature.SIGNATURE_BYTES,
|
|
||||||
hashedData, 0,
|
|
||||||
hashedData.length);
|
|
||||||
rxHashBytes = hashGen.calculateHash(hashedData).toByteArray();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
_log.error("Caught IOException - INCONSISTENT STATE!", e);
|
_log.error("Caught IOException - INCONSISTENT STATE!", e);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ public final class I2PDatagramMaker {
|
|||||||
private SigningPrivateKey sxPrivKey = null;
|
private SigningPrivateKey sxPrivKey = null;
|
||||||
private byte[] sxDestBytes = null;
|
private byte[] sxDestBytes = null;
|
||||||
|
|
||||||
private ByteArrayOutputStream sxBuf = new ByteArrayOutputStream(DGRAM_BUFSIZE);
|
|
||||||
private ByteArrayOutputStream sxDGram = 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.
|
* @param payload Bytes to be contained in the I2P datagram.
|
||||||
*/
|
*/
|
||||||
public byte[] makeI2PDatagram(byte[] payload) {
|
public byte[] makeI2PDatagram(byte[] payload) {
|
||||||
byte[] hashedData;
|
|
||||||
|
|
||||||
sxBuf.reset();
|
|
||||||
sxDGram.reset();
|
sxDGram.reset();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sxBuf.write(sxDestBytes);
|
sxDGram.write(sxDestBytes);
|
||||||
sxBuf.write(payload);
|
|
||||||
|
dsaEng.sign(hashGen.calculateHash(payload).toByteArray(),
|
||||||
hashedData = sxBuf.toByteArray();
|
|
||||||
|
|
||||||
dsaEng.sign(hashGen.calculateHash(hashedData).toByteArray(),
|
|
||||||
sxPrivKey).writeBytes(sxDGram);
|
sxPrivKey).writeBytes(sxDGram);
|
||||||
|
|
||||||
sxDGram.write(hashedData);
|
sxDGram.write(payload);
|
||||||
|
|
||||||
return sxDGram.toByteArray();
|
return sxDGram.toByteArray();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
_log.error("Caught IOException", e);
|
_log.error("Caught IOException", e);
|
||||||
|
Reference in New Issue
Block a user