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
public class RatchetSKM extends SessionKeyManager implements SessionTagListener
- Since:
- 0.9.44
-
-
Field Summary
Fields Modifier and Type Field Description protected I2PAppContext_context
-
Constructor Summary
Constructors Constructor Description RatchetSKM(RouterContext context)The session key manager should only be constructed and accessed through the application context.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaddTag(RatchetSessionTag tag, RatchetTagSet ts)Map the tag to this tagset.RatchetEntryconsumeNextAvailableTag(PublicKey target)Outbound.SessionTagconsumeNextAvailableTag(PublicKey target, SessionKey key)Retrieve the next available session tag for identifying the use of the given key when communicating with the target.SessionKeyconsumeTag(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(...)).SessionKeyAndNonceconsumeTag(RatchetSessionTag tag)Inbound.(package private) booleancreateSession(PublicKey target, HandshakeState state)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.voidfailTags(PublicKey target)Deprecated.unused and rather drasticvoidfailTags(PublicKey target, SessionKey key, TagSetHandle ts)Mark these tags as invalid, since the peer has failed to ack them in time.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 millisecondsSessionKeygetCurrentKey(PublicKey target)Retrieve the session key currently associated with encryption to the target, or null if a new session key should be generated.SessionKeygetCurrentOrNewKey(PublicKey target)Retrieve the session key currently associated with encryption to the target.intgetLowThreshold()intgetTagsToSend()How many to send, IF we need to.voidrenderStatusHTML(Writer out)booleanshouldSendTags(PublicKey target, SessionKey key, int lowThreshold)voidshutdown()Called when the system is closing down, instructing the session key manager to take whatever precautions are necessary (saving state, etc)voidtagsAcked(PublicKey target, SessionKey key, TagSetHandle ts)Mark these tags as acked, start to use them (if we haven't already) If the set was previously failed, it will be added back in.TagSetHandletagsDelivered(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 been sent.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.(package private) booleanupdateSession(PublicKey target, HandshakeState oldState, HandshakeState state)Inbound or outbound.-
Methods inherited from class net.i2p.crypto.SessionKeyManager
createSession, shouldSendTags
-
-
-
-
Field Detail
-
_context
protected final I2PAppContext _context
-
-
Constructor Detail
-
RatchetSKM
public RatchetSKM(RouterContext context)
The session key manager should only be constructed and accessed through the application context. This constructor should only be used by the appropriate application context itself.
-
-
Method Detail
-
shutdown
public void shutdown()
Description copied from class:SessionKeyManagerCalled when the system is closing down, instructing the session key manager to take whatever precautions are necessary (saving state, etc)- Overrides:
shutdownin classSessionKeyManager
-
getCurrentKey
public SessionKey getCurrentKey(PublicKey target)
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
public SessionKey getCurrentOrNewKey(PublicKey target)
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
public void createSession(PublicKey target, SessionKey key)
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
-
createSession
boolean createSession(PublicKey target, HandshakeState state)
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.
-
updateSession
boolean updateSession(PublicKey target, HandshakeState oldState, HandshakeState state)
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
-
consumeNextAvailableTag
public SessionTag consumeNextAvailableTag(PublicKey target, SessionKey key)
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
public RatchetEntry consumeNextAvailableTag(PublicKey target)
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
public boolean shouldSendTags(PublicKey target, SessionKey key, int lowThreshold)
- Overrides:
shouldSendTagsin classSessionKeyManager- Returns:
- false always
-
getAvailableTags
public int getAvailableTags(PublicKey target, SessionKey key)
Determine (approximately) how many available session tags for the current target have been confirmed and are available- Overrides:
getAvailableTagsin classSessionKeyManager
-
getAvailableTimeLeft
public long getAvailableTimeLeft(PublicKey target, SessionKey key)
Determine how long the available tags will be available for before expiring, in milliseconds- Overrides:
getAvailableTimeLeftin classSessionKeyManager
-
tagsDelivered
public TagSetHandle 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 been sent. Whether to use the tags immediately (i.e. assume they will be received) or to wait until an ack, is implementation dependent.- Overrides:
tagsDeliveredin classSessionKeyManager- Parameters:
sessionTags- ignored, must be null- Returns:
- the TagSetHandle. Caller MUST subsequently call failTags() or tagsAcked() with this handle. May be null.
-
failTags
@Deprecated public void failTags(PublicKey target)
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
-
failTags
public void failTags(PublicKey target, SessionKey key, TagSetHandle ts)
Mark these tags as invalid, since the peer has failed to ack them in time.- Overrides:
failTagsin classSessionKeyManager
-
tagsAcked
public void tagsAcked(PublicKey target, SessionKey key, TagSetHandle ts)
Mark these tags as acked, start to use them (if we haven't already) If the set was previously failed, it will be added back in.- Overrides:
tagsAckedin classSessionKeyManager
-
tagsReceived
public void tagsReceived(SessionKey key, Set<SessionTag> sessionTags)
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
public void tagsReceived(SessionKey key, Set<SessionTag> sessionTags, long expire)
Description copied from class:SessionKeyManagerAccept the given tags and associate them with the given key for decryption, with specified expiration.- Overrides:
tagsReceivedin classSessionKeyManagersessionTags- modifiable; NOT copiedexpire- time from now- Throws:
UnsupportedOperationException- always
-
consumeTag
public SessionKey consumeTag(SessionTag tag)
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
public SessionKeyAndNonce consumeTag(RatchetSessionTag tag)
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
public boolean addTag(RatchetSessionTag tag, RatchetTagSet ts)
Map the tag to this tagset.- Specified by:
addTagin interfaceSessionTagListener- Returns:
- true if added, false if dup
-
expireTag
public void expireTag(RatchetSessionTag tag, RatchetTagSet ts)
Remove the tag associated with this tagset.- Specified by:
expireTagin interfaceSessionTagListener
-
renderStatusHTML
public void renderStatusHTML(Writer out) throws IOException
- Overrides:
renderStatusHTMLin classSessionKeyManager- Throws:
IOException
-
-