use of net.i2p.data.i2np.GarlicClove in project i2p.i2p by i2p.
the class CloveSet method toString.
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("{");
for (int i = 0; i < _cloves.length; i++) {
GarlicClove clove = _cloves[i];
if (clove.getData() != null)
buf.append(clove.getData().getClass().getName()).append(", ");
else
buf.append("[null clove], ");
}
buf.append("}");
return buf.toString();
}
use of net.i2p.data.i2np.GarlicClove in project i2p.i2p by i2p.
the class GarlicMessageBuilder method buildClove.
/**
* UNUSED
*
* The Garlic Message we are building contains another garlic message,
* as specified by a GarlicConfig (NOT a PayloadGarlicConfig).
*
* So this calls back to the top, to buildMessage(ctx, config),
* which uses the router's SKM, i.e. the wrong one.
* Unfortunately we've lost the reference to the SessionKeyManager way down here,
* so we can't call buildMessage(ctx, config, key, tags, skm).
*
* If we do ever end up constructing a garlic message that contains a garlic message,
* we'll have to fix this by passing the skm through the last buildMessage,
* through buildCloveSet, to here.
*/
private static byte[] buildClove(RouterContext ctx, GarlicConfig config) throws DataFormatException, IOException {
GarlicClove clove = new GarlicClove(ctx);
GarlicMessage msg = buildMessage(ctx, config);
if (msg == null)
throw new DataFormatException("Unable to build message from clove config");
clove.setData(msg);
return buildCommonClove(clove, config);
}
use of net.i2p.data.i2np.GarlicClove in project i2p.i2p by i2p.
the class GarlicMessageReceiver method receive.
public void receive(GarlicMessage message) {
PrivateKey decryptionKey;
SessionKeyManager skm;
if (_clientDestination != null) {
LeaseSetKeys keys = _context.keyManager().getKeys(_clientDestination);
skm = _context.clientManager().getClientSessionKeyManager(_clientDestination);
if (keys != null && skm != null) {
decryptionKey = keys.getDecryptionKey();
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("Not trying to decrypt a garlic routed message to a disconnected client");
return;
}
} else {
decryptionKey = _context.keyManager().getPrivateKey();
skm = _context.sessionKeyManager();
}
CloveSet set = _context.garlicMessageParser().getGarlicCloves(message, decryptionKey, skm);
if (set != null) {
for (int i = 0; i < set.getCloveCount(); i++) {
GarlicClove clove = set.getClove(i);
handleClove(clove);
}
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("CloveMessageParser failed to decrypt the message [" + message.getUniqueId() + "]", new Exception("Decrypt garlic failed"));
_context.statManager().addRateData("crypto.garlic.decryptFail", 1);
_context.messageHistory().messageProcessingError(message.getUniqueId(), message.getClass().getName(), "Garlic could not be decrypted");
}
}
use of net.i2p.data.i2np.GarlicClove in project i2p.i2p by i2p.
the class GarlicMessageBuilder method buildClove.
private static byte[] buildClove(RouterContext ctx, PayloadGarlicConfig config) throws DataFormatException, IOException {
GarlicClove clove = new GarlicClove(ctx);
clove.setData(config.getPayload());
return buildCommonClove(clove, config);
}
use of net.i2p.data.i2np.GarlicClove in project i2p.i2p by i2p.
the class GarlicMessageParser method readCloveSet.
private CloveSet readCloveSet(byte[] data) throws DataFormatException {
int offset = 0;
int numCloves = data[offset] & 0xff;
offset++;
if (_log.shouldLog(Log.DEBUG))
_log.debug("# cloves to read: " + numCloves);
if (numCloves <= 0 || numCloves > MAX_CLOVES)
throw new DataFormatException("bad clove count " + numCloves);
GarlicClove[] cloves = new GarlicClove[numCloves];
for (int i = 0; i < numCloves; i++) {
// if (_log.shouldLog(Log.DEBUG))
// _log.debug("Reading clove " + i);
GarlicClove clove = new GarlicClove(_context);
offset += clove.readBytes(data, offset);
cloves[i] = clove;
// if (_log.shouldLog(Log.DEBUG))
// _log.debug("After reading clove " + i);
}
// Certificate cert = new Certificate();
// offset += cert.readBytes(data, offset);
Certificate cert = Certificate.create(data, offset);
offset += cert.size();
long msgId = DataHelper.fromLong(data, offset, 4);
offset += 4;
// Date expiration = DataHelper.fromDate(data, offset);
long expiration = DataHelper.fromLong(data, offset, 8);
CloveSet set = new CloveSet(cloves, cert, msgId, expiration);
return set;
}
Aggregations