minor optimization in I2PDatagramDissector(only verfy signature once)
This commit is contained in:
@ -43,6 +43,8 @@ public final class I2PDatagramDissector {
|
|||||||
|
|
||||||
private int rxPayloadLen = 0;
|
private int rxPayloadLen = 0;
|
||||||
|
|
||||||
|
private boolean valid = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crate a new I2P repliable datagram dissector.
|
* Crate a new I2P repliable datagram dissector.
|
||||||
*/
|
*/
|
||||||
@ -89,10 +91,7 @@ public final class I2PDatagramDissector {
|
|||||||
* @throws I2PInvalidDatagramException if the signature verification fails
|
* @throws I2PInvalidDatagramException if the signature verification fails
|
||||||
*/
|
*/
|
||||||
public byte[] getPayload() throws I2PInvalidDatagramException {
|
public byte[] getPayload() throws I2PInvalidDatagramException {
|
||||||
if (!dsaEng.verifySignature(rxSign, rxHashBytes,
|
this.verifySignature();
|
||||||
rxDest.getSigningPublicKey())) {
|
|
||||||
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] retPayload = new byte[rxPayloadLen];
|
byte[] retPayload = new byte[rxPayloadLen];
|
||||||
System.arraycopy(rxPayload, 0, retPayload, 0, rxPayloadLen);
|
System.arraycopy(rxPayload, 0, retPayload, 0, rxPayloadLen);
|
||||||
@ -109,10 +108,7 @@ public final class I2PDatagramDissector {
|
|||||||
* @throws I2PInvalidDatagramException if the signature verification fails
|
* @throws I2PInvalidDatagramException if the signature verification fails
|
||||||
*/
|
*/
|
||||||
public Destination getSender() throws I2PInvalidDatagramException {
|
public Destination getSender() throws I2PInvalidDatagramException {
|
||||||
if (!dsaEng.verifySignature(rxSign, rxHashBytes,
|
this.verifySignature();
|
||||||
rxDest.getSigningPublicKey())) {
|
|
||||||
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");
|
|
||||||
}
|
|
||||||
|
|
||||||
Destination retDest = new Destination();
|
Destination retDest = new Destination();
|
||||||
try {
|
try {
|
||||||
@ -156,4 +152,21 @@ public final class I2PDatagramDissector {
|
|||||||
|
|
||||||
return retDest;
|
return retDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the signature of this datagram (previously loaded with the
|
||||||
|
* loadI2PDatagram() method)
|
||||||
|
*/
|
||||||
|
public void verifySignature() throws I2PInvalidDatagramException {
|
||||||
|
// first check if it already got validated
|
||||||
|
if(this.valid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// now validate
|
||||||
|
if (!dsaEng.verifySignature(rxSign, rxHashBytes, rxDest.getSigningPublicKey()))
|
||||||
|
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");
|
||||||
|
|
||||||
|
// set validated
|
||||||
|
this.valid = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user