I2CP: Don't try to decrypt an LS before it's encrypted (ticket #1608)

log tweaks
This commit is contained in:
zzz
2015-06-23 21:16:34 +00:00
parent 975149d049
commit 355b2a1528
4 changed files with 19 additions and 7 deletions

View File

@ -418,10 +418,10 @@ public class LeaseSet extends DatabaseEntry {
encryp(key);
} catch (DataFormatException dfe) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
log.error("Error encrypting lease: " + _destination.calculateHash());
log.error("Error encrypting lease: " + _destination.calculateHash(), dfe);
} catch (IOException ioe) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
log.error("Error encrypting lease: " + _destination.calculateHash());
log.error("Error encrypting lease: " + _destination.calculateHash(), ioe);
}
}
@ -520,7 +520,11 @@ public class LeaseSet extends DatabaseEntry {
private synchronized boolean isEncrypted() {
if (_decrypted)
return true;
if (_checked || _destination == null)
// If the encryption key is not set yet, it can't have been encrypted yet.
// Router-side I2CP sets the destination (but not the encryption key)
// on an unsigned LS which is pending signature (and possibly encryption)
// by the client, and we don't want to attempt 'decryption' on it.
if (_checked || _encryptionKey == null || _destination == null)
return false;
SessionKey key = I2PAppContext.getGlobalContext().keyRing().get(_destination.calculateHash());
if (key != null) {
@ -529,10 +533,10 @@ public class LeaseSet extends DatabaseEntry {
_decrypted = true;
} catch (DataFormatException dfe) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
log.error("Error decrypting lease: " + _destination.calculateHash() + dfe);
log.error("Error decrypting lease: " + _destination.calculateHash(), dfe);
} catch (IOException ioe) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
log.error("Error decrypting lease: " + _destination.calculateHash() + ioe);
log.error("Error decrypting lease: " + _destination.calculateHash(), ioe);
}
}
_checked = true;