java.lang.Object
net.i2p.data.SimpleDataStructure
net.i2p.data.SessionKey
net.i2p.router.crypto.ratchet.SessionKeyAndNonce
- All Implemented Interfaces:
DataStructure
Session key with nonce and optional handshake state for ratchet message encryption and decryption operations, supporting nonces up to 65535
This is what is returned from RatchetTagSet.consume(RatchetSessionTag). RatchetSKM puts it in a RatchetEntry and returns it to ECIESAEADEngine.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe session's id.private final intThe nonce for the session's next message.private final PublicKeyThe remote peer's key, for a reply.private final HandshakeStateThe handshake state the keys came from.Fields inherited from class SessionKey
INVALID_KEY, KEYSIZE_BYTESModifier and TypeFieldDescriptionstatic final SessionKeyA key with all zeroes in the data.static final intKey size in bytes (32).Fields inherited from class SimpleDataStructure
_dataConstructor Summary
ConstructorsConstructorDescriptionSessionKeyAndNonce(byte[] data, int nonce) For outbound Existing Session.SessionKeyAndNonce(byte[] data, int id, int nonce, PublicKey remoteKey) For inbound Existing Session.SessionKeyAndNonce(HandshakeState state) For New Session Replies.Method Summary
All MethodsMethods inherited from class SessionKey
getPreparedKey, length, setData, setPreparedKeyModifier and TypeMethodDescriptionRetrieve an internal representation of the session key, as known by the AES engine used.intlength()The legal length of the byte array in this data structure.voidsetData(byte[] data) Session key data.voidsetPreparedKey(Object obj) Set the internal prepared AES key representation.Methods inherited from class SimpleDataStructure
calculateHash, equals, fromBase64, fromByteArray, getData, hashCode, read, readBytes, toBase64, toByteArray, writeBytesModifier and TypeMethodDescriptionSHA256 hash of the byte array, or null if data is null.booleanCompares the raw data only: two different SimpleDataStructure subclasses of the same length holding the same bytes are equal, e.g.voidfromBase64(String data) Data from the base64 string.voidfromByteArray(byte[] data) Does the same thing asSimpleDataStructure.setData(byte[])but null not allowed.byte[]getData()Data reference (not a copy).inthashCode()We assume the data has enough randomness in it, so use the first 4 bytes for speed.protected intread(InputStream in, byte[] target) Repeated reads until the buffer is full or IOException is thrown.voidreadBytes(InputStream in) Data read from the stream.toBase64()Renders the structure into modified base 64 notation.byte[]Same thing as getData().voidwriteBytes(OutputStream out) Writes the data to the output stream.
Field Details
_id
private final int _idThe session's id._nonce
private final int _nonceThe nonce for the session's next message._state
The handshake state the keys came from._remoteKey
The remote peer's key, for a reply.
Constructor Details
SessionKeyAndNonce
public SessionKeyAndNonce(byte[] data, int nonce) For outbound Existing Session.- Parameters:
data- the AEAD session key, handed to the superclassnonce- message nonce, 0 to 65535
SessionKeyAndNonce
For inbound Existing Session.- Parameters:
data- the AEAD session key, handed to the superclassid- index of the session within the inbound tag setnonce- message nonce, 0 to 65535remoteKey- the sender's static public key
SessionKeyAndNonce
For New Session Replies.- Parameters:
state- the noise handshake state carried over into the new session
Method Details
getNonce
public int getNonce()For ES, else 0.- Returns:
- the message nonce in the range 0 to 65535 that this session key is paired with, or 0 when no established session key is held yet
getID
public int getID()For inbound ES, else 0.- Returns:
- the session ID
getRemoteKey
For inbound ES, else null. For NSR, usegetHandshakeState().getRemotePublicKey().getPublicKey().- Returns:
- the remote key
getHandshakeState
For inbound NSR only, else null. MUST be cloned before processing NSR.- Returns:
- the handshake state
toString
Description copied from class:SimpleDataStructureReturns a string representation of this data structure.- Overrides:
toStringin classSimpleDataStructure