Search in sources :

Example 26 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class GarlicMessageBuilder method buildMessage.

/**
 * called by netdb and above
 *
 * @param ctx scope
 * @param config how/what to wrap
 * @param wrappedKey output parameter that will be filled with the sessionKey used
 * @param wrappedTags Output parameter that will be filled with the sessionTags used.
 *                          If non-empty on return you must call skm.tagsDelivered() when sent
 *                          and then call skm.tagsAcked() or skm.failTags() later.
 * @param numTagsToDeliver only if the estimated available tags are below the threshold.
 *                               Set to zero to disable tag delivery. You must set to zero if you are not
 *                               equipped to confirm delivery and call skm.tagsAcked() or failTags() later.
 *                               If this is always 0, it forces ElGamal every time.
 * @param lowTagsThreshold the threshold
 * @param skm non-null
 * @throws IllegalArgumentException on error
 */
public static GarlicMessage buildMessage(RouterContext ctx, GarlicConfig config, SessionKey wrappedKey, Set<SessionTag> wrappedTags, int numTagsToDeliver, int lowTagsThreshold, SessionKeyManager skm) {
    Log log = ctx.logManager().getLog(GarlicMessageBuilder.class);
    PublicKey key = config.getRecipientPublicKey();
    if (key == null) {
        if (config.getRecipient() == null) {
            throw new IllegalArgumentException("Null recipient specified");
        } else if (config.getRecipient().getIdentity() == null) {
            throw new IllegalArgumentException("Null recipient.identity specified");
        } else if (config.getRecipient().getIdentity().getPublicKey() == null) {
            throw new IllegalArgumentException("Null recipient.identity.publicKey specified");
        } else
            key = config.getRecipient().getIdentity().getPublicKey();
    }
    if (log.shouldLog(Log.INFO))
        log.info("Encrypted with public key to expire on " + new Date(config.getExpiration()));
    SessionKey curKey = skm.getCurrentOrNewKey(key);
    SessionTag curTag = null;
    curTag = skm.consumeNextAvailableTag(key, curKey);
    if (log.shouldLog(Log.DEBUG)) {
        int availTags = skm.getAvailableTags(key, curKey);
        log.debug("Available tags for encryption: " + availTags + " low threshold: " + lowTagsThreshold);
    }
    if (numTagsToDeliver > 0 && skm.shouldSendTags(key, curKey, lowTagsThreshold)) {
        for (int i = 0; i < numTagsToDeliver; i++) wrappedTags.add(new SessionTag(true));
        if (log.shouldLog(Log.INFO))
            log.info("Too few tags available so we're including " + numTagsToDeliver);
    }
    wrappedKey.setData(curKey.getData());
    return buildMessage(ctx, config, wrappedKey, wrappedTags, key, curKey, curTag);
}
Also used : Log(net.i2p.util.Log) PublicKey(net.i2p.data.PublicKey) SessionKey(net.i2p.data.SessionKey) SessionTag(net.i2p.data.SessionTag) Date(java.util.Date)

Example 27 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class GarlicMessageBuilder method buildMessage.

/**
 *  used by TestJob and directly above
 *  and for encrypting DatabaseLookupMessages
 *
 * @param ctx scope
 * @param config how/what to wrap
 * @param wrappedKey unused - why??
 * @param wrappedTags New tags to be sent along with the message.
 *                    200 max enforced at receiver; null OK
 * @param target public key of the location being garlic routed to (may be null if we
 *               know the encryptKey and encryptTag)
 * @param encryptKey sessionKey used to encrypt the current message, non-null
 * @param encryptTag sessionTag used to encrypt the current message, null to force ElG
 * @throws IllegalArgumentException on error
 */
public static GarlicMessage buildMessage(RouterContext ctx, GarlicConfig config, SessionKey wrappedKey, Set<SessionTag> wrappedTags, PublicKey target, SessionKey encryptKey, SessionTag encryptTag) {
    Log log = ctx.logManager().getLog(GarlicMessageBuilder.class);
    if (config == null)
        throw new IllegalArgumentException("Null config specified");
    GarlicMessage msg = new GarlicMessage(ctx);
    // noteWrap(ctx, msg, config);
    byte[] cloveSet = buildCloveSet(ctx, config);
    // TODO - 128 is the minimum padded size - should it be more? less? random?
    byte[] encData = ctx.elGamalAESEngine().encrypt(cloveSet, target, encryptKey, wrappedTags, encryptTag, 128);
    msg.setData(encData);
    msg.setMessageExpiration(config.getExpiration());
    long timeFromNow = config.getExpiration() - ctx.clock().now();
    if (timeFromNow < 1 * 1000) {
        if (log.shouldLog(Log.DEBUG))
            log.debug("Building a message expiring in " + timeFromNow + "ms: " + config, new Exception("created by"));
        return null;
    }
    if (log.shouldLog(Log.DEBUG))
        log.debug("CloveSet (" + config.getCloveCount() + " cloves) for message " + msg.getUniqueId() + " is " + cloveSet.length + " bytes and encrypted message data is " + encData.length + " bytes");
    return msg;
}
Also used : Log(net.i2p.util.Log) GarlicMessage(net.i2p.data.i2np.GarlicMessage) DataFormatException(net.i2p.data.DataFormatException) IOException(java.io.IOException)

Example 28 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class OutboundClientMessageJobHelper method buildAckClove.

/**
 *  Build a clove that sends a DeliveryStatusMessage to us.
 *  As of 0.9.12, the DSM is wrapped in a GarlicMessage.
 *  @param skm encrypt dsm with this skm non-null
 *  @return null on error
 */
