Package net.i2p.router.crypto.ratchet
Class RatchetSKM
java.lang.Object
net.i2p.crypto.SessionKeyManager
net.i2p.router.crypto.ratchet.RatchetSKM
- All Implemented Interfaces:
SessionTagListener
- Since:
- 0.9.44
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RouterContext(package private) static final longKeep unused inbound session tags around for this long (a few minutes longer than session tags are used on the outbound side so that no reasonable network lag can cause failed decrypts) This is also the max idle time for an outbound session.(package private) static final long(package private) static final longLet outbound session tags sit around for this long before expiring them. -
Constructor Summary
ConstructorsConstructorDescriptionRatchetSKM(RouterContext context) For the router SKM only.RatchetSKM(RouterContext context, Destination dest) The session key manager is constructed and accessed through the client manager. -
Method Summary
Modifier and TypeMethodDescription(package private) voidackRequested(PublicKey target, int id, int n) booleanaddTag(RatchetSessionTag tag, RatchetTagSet ts) Map the tag to this tagset.consumeNextAvailableTag(PublicKey target) Outbound.consumeNextAvailableTag(PublicKey target, SessionKey key) Retrieve the next available session tag for identifying the use of the given key when communicating with the target.consumeTag(SessionTag tag) Determine if we have received a session key associated with the given session tag, and if so, discard it (but keep track for frequent dups) and return the decryption key it was received with (via tagsReceived(...)).Inbound.(package private) booleancreateSession(PublicKey target, Destination d, HandshakeState state, ReplyCallback callback) Inbound or outbound.voidcreateSession(PublicKey target, SessionKey key) Associate a new session key with the specified target.voidexpireTag(RatchetSessionTag tag, RatchetTagSet ts) Remove the tag associated with this tagset.voidDeprecated.unused and rather drasticvoidfailTags(PublicKey target, SessionKey key, TagSetHandle ts) intgetAvailableTags(PublicKey target, SessionKey key) Determine (approximately) how many available session tags for the current target have been confirmed and are availablelonggetAvailableTimeLeft(PublicKey target, SessionKey key) Determine how long the available tags will be available for before expiring, in millisecondsgetCurrentKey(PublicKey target) Retrieve the session key currently associated with encryption to the target, or null if a new session key should be generated.getCurrentOrNewKey(PublicKey target) Retrieve the session key currently associated with encryption to the target.The local destination for this SKM(package private) DestinationgetDestination(PublicKey target) intintHow many to send, IF we need to.(package private) booleanisDuplicate(PublicKey pk) (package private) voidnextKeyReceived(PublicKey target, NextSessionKey key) (package private) voidreceivedACK(PublicKey target, int id, int n) (package private) voidregisterCallback(PublicKey target, int id, int n, ReplyCallback callback) (package private) booleanregisterTimer(PublicKey target, Destination d, SimpleTimer2.TimedEvent timer) Side effect - binds this session to the supplied destination.voidrenderStatusHTML(Writer out) booleanshouldSendTags(PublicKey target, SessionKey key, int lowThreshold) voidshutdown()Cannot be restartedvoidtagsAcked(PublicKey target, SessionKey key, TagSetHandle ts) tagsDelivered(PublicKey target, SessionKey key, Set<SessionTag> sessionTags) Take note of the fact that the given sessionTags associated with the key for encryption to the target have definitely been received at the target (aka call this method after receiving an ack to a message delivering them)voidtagsReceived(SessionKey key, Set<SessionTag> sessionTags) Accept the given tags and associate them with the given key for decryption, with the default expiration.voidtagsReceived(SessionKey key, Set<SessionTag> sessionTags, long expire) Accept the given tags and associate them with the given key for decryption, with specified expiration.voidtagsReceived(SessionKey key, RatchetSessionTag tag, long expire) One time session(package private) booleanupdateSession(PublicKey target, HandshakeState oldState, HandshakeState state, ReplyCallback callback, SplitKeys split) Inbound or outbound.Methods inherited from class net.i2p.crypto.SessionKeyManager
createSession, shouldSendTags
-
Field Details
-
_context
-
SESSION_TAG_DURATION_MS
static final long SESSION_TAG_DURATION_MSLet outbound session tags sit around for this long before expiring them. Inbound tag expiration is set by SESSION_LIFETIME_MAX_MS- See Also:
-
SESSION_LIFETIME_MAX_MS
static final long SESSION_LIFETIME_MAX_MSKeep unused inbound session tags around for this long (a few minutes longer than session tags are used on the outbound side so that no reasonable network lag can cause failed decrypts) This is also the max idle time for an outbound session.- See Also:
-
SESSION_PENDING_DURATION_MS
static final long SESSION_PENDING_DURATION_MS- See Also:
-
-
Constructor Details
-
RatchetSKM
For the router SKM only.- Since:
- 0.9.48
-
RatchetSKM
The session key manager is constructed and accessed through the client manager.- Parameters:
dest- null for router's SKM only
-
-
Method Details
-
shutdown
public void shutdown()Cannot be restarted- Overrides:
shutdownin classSessionKeyManager
-
getDestination
The local destination for this SKM- Returns:
- our destination or null for the router SKM
- Since:
- 0.9.46
-
getCurrentKey
Description copied from class:SessionKeyManagerRetrieve the session key currently associated with encryption to the target, or null if a new session key should be generated. Warning - don't generate a new session if this returns null, it's racy, use getCurrentOrNewKey()- Overrides:
getCurrentKeyin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
getCurrentOrNewKey
Description copied from class:SessionKeyManagerRetrieve the session key currently associated with encryption to the target. Generates a new session and session key if not previously exising.- Overrides:
getCurrentOrNewKeyin classSessionKeyManager- Returns:
- non-null
- Throws:
UnsupportedOperationException- always
-
createSession
Description copied from class:SessionKeyManagerAssociate a new session key with the specified target. Metrics to determine when to expire that key begin with this call. Racy if called after getCurrentKey() to check for a current session; use getCurrentOrNewKey() in that case.- Overrides:
createSessionin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
isDuplicate
- Returns:
- true if a dup
- Since:
- 0.9.46
-
createSession
boolean createSession(PublicKey target, Destination d, HandshakeState state, ReplyCallback callback) Inbound or outbound. Checks state.getRole() to determine. For outbound (NS sent), adds to list of pending inbound sessions and returns true. For inbound (NS rcvd), if no other pending outbound sessions, creates one and returns true, or false if one already exists.- Parameters:
d- null if unknowncallback- null for inbound, may be null for outbound
-
updateSession
boolean updateSession(PublicKey target, HandshakeState oldState, HandshakeState state, ReplyCallback callback, SplitKeys split) Inbound or outbound. Checks state.getRole() to determine. For outbound (NSR rcvd by Alice), sets session to transition to ES mode outbound. For inbound (NSR sent by Bob), sets up inbound ES tagset.- Parameters:
oldState- null for inbound, pre-clone for outbound- Returns:
- true if this was the first NSR received
-
nextKeyReceived
- Since:
- 0.9.46
-
registerTimer
Side effect - binds this session to the supplied destination.- Parameters:
d- the far-end Destination for this PublicKey if known, or null- Returns:
- true if registered
- Since:
- 0.9.47
-
getDestination
- Returns:
- the far-end Destination for this PublicKey, or null
- Since:
- 0.9.47
-
consumeNextAvailableTag
Description copied from class:SessionKeyManagerRetrieve the next available session tag for identifying the use of the given key when communicating with the target. If this returns null, no tags are available so ElG should be used with the given key (a new sessionKey should NOT be used)- Overrides:
consumeNextAvailableTagin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
consumeNextAvailableTag
Outbound. Retrieve the next available session tag and key for sending a message to the target. If this returns null, no session is set up yet, and a New Session message should be sent. If this returns non-null, the tag in the RatchetEntry will be non-null. If the SessionKeyAndNonce contains a HandshakeState, then the session setup is in progress, and a New Session Reply message should be sent. Otherwise, an Existing Session message should be sent. -
getTagsToSend
public int getTagsToSend()How many to send, IF we need to.- Overrides:
getTagsToSendin classSessionKeyManager- Returns:
- the configured value (not adjusted for current available)
-
getLowThreshold
public int getLowThreshold()- Overrides:
getLowThresholdin classSessionKeyManager- Returns:
- the configured value
-
shouldSendTags
- Overrides:
shouldSendTagsin classSessionKeyManager- Returns:
- false always
-
getAvailableTags
Determine (approximately) how many available session tags for the current target have been confirmed and are available- Overrides:
getAvailableTagsin classSessionKeyManager
-
getAvailableTimeLeft
Determine how long the available tags will be available for before expiring, in milliseconds- Overrides:
getAvailableTimeLeftin classSessionKeyManager
-
tagsDelivered
Description copied from class:SessionKeyManagerTake note of the fact that the given sessionTags associated with the key for encryption to the target have definitely been received at the target (aka call this method after receiving an ack to a message delivering them)- Overrides:
tagsDeliveredin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
failTags
Deprecated.unused and rather drasticMark all of the tags delivered to the target up to this point as invalid, since the peer has failed to respond when they should have. This call essentially lets the system recover from corrupted tag sets and crashes- Overrides:
failTagsin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
failTags
- Overrides:
failTagsin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
tagsAcked
- Overrides:
tagsAckedin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
tagsReceived
Description copied from class:SessionKeyManagerAccept the given tags and associate them with the given key for decryption, with the default expiration.- Overrides:
tagsReceivedin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
tagsReceived
Description copied from class:SessionKeyManagerAccept the given tags and associate them with the given key for decryption, with specified expiration.- Overrides:
tagsReceivedin classSessionKeyManager- Parameters:
sessionTags- modifiable; NOT copiedexpire- time from now- Throws:
UnsupportedOperationException- always
-
tagsReceived
One time session- Parameters:
expire- time from now
-
consumeTag
Description copied from class:SessionKeyManagerDetermine if we have received a session key associated with the given session tag, and if so, discard it (but keep track for frequent dups) and return the decryption key it was received with (via tagsReceived(...)). returns null if no session key matches- Overrides:
consumeTagin classSessionKeyManager- Throws:
UnsupportedOperationException- always
-
consumeTag
Inbound. Determine if we have received a session key associated with the given session tag, and if so, discard it and return the decryption key it was received with (via tagsReceived(...)). returns null if no session key matches If the return value has null data, it will have a non-null HandshakeState.- Returns:
- a SessionKeyAndNonce or null
-
addTag
Map the tag to this tagset.- Specified by:
addTagin interfaceSessionTagListener- Returns:
- true if added, false if dup
-
expireTag
Remove the tag associated with this tagset.- Specified by:
expireTagin interfaceSessionTagListener
-
registerCallback
- Since:
- 0.9.46
-
receivedACK
- Since:
- 0.9.46
-
ackRequested
- Since:
- 0.9.46
-
renderStatusHTML
- Overrides:
renderStatusHTMLin classSessionKeyManager- Throws:
IOException
-