Search in sources :

Example 1 with GarlicClove

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();
}
Also used : GarlicClove(net.i2p.data.i2np.GarlicClove)

Example 2 with GarlicClove

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);
}
Also used : DataFormatException(net.i2p.data.DataFormatException) GarlicMessage(net.i2p.data.i2np.GarlicMessage) GarlicClove(net.i2p.data.i2np.GarlicClove)

Example 3 with GarlicClove

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");
    }
}
Also used : PrivateKey(net.i2p.data.PrivateKey) LeaseSetKeys(net.i2p.router.LeaseSetKeys) SessionKeyManager(net.i2p.crypto.SessionKeyManager) GarlicClove(net.i2p.data.i2np.GarlicClove)

Example 4 with GarlicClove

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);
}
Also used : GarlicClove(net.i2p.data.i2np.GarlicClove)

Example 5 with GarlicClove

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;
}
Also used : DataFormatException(net.i2p.data.DataFormatException) GarlicClove(net.i2p.data.i2np.GarlicClove) Certificate(net.i2p.data.Certificate)

Aggregations

GarlicClove (net.i2p.data.i2np.GarlicClove)5 DataFormatException (net.i2p.data.DataFormatException)2 SessionKeyManager (net.i2p.crypto.SessionKeyManager)1 Certificate (net.i2p.data.Certificate)1 PrivateKey (net.i2p.data.PrivateKey)1 GarlicMessage (net.i2p.data.i2np.GarlicMessage)1 LeaseSetKeys (net.i2p.router.LeaseSetKeys)1