java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.i2cp.SessionConfig
- All Implemented Interfaces:
Serializable, DataStructure
Defines the information a client must provide to create a session.
- See Also:
Field Summary
Modifier and TypeFieldDescriptionprivate DateWhen this session config was created.private DestinationThe destination for this session.private PropertiesSession configuration options.private SignatureSignature authorizing this session.private static final longIf the client authorized this session more than the specified period ago, refuse it, since it may be a replay attack.static final StringSeconds since epoch, NOT ms.static final StringBase 64, optionally preceded by sig type and ':', default DSA-SHA1.static final StringBase 64, optionally preceded by sig type and ':', default DSA-SHA1.Constructor Summary
ConstructorsConstructorDescriptionCreate a session configuration with no destination chosen yet.SessionConfig(Destination dest) Create a session configuration stamped with the current creation time.Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this session config with another object for equality.private byte[]getBytes()Serialized session config, or empty array on failure.Determine when this session was authorized by the destination (so we can prevent replay attacks).Retrieve the destination for which this session is supposed to connect.longGet the offline expiration.The offline signature parsed from the "offlineSignature" session option.Retrieve any configuration options for the session.Return the signature authenticating this session authorization, or null.Gets the transient signing public key for offline signing.inthashCode()Hash code derived from the session signature.voidreadBytes(InputStream rawConfig) Reads the session config from a stream.voidsetCreationDate(Date date) Creation date for this session.voidsetOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig) Set the offline signing data.voidsetOptions(Properties options) Configure the session with the given options; keys and values 255 bytes (not chars) max eachvoidsetSignature(Signature sig) Signature for this session authorization.voidsignSessionConfig(SigningPrivateKey signingKey) Sign the structure using the supplied private key.booleantooOld()Misnamed, could be too old or too far in the future.toString()Returns a string representation of this session config.booleanVerify that the signature matches the destination's signing public key.voidwriteBytes(OutputStream out) Writes the session config to a stream.Methods inherited from class DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayModifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios).voidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.toBase64()Render the structure into modified base 64 notation.byte[]Convert the structure to a byte array.
Field Details
_destination
The destination for this session._signature
Signature authorizing this session._creationDate
When this session config was created._options
Session configuration options.PROP_OFFLINE_EXPIRATION
Seconds since epoch, NOT ms.- See Also:
PROP_TRANSIENT_KEY
Base 64, optionally preceded by sig type and ':', default DSA-SHA1.- See Also:
PROP_OFFLINE_SIGNATURE
Base 64, optionally preceded by sig type and ':', default DSA-SHA1.- See Also:
OFFSET_VALIDITY
private static final long OFFSET_VALIDITYIf 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
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
Retrieve the destination for which this session is supposed to connect.- Returns:
- Destination for this session
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
Creation date for this session.- Parameters:
date- the time this session was authorized, used to reject replays
getOptions
Retrieve any configuration options for the session.- Returns:
- Properties of this session
setOptions
Configure the session with the given options; keys and values 255 bytes (not chars) max eachDefaults 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
Return the signature authenticating this session authorization, or null.- Returns:
- the signature over the session authorization, or null if none was set
setSignature
Signature for this session authorization.- Parameters:
sig- the signature authenticating this session authorization
setOfflineSignature
Set the offline signing data. Does NOT validate the signature. Must be called AFTERsetOptions(Properties). Will throw ISE otherwise. Side effect - modifies options.- Parameters:
expires- expiration of the offline signature, in milliseconds since the epochtransientSPK- the transient signing key the offline signature coversofflineSig- 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
Gets the transient signing public key for offline signing.- Returns:
- null on error or if not initialized or does not have offline keys
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
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
Reads the session config from a stream.- Parameters:
rawConfig- stream to read from- Throws:
DataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
writeBytes
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 writtenIOException- if there was a problem writing to the stream
equals
hashCode
toString