forked from I2P_Developers/i2p.i2p
added stat - crypto.garlic.decryptFail
formatting / logging
This commit is contained in:
@ -25,6 +25,7 @@ import net.i2p.router.KeyManager;
|
|||||||
import net.i2p.router.LeaseSetKeys;
|
import net.i2p.router.LeaseSetKeys;
|
||||||
import net.i2p.router.MessageHistory;
|
import net.i2p.router.MessageHistory;
|
||||||
import net.i2p.router.Router;
|
import net.i2p.router.Router;
|
||||||
|
import net.i2p.stat.StatManager;
|
||||||
import net.i2p.util.Clock;
|
import net.i2p.util.Clock;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
@ -42,6 +43,10 @@ public class HandleGarlicMessageJob extends JobImpl {
|
|||||||
private Hash _fromHash;
|
private Hash _fromHash;
|
||||||
private static Map _cloves; // map of clove Id --> Expiration of cloves we've already seen
|
private static Map _cloves; // map of clove Id --> Expiration of cloves we've already seen
|
||||||
|
|
||||||
|
static {
|
||||||
|
StatManager.getInstance().createRateStat("crypto.garlic.decryptFail", "How often garlic messages are undecryptable", "Encryption", new long[] { 5*60*1000, 60*60*1000, 24*60*60*1000 });
|
||||||
|
}
|
||||||
|
|
||||||
private final static int FORWARD_PRIORITY = 50;
|
private final static int FORWARD_PRIORITY = 50;
|
||||||
|
|
||||||
public HandleGarlicMessageJob(GarlicMessage msg, RouterIdentity from, Hash fromHash) {
|
public HandleGarlicMessageJob(GarlicMessage msg, RouterIdentity from, Hash fromHash) {
|
||||||
@ -68,11 +73,13 @@ public class HandleGarlicMessageJob extends JobImpl {
|
|||||||
set = GarlicMessageParser.getInstance().getGarlicCloves(_message, lskeys.getDecryptionKey());
|
set = GarlicMessageParser.getInstance().getGarlicCloves(_message, lskeys.getDecryptionKey());
|
||||||
if (set != null) {
|
if (set != null) {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Decrypted garlic message with lease set key for destination " + lskeys.getDestination().calculateHash().toBase64() + " SUCCEEDED: " + set);
|
_log.debug("Decrypted garlic message with lease set key for destination "
|
||||||
|
+ lskeys.getDestination().calculateHash().toBase64() + " SUCCEEDED: " + set);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Decrypting garlic message with lease set key for destination " + lskeys.getDestination().calculateHash().toBase64() + " failed");
|
_log.debug("Decrypting garlic message with lease set key for destination "
|
||||||
|
+ lskeys.getDestination().calculateHash().toBase64() + " failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -86,8 +93,13 @@ public class HandleGarlicMessageJob extends JobImpl {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
_log.error("CloveMessageParser failed to decrypt the message [" + _message.getUniqueId() + "] to us when received from [" + _fromHash + "] / [" + _from + "]", new Exception("Decrypt garlic failed"));
|
_log.error("CloveMessageParser failed to decrypt the message [" + _message.getUniqueId()
|
||||||
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(), _message.getClass().getName(), "Garlic could not be decrypted");
|
+ "] to us when received from [" + _fromHash + "] / [" + _from + "]",
|
||||||
|
new Exception("Decrypt garlic failed"));
|
||||||
|
StatManager.getInstance().addRateData("crypto.garlic.decryptFail", 1, 0);
|
||||||
|
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(),
|
||||||
|
_message.getClass().getName(),
|
||||||
|
"Garlic could not be decrypted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,23 +133,25 @@ public class HandleGarlicMessageJob extends JobImpl {
|
|||||||
|
|
||||||
private static boolean isValid(GarlicClove clove) {
|
private static boolean isValid(GarlicClove clove) {
|
||||||
if (isKnown(clove.getCloveId())) {
|
if (isKnown(clove.getCloveId())) {
|
||||||
_log.error("Duplicate garlic clove received - replay attack in progress? [cloveId = " +
|
_log.error("Duplicate garlic clove received - replay attack in progress? [cloveId = "
|
||||||
clove.getCloveId() + " expiration = " + clove.getExpiration());
|
+ clove.getCloveId() + " expiration = " + clove.getExpiration());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
_log.debug("Clove " + clove.getCloveId() + " expiring on " + clove.getExpiration() + " is not known");
|
_log.debug("Clove " + clove.getCloveId() + " expiring on " + clove.getExpiration()
|
||||||
|
+ " is not known");
|
||||||
}
|
}
|
||||||
long now = Clock.getInstance().now();
|
long now = Clock.getInstance().now();
|
||||||
if (clove.getExpiration().getTime() < now) {
|
if (clove.getExpiration().getTime() < now) {
|
||||||
if (clove.getExpiration().getTime() < now + Router.CLOCK_FUDGE_FACTOR) {
|
if (clove.getExpiration().getTime() < now + Router.CLOCK_FUDGE_FACTOR) {
|
||||||
_log.warn("Expired garlic received, but within our fudge factor [" + clove.getExpiration() + "]");
|
_log.warn("Expired garlic received, but within our fudge factor ["
|
||||||
|
+ clove.getExpiration() + "]");
|
||||||
} else {
|
} else {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.error("Expired garlic clove received - replay attack in progress? [cloveId = " +
|
_log.error("Expired garlic clove received - replay attack in progress? [cloveId = "
|
||||||
clove.getCloveId() + " expiration = " + clove.getExpiration() + " now = " + (new Date(Clock.getInstance().now())));
|
+ clove.getCloveId() + " expiration = " + clove.getExpiration()
|
||||||
|
+ " now = " + (new Date(Clock.getInstance().now())));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
synchronized (_cloves) {
|
synchronized (_cloves) {
|
||||||
_cloves.put(new Long(clove.getCloveId()), clove.getExpiration());
|
_cloves.put(new Long(clove.getCloveId()), clove.getExpiration());
|
||||||
@ -154,11 +168,15 @@ public class HandleGarlicMessageJob extends JobImpl {
|
|||||||
}
|
}
|
||||||
boolean requestAck = (clove.getSourceRouteBlockAction() == GarlicClove.ACTION_STATUS);
|
boolean requestAck = (clove.getSourceRouteBlockAction() == GarlicClove.ACTION_STATUS);
|
||||||
long sendExpiration = clove.getExpiration().getTime();
|
long sendExpiration = clove.getExpiration().getTime();
|
||||||
MessageHandler.getInstance().handleMessage(clove.getInstructions(), clove.getData(), requestAck, clove.getSourceRouteBlock(),
|
MessageHandler.getInstance().handleMessage(clove.getInstructions(), clove.getData(),
|
||||||
clove.getCloveId(), _from, _fromHash, sendExpiration, FORWARD_PRIORITY);
|
requestAck, clove.getSourceRouteBlock(),
|
||||||
|
clove.getCloveId(), _from, _fromHash,
|
||||||
|
sendExpiration, FORWARD_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropped() {
|
public void dropped() {
|
||||||
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(), _message.getClass().getName(), "Dropped due to overload");
|
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(),
|
||||||
|
_message.getClass().getName(),
|
||||||
|
"Dropped due to overload");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user