net.i2p.router.networkdb.kademlia

## Class MessageWrapper

- java.lang.Object
- - net.i2p.router.networkdb.kademlia.MessageWrapper

-     public class MessageWrapper
      extends Object

  Method and class for garlic encrypting outbound netdb traffic, and sending keys and tags for others to encrypt inbound netdb traffic, including management of the ElGamal/AES tags.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MessageWrapper.OneTimeSession` A single key and tag, for receiving a single message.
    `(package private) static class` | `MessageWrapper.WrappedMessage` Wrapper so that we can keep track of the key and tags for later notification to the SKM

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MessageWrapper()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static MessageWrapper.OneTimeSession` | `generateSession(RouterContext ctx, Hash localDest, long expiration, boolean forceElG)` Create a single key and tag, for receiving a single encrypted message, and register it with the client's session key manager, to expire in the time specified.
    `static MessageWrapper.OneTimeSession` | `generateSession(RouterContext ctx, long expiration)` Create a single key and tag, for receiving a single encrypted message, and register it with our router's session key manager, to expire in the time specified.
    `static MessageWrapper.OneTimeSession` | `generateSession(RouterContext ctx, SessionKeyManager skm, long expiration, boolean forceElG)` Create a single key and tag, for receiving a single encrypted message, and register it with the client's session key manager, to expire in the time specified.
    `(package private) static MessageWrapper.WrappedMessage` | `wrap(RouterContext ctx, I2NPMessage m, Hash from, RouterInfo to)` Garlic wrap a message from a client or this router, destined for a router, to hide the contents from the OBEP.
    `static GarlicMessage` | `wrap(RouterContext ctx, I2NPMessage m, MessageWrapper.OneTimeSession session)` Garlic wrap a message from nobody, destined for an unknown router, to hide the contents from the IBGW.
    `static GarlicMessage` | `wrap(RouterContext ctx, I2NPMessage m, RouterInfo to)` Garlic wrap a message from nobody, destined for a router, to hide the contents from the OBEP.
    `static GarlicMessage` | `wrap(RouterContext ctx, I2NPMessage m, SessionKey encryptKey, RatchetSessionTag encryptTag)` Garlic wrap a message from nobody, destined for an unknown router, to hide the contents from the IBGW.
    `static GarlicMessage` | `wrap(RouterContext ctx, I2NPMessage m, SessionKey encryptKey, SessionTag encryptTag)` Garlic wrap a message from nobody, destined for an unknown router, to hide the contents from the IBGW.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MessageWrapper

          public MessageWrapper()

  - ### Method Detail

    - #### generateSession

          public static MessageWrapper.OneTimeSession generateSession(RouterContext ctx,
                                                                      Hash localDest,
                                                                      long expiration,
                                                                      boolean forceElG)

      Create a single key and tag, for receiving a single encrypted message, and register it with the client's session key manager, to expire in the time specified. The recipient can then send us an AES- or ChaCha- encrypted message, avoiding full ElGamal or ECIES.
      Parameters:
        `expiration` - time from now
      Returns:
        null if we can't find the SKM for the localDest

    - #### generateSession

          public static MessageWrapper.OneTimeSession generateSession(RouterContext ctx,
                                                                      long expiration)

      Create a single key and tag, for receiving a single encrypted message, and register it with our router's session key manager, to expire in the time specified. The recipient can then send us an AES- or ChaCha- encrypted message, avoiding full ElGamal or ECIES.
      Parameters:
        `expiration` - time from now

    - #### generateSession

          public static MessageWrapper.OneTimeSession generateSession(RouterContext ctx,
                                                                      SessionKeyManager skm,
                                                                      long expiration,
                                                                      boolean forceElG)

      Create a single key and tag, for receiving a single encrypted message, and register it with the client's session key manager, to expire in the time specified. The recipient can then send us an AES- or ChaCha- encrypted message, avoiding full ElGamal or ECIES.
      Parameters:
        `expiration` - time from now
      Returns:
        non-null

    - #### wrap

          static MessageWrapper.WrappedMessage wrap(RouterContext ctx,
                                                    I2NPMessage m,
                                                    Hash from,
                                                    RouterInfo to)

      Garlic wrap a message from a client or this router, destined for a router, to hide the contents from the OBEP. Caller must call acked() or fail() on the returned object. ELGAMAL ONLY. Both from and to must support ElGamal.
      Parameters:
        `from` - must be a local client with a session key manager, or null to use the router's session key manager. SessionKeyManager MUST support ElGamal.
        `to` - must be ELGAMAL_2048 EncType
      Returns:
        null on encrypt failure

    - #### wrap

          public static GarlicMessage wrap(RouterContext ctx,
                                           I2NPMessage m,
                                           MessageWrapper.OneTimeSession session)

      Garlic wrap a message from nobody, destined for an unknown router, to hide the contents from the IBGW. Uses a supplied one-time session key tag for AES or AEAD encryption, avoiding ElGamal or X25519. Used by OCMJH for DSM.
      Parameters:
        `session` - non-null
      Returns:
        null on encrypt failure

    - #### wrap

          public static GarlicMessage wrap(RouterContext ctx,
                                           I2NPMessage m,
                                           RouterInfo to)

      Garlic wrap a message from nobody, destined for a router, to hide the contents from the OBEP. Forces full asymmetric encryption.
      Parameters:
        `to` - must be ELGAMAL_2048 or ECIES_X25519 EncType
      Returns:
        null on encrypt failure

    - #### wrap

          public static GarlicMessage wrap(RouterContext ctx,
                                           I2NPMessage m,
                                           SessionKey encryptKey,
                                           RatchetSessionTag encryptTag)

      Garlic wrap a message from nobody, destined for an unknown router, to hide the contents from the IBGW. Uses a supplied session key and session tag for ratchet encryption, avoiding full ECIES. Used by above and for DLM replies in HDLMJ.
      Parameters:
        `encryptKey` - non-null
        `encryptTag` - non-null
      Returns:
        null on encrypt failure

    - #### wrap

          public static GarlicMessage wrap(RouterContext ctx,
                                           I2NPMessage m,
                                           SessionKey encryptKey,
                                           SessionTag encryptTag)

      Garlic wrap a message from nobody, destined for an unknown router, to hide the contents from the IBGW. Uses a supplied session key and session tag for AES encryption, avoiding ElGamal. Used by above and for DLM replies in HDLMJ.
      Parameters:
        `encryptKey` - non-null
        `encryptTag` - non-null
      Returns:
        null on encrypt failure