net.i2p.data.i2cp

## Class SessionConfig

- java.lang.Object
- - net.i2p.data.DataStructureImpl
  - - net.i2p.data.i2cp.SessionConfig

- All Implemented Interfaces:
    Serializable, DataStructure

      public class SessionConfig
      extends DataStructureImpl

  Defines the information a client must provide to create a session
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PROP_OFFLINE_EXPIRATION` Seconds since epoch, NOT ms
    `static String` | `PROP_OFFLINE_SIGNATURE` Base 64, optionally preceded by sig type and ':', default DSA-SHA1
    `static String` | `PROP_TRANSIENT_KEY` Base 64, optionally preceded by sig type and ':', default DSA-SHA1

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SessionConfig()`
    `SessionConfig(Destination dest)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object object)`
    `Date` | `getCreationDate()` Determine when this session was authorized by the destination (so we can prevent replay attacks)
    `Destination` | `getDestination()` Retrieve the destination for which this session is supposed to connect
    `long` | `getOfflineExpiration()` Get the offline expiration
    `Signature` | `getOfflineSignature()` Gets the offline signature from the options.
    `Properties` | `getOptions()` Retrieve any configuration options for the session
    `Signature` | `getSignature()`
    `SigningPublicKey` | `getTransientSigningPublicKey()` Gets the transient signing public key for offline signing.
    `int` | `hashCode()`
    `void` | `readBytes(InputStream rawConfig)` Load up the current object with data from the given stream.
    `void` | `setCreationDate(Date date)`
    `void` | `setOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig)` Set the offline signing data.
    `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.
    `void` | `setSignature(Signature sig)`
    `void` | `signSessionConfig(SigningPrivateKey signingKey)` Sign the structure using the supplied private key
    `boolean` | `tooOld()` Misnamed, could be too old or too far in the future.
    `String` | `toString()`
    `boolean` | `verifySignature()` Verify that the signature matches the destination's signing public key.
    `void` | `writeBytes(OutputStream out)` Write out the data structure to the stream, using the format defined in the I2P data structure specification.

    - ### Methods inherited from class net.i2p.data.DataStructureImpl

      `calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### PROP_OFFLINE_EXPIRATION

          public static final String PROP_OFFLINE_EXPIRATION

      Seconds since epoch, NOT ms
      See Also:
        Constant Field Values

    - #### PROP_OFFLINE_SIGNATURE

          public static final String PROP_OFFLINE_SIGNATURE

      Base 64, optionally preceded by sig type and ':', default DSA-SHA1
      See Also:
        Constant Field Values

    - #### PROP_TRANSIENT_KEY

          public static final String PROP_TRANSIENT_KEY

      Base 64, optionally preceded by sig type and ':', default DSA-SHA1
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SessionConfig

          public SessionConfig()

    - #### SessionConfig

          public SessionConfig(Destination dest)

  - ### Method Detail

    - #### equals

          public boolean equals(Object object)

      Overrides:
        `equals` in class `Object`

    - #### getCreationDate

          public Date getCreationDate()

      Determine when this session was authorized by the destination (so we can prevent replay attacks)
      Returns:
        Date

    - #### getDestination

          public Destination getDestination()

      Retrieve the destination for which this session is supposed to connect
      Returns:
        Destination for this session

    - #### getOfflineExpiration

          public long getOfflineExpiration()

      Get the offline expiration
      Returns:
        Java time (ms) or 0 if not initialized or does not have offline keys

    - #### getOfflineSignature

          public Signature getOfflineSignature()

      Gets the offline signature from the options.
      Returns:
        null on error or if not initialized or does not have offline keys

    - #### getOptions

          public Properties getOptions()

      Retrieve any configuration options for the session
      Returns:
        Properties of this session

    - #### getSignature

          public Signature getSignature()

    - #### 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

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### readBytes

          public void readBytes(InputStream rawConfig)
                         throws DataFormatException,
                                IOException

      Description copied from interface: `DataStructure`
      Load up the current object with data from the given stream. Data loaded this way must match the I2P data structure specification. Warning - many classes will throw IllegalStateException if data is already set.
      Parameters:
        `rawConfig` - stream to read from
      Throws:
        `DataFormatException` - if the data is improperly formatted
        `IOException` - if there was a problem reading the stream

    - #### setCreationDate

          public void setCreationDate(Date date)

    - #### 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(). Will throw ISE otherwise. Side effect - modifies options.
      Throws:
        `IllegalStateException` - if options are not set

    - #### 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

    - #### setSignature

          public void setSignature(Signature sig)

    - #### 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

    - #### tooOld

          public boolean tooOld()

      Misnamed, could be too old or too far in the future.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### 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

    - #### writeBytes

          public void writeBytes(OutputStream out)
                          throws DataFormatException,
                                 IOException

      Description copied from interface: `DataStructure`
      Write out the data structure to the stream, using the format defined in the I2P data structure specification.
      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