java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.i2cp.SessionConfig
All Implemented Interfaces:
Serializable, DataStructure

public class SessionConfigextends DataStructureImpl
Defines the information a client must provide to create a session.
See Also:
  • Field Details

    • _destination

      private Destination _destination
      The destination for this session.
    • _signature

      private Signature _signature
      Signature authorizing this session.
    • _creationDate

      private Date _creationDate
      When this session config was created.
    • _options

      private Properties _options
      Session configuration options.
    • PROP_OFFLINE_EXPIRATION

      public static final String PROP_OFFLINE_EXPIRATION
      Seconds since epoch, NOT ms.
      See Also:
    • PROP_TRANSIENT_KEY

      public static final String PROP_TRANSIENT_KEY
      Base 64, optionally preceded by sig type and ':', default DSA-SHA1.
      See Also:
    • PROP_OFFLINE_SIGNATURE

      public static final String PROP_OFFLINE_SIGNATURE
      Base 64, optionally preceded by sig type and ':', default DSA-SHA1.
      See Also:
    • OFFSET_VALIDITY

      private static final long OFFSET_VALIDITY
      If the client authorized this session more than the specified period ago, refuse it, since it may be a replay attack.

      Really? See also ClientManager.REQUEST_LEASESET_TIMEOUT. If I2CP replay attacks are a thing, there's a lot more to do.

      Maximum age of a session authorization in milliseconds.

      See Also:
  • Constructor Details

    • SessionConfig

      public SessionConfig()
      Create a session configuration with no destination chosen yet.
    • SessionConfig

      public SessionConfig(Destination dest)
      Create a session configuration stamped with the current creation time.
      Parameters:
      dest - the destination this session connects to, or null if not chosen yet
  • Method Details

    • getDestination

      public Destination getDestination()
      Retrieve the destination for which this session is supposed to connect.
      Returns:
      Destination for this session
    • getCreationDate

      public Date getCreationDate()
      Determine when this session was authorized by the destination (so we can prevent replay attacks).
      Returns:
      the time the destination authorized this session, or null if never set
    • setCreationDate

      public void setCreationDate(Date date)
      Creation date for this session.
      Parameters:
      date - the time this session was authorized, used to reject replays
    • getOptions

      public Properties getOptions()
      Retrieve any configuration options for the session.
      Returns:
      Properties of this session
    • setOptions

      public void setOptions(Properties options)
      Configure the session with the given options; keys and values 255 bytes (not chars) max each

      Defaults in SessionConfig options are, in general, NOT honored. Defaults are not serialized out-of-JVM, and the router does not recognize defaults in-JVM. Client side must promote defaults to the primary map.

      Does NOT make a copy.

      Parameters:
      options - Properties for this session
    • getSignature

      public Signature getSignature()
      Return the signature authenticating this session authorization, or null.
      Returns:
      the signature over the session authorization, or null if none was set
    • setSignature

      public void setSignature(Signature sig)
      Signature for this session authorization.
      Parameters:
      sig - the signature authenticating this session authorization
    • setOfflineSignature

      public void setOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig)
      Set the offline signing data. Does NOT validate the signature. Must be called AFTER setOptions(Properties). Will throw ISE otherwise. Side effect - modifies options.
      Parameters:
      expires - expiration of the offline signature, in milliseconds since the epoch
      transientSPK - the transient signing key the offline signature covers
      offlineSig - the signature over the offline signing data
      Throws:
      IllegalStateException - if options are not set
    • getOfflineExpiration

      public long getOfflineExpiration()
      Get the offline expiration.
      Returns:
      Java time (ms) or 0 if not initialized or does not have offline keys
    • getTransientSigningPublicKey

      public SigningPublicKey getTransientSigningPublicKey()
      Gets the transient signing public key for offline signing.
      Returns:
      null on error or if not initialized or does not have offline keys
    • getOfflineSignature

      public Signature getOfflineSignature()
      The offline signature parsed from the "offlineSignature" session option.
      Returns:
      null on error or if not initialized or does not have offline keys
    • signSessionConfig

      public void signSessionConfig(SigningPrivateKey signingKey) throws DataFormatException
      Sign the structure using the supplied private key.
      Parameters:
      signingKey - SigningPrivateKey to sign with. If offline data is set, must be with the transient key.
      Throws:
      DataFormatException - if the data cannot be signed
    • verifySignature

      public boolean verifySignature()
      Verify that the signature matches the destination's signing public key.

      Note that this also returns false if the creation date is too far in the past or future. See tooOld() and getCreationDate().

      As of 0.9.38, validates the offline signature if included.

      Returns:
      true only if the signature matches
    • tooOld

      public boolean tooOld()
      Misnamed, could be too old or too far in the future.
      Returns:
      true if the creation date is out of range
    • getBytes

      private byte[] getBytes()
      Serialized session config, or empty array on failure.
      Returns:
      the serialized session config, or empty array on failure
    • readBytes

      public void readBytes(InputStream rawConfig) throws DataFormatException, IOException
      Reads the session config from a stream.
      Parameters:
      rawConfig - stream to read from
      Throws:
      DataFormatException - if the data is improperly formatted
      IOException - if there was a problem reading the stream
    • writeBytes

      public void writeBytes(OutputStream out) throws DataFormatException, IOException
      Writes the session config to a stream.
      Parameters:
      out - stream to write to
      Throws:
      DataFormatException - if the data was incomplete or not yet ready to be written
      IOException - if there was a problem writing to the stream
    • equals

      public boolean equals(Object object)
      Compares this session config with another object for equality.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Hash code derived from the session signature.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of this session config.
      Overrides:
      toString in class Object