Search in sources :

Example 1 with RemovableSingletonSet

use of net.i2p.router.util.RemovableSingletonSet in project i2p.i2p by i2p.

the class TestJob method sendTest.

private void sendTest(I2NPMessage m) {
    // garlic route that DeliveryStatusMessage to ourselves so the endpoints and gateways
    // can't tell its a test.  to simplify this, we encrypt it with a random key and tag,
    // remembering that key+tag so that we can decrypt it later.  this means we can do the
    // garlic encryption without any ElGamal (yay)
    PayloadGarlicConfig payload = new PayloadGarlicConfig();
    payload.setCertificate(Certificate.NULL_CERT);
    payload.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
    payload.setPayload(m);
    payload.setRecipient(getContext().router().getRouterInfo());
    payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    payload.setExpiration(m.getMessageExpiration());
    SessionKey encryptKey = getContext().keyGenerator().generateSessionKey();
    SessionTag encryptTag = new SessionTag(true);
    _encryptTag = encryptTag;
    SessionKey sentKey = new SessionKey();
    Set<SessionTag> sentTags = null;
    GarlicMessage msg = GarlicMessageBuilder.buildMessage(getContext(), payload, sentKey, sentTags, getContext().keyManager().getPublicKey(), encryptKey, encryptTag);
    if (msg == null) {
        // overloaded / unknown peers / etc
        scheduleRetest();
        return;
    }
    Set<SessionTag> encryptTags = new RemovableSingletonSet<SessionTag>(encryptTag);
    // Register the single tag with the appropriate SKM
    if (_cfg.isInbound() && !_pool.getSettings().isExploratory()) {
        SessionKeyManager skm = getContext().clientManager().getClientSessionKeyManager(_pool.getSettings().getDestination());
        if (skm != null)
            skm.tagsReceived(encryptKey, encryptTags);
    } else {
        getContext().sessionKeyManager().tagsReceived(encryptKey, encryptTags);
    }
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Sending garlic test of " + _outTunnel + " / " + _replyTunnel);
    getContext().tunnelDispatcher().dispatchOutbound(msg, _outTunnel.getSendTunnelId(0), _replyTunnel.getReceiveTunnelId(0), _replyTunnel.getPeer(0));
}
Also used : PayloadGarlicConfig(net.i2p.router.message.PayloadGarlicConfig) SessionKey(net.i2p.data.SessionKey) RemovableSingletonSet(net.i2p.router.util.RemovableSingletonSet) GarlicMessage(net.i2p.data.i2np.GarlicMessage) SessionKeyManager(net.i2p.crypto.SessionKeyManager) SessionTag(net.i2p.data.SessionTag)

Example 2 with RemovableSingletonSet

use of net.i2p.router.util.RemovableSingletonSet in project i2p.i2p by i2p.

the class MessageWrapper method generateSession.

/**
 *  Create a single key and tag, for receiving a single encrypted message,
 *  and register it with the given session key manager, to expire in two minutes.
 *  The recipient can then send us an AES-encrypted message,
 *  avoiding ElGamal.
 *
 *  @return non-null
 *  @since 0.9.9
 */
public static OneTimeSession generateSession(RouterContext ctx, SessionKeyManager skm) {
    SessionKey key = ctx.keyGenerator().generateSessionKey();
    SessionTag tag = new SessionTag(true);
    Set<SessionTag> tags = new RemovableSingletonSet<SessionTag>(tag);
    skm.tagsReceived(key, tags, 2 * 60 * 1000);
    return new OneTimeSession(key, tag);
}
Also used : SessionKey(net.i2p.data.SessionKey) RemovableSingletonSet(net.i2p.router.util.RemovableSingletonSet) SessionTag(net.i2p.data.SessionTag)

Aggregations

SessionKey (net.i2p.data.SessionKey)2 SessionTag (net.i2p.data.SessionTag)2 RemovableSingletonSet (net.i2p.router.util.RemovableSingletonSet)2 SessionKeyManager (net.i2p.crypto.SessionKeyManager)1 GarlicMessage (net.i2p.data.i2np.GarlicMessage)1 PayloadGarlicConfig (net.i2p.router.message.PayloadGarlicConfig)1