* Datagram Dissector: Fix RuntimeException caused by reuse,

preventing iMule from connecting on UDP
                          (thanks devzero)
This commit is contained in:
zzz
2010-12-31 13:16:46 +00:00
parent 1b74b49e0f
commit a64d0a54b1

View File

@ -37,9 +37,9 @@ public final class I2PDatagramDissector {
private Hash rxHash = null; private Hash rxHash = null;
private Signature rxSign = new Signature(); private Signature rxSign;
private Destination rxDest = new Destination(); private Destination rxDest;
private byte[] rxPayload = new byte[DGRAM_BUFSIZE]; private byte[] rxPayload = new byte[DGRAM_BUFSIZE];
@ -68,6 +68,9 @@ public final class I2PDatagramDissector {
this.valid = false; this.valid = false;
try { try {
rxDest = new Destination();
rxSign = new Signature();
// read destination // read destination
rxDest.readBytes(dgStream); rxDest.readBytes(dgStream);
@ -153,6 +156,8 @@ public final class I2PDatagramDissector {
* @return The Destination of the I2P repliable datagram sender * @return The Destination of the I2P repliable datagram sender
*/ */
public Destination extractSender() { public Destination extractSender() {
if (this.rxDest == null)
return null;
Destination retDest = new Destination(); Destination retDest = new Destination();
try { try {
retDest.fromByteArray(this.rxDest.toByteArray()); retDest.fromByteArray(this.rxDest.toByteArray());
@ -184,6 +189,10 @@ public final class I2PDatagramDissector {
if(this.valid) if(this.valid)
return; return;
if (rxSign == null || rxSign.getData() == null ||
rxDest == null || rxDest.getSigningPublicKey() == null)
throw new I2PInvalidDatagramException("Datagram not yet read");
// now validate // now validate
if (!this.dsaEng.verifySignature(rxSign, rxHash.getData(), rxDest.getSigningPublicKey())) if (!this.dsaEng.verifySignature(rxSign, rxHash.getData(), rxDest.getSigningPublicKey()))
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature"); throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");