private static PayloadGarlicConfig buildAckClove(RouterContext ctx, Hash from, TunnelInfo replyToTunnel, long replyToken, long expiration, SessionKeyManager skm) {
    Log log = ctx.logManager().getLog(OutboundClientMessageJobHelper.class);
    if (replyToTunnel == null) {
        if (log.shouldLog(Log.WARN))
            log.warn("Unable to send client message from " + from.toBase64() + ", as there are no inbound tunnels available");
        return null;
    }
    // tunnel id on that gateway
    TunnelId replyToTunnelId = replyToTunnel.getReceiveTunnelId(0);
    // inbound tunnel gateway
    Hash replyToTunnelRouter = replyToTunnel.getPeer(0);
    if (log.shouldLog(Log.DEBUG))
        log.debug("Ack for the data message will come back along tunnel " + replyToTunnelId + ": " + replyToTunnel);
    DeliveryInstructions ackInstructions = new DeliveryInstructions();
    ackInstructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
    ackInstructions.setRouter(replyToTunnelRouter);
    ackInstructions.setTunnelId(replyToTunnelId);
    // defaults
    // ackInstructions.setDelayRequested(false);
    // ackInstructions.setDelaySeconds(0);
    // ackInstructions.setEncrypted(false);
    PayloadGarlicConfig ackClove = new PayloadGarlicConfig();
    ackClove.setCertificate(Certificate.NULL_CERT);
    ackClove.setDeliveryInstructions(ackInstructions);
    ackClove.setExpiration(expiration);
    ackClove.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    DeliveryStatusMessage dsm = buildDSM(ctx, replyToken);
    GarlicMessage msg = wrapDSM(ctx, skm, dsm);
    if (msg == null) {
        if (log.shouldLog(Log.WARN))
            log.warn("Failed to wrap ack clove");
        return null;
    }
    ackClove.setPayload(msg);
    return ackClove;
}
Also used : DeliveryInstructions(net.i2p.data.i2np.DeliveryInstructions) Log(net.i2p.util.Log) GarlicMessage(net.i2p.data.i2np.GarlicMessage) Hash(net.i2p.data.Hash) TunnelId(net.i2p.data.TunnelId) DeliveryStatusMessage(net.i2p.data.i2np.DeliveryStatusMessage)

Example 29 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class OutboundClientMessageJobHelper method createGarlicConfig.

/**
 * Make the top-level config, with a data clove, an optional ack clove, and
 * an optional leaseset clove.
 *
 * @param dataClove non-null
 * @param replyTunnel non-null if requireAck is true or bundledReplyLeaseSet is non-null
 * @param requireAck if true, bundle replyToken in an ack clove
 * @param bundledReplyLeaseSet may be null; if non-null, put it in a clove
 * @param skm encrypt dsm with this skm non-null
 * @return null on error
 */
private static GarlicConfig createGarlicConfig(RouterContext ctx, long replyToken, long expiration, PublicKey recipientPK, PayloadGarlicConfig dataClove, Hash from, Destination dest, TunnelInfo replyTunnel, boolean requireAck, LeaseSet bundledReplyLeaseSet, SessionKeyManager skm) {
    Log log = ctx.logManager().getLog(OutboundClientMessageJobHelper.class);
    if (replyToken >= 0 && log.shouldLog(Log.DEBUG))
        log.debug("Reply token: " + replyToken);
    GarlicConfig config = new GarlicConfig();
    if (requireAck) {
        // extend the expiration of the return message
        PayloadGarlicConfig ackClove = buildAckClove(ctx, from, replyTunnel, replyToken, expiration + ACK_EXTRA_EXPIRATION, skm);
        if (ackClove == null)
            // no tunnels... TODO carry on anyway?
            return null;
        config.addClove(ackClove);
    }
    if (bundledReplyLeaseSet != null) {
        PayloadGarlicConfig leaseSetClove = buildLeaseSetClove(ctx, expiration, bundledReplyLeaseSet);
        config.addClove(leaseSetClove);
    }
    // As of 0.9.2, since the receiver processes them in-order,
    // put data clove last to speed up the ack,
    // and get the leaseset stored before handling the data
    config.addClove(dataClove);
    config.setCertificate(Certificate.NULL_CERT);
    config.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    config.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    // +2*Router.CLOCK_FUDGE_FACTOR);
    config.setExpiration(expiration);
    config.setRecipientPublicKey(recipientPK);
    if (log.shouldLog(Log.INFO))
        log.info("Creating garlic config to be encrypted to " + recipientPK + " for destination " + dest.calculateHash().toBase64());
    return config;
}
Also used : Log(net.i2p.util.Log)

Example 30 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class UDPPacket method verifyNotReleased.

private synchronized void verifyNotReleased() {
    if (!CACHE)
        return;
    if (_released) {
        Log log = _context.logManager().getLog(UDPPacket.class);
        log.error("Already released", new Exception());
    // log.log(Log.CRIT, "Released by: ", _releasedBy);
    // log.log(Log.CRIT, "Acquired by: ", _acquiredBy);
    }
}
Also used : Log(net.i2p.util.Log)

Aggregations

Log (net.i2p.util.Log)94 IOException (java.io.IOException)30 File (java.io.File)13 Properties (java.util.Properties)11 DataFormatException (net.i2p.data.DataFormatException)11 FileInputStream (java.io.FileInputStream)7 GeneralSecurityException (java.security.GeneralSecurityException)7 ArrayList (java.util.ArrayList)7 Hash (net.i2p.data.Hash)6 HashMap (java.util.HashMap)5 InputStream (java.io.InputStream)4 EventLog (net.i2p.router.util.EventLog)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 I2PAppContext (net.i2p.I2PAppContext)3 I2PSession (net.i2p.client.I2PSession)3 I2PSessionException (net.i2p.client.I2PSessionException)3 SigType (net.i2p.crypto.SigType)3 RouterInfo (net.i2p.data.router.RouterInfo)3