java.lang.Object
net.i2p.crypto.SessionKeyManager
net.i2p.router.crypto.ratchet.MuxedSKM
Multiplexed session key manager combining ElGamal and ECIES key management.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RatchetSKMThe ratcheted ECIES session keys.private final AtomicIntegerCounts the ratcheted keys handed out.private final TransientSessionKeyManagerThe ElGamal session keys.private final AtomicIntegerCounts the ElGamal keys handed out.(package private) static final intHow much slower the ElGamal slow decrypt is than the ratchet one, so its success count is divided by this much before the two are compared.(package private) static final intSize of the sampling window.Constructor Summary
ConstructorsConstructorDescriptionMuxedSKM(TransientSessionKeyManager elg, RatchetSKM ec) Combines ElGamal and ECIES SKMs with adaptive decrypt ordering.Method Summary
Modifier and TypeMethodDescriptionconsumeNextAvailableTag(PublicKey target) EC only.consumeNextAvailableTag(PublicKey target, SessionKey key) ElG only.consumeTag(SessionTag tag) Tries ElGamal tag lookup first, falls back to ratchet lookup.createSession(PublicKey target) ElG only.voidcreateSession(PublicKey target, SessionKey key) ElG only.voidfailTags(PublicKey target, SessionKey key, TagSetHandle ts) ElG only.intgetAvailableTags(PublicKey target, SessionKey key) Delegates to the appropriate key manager by encryption type.longgetAvailableTimeLeft(PublicKey target, SessionKey key) Delegates to the appropriate key manager by encryption type.getCurrentKey(PublicKey target) ElG only.getCurrentOrNewKey(PublicKey target) ElG only.long[]Sums the debug stats of both key managers, null if neither tracks them.getECSKM()Return the ratchet key manager that handles ECIES-X25519 sessions.Return the ElGamal key manager that handles legacy transient sessions.intNot used; thresholds are not used for ratchet sessions.intNot used; tag management is handled by the ratchet protocol.(package private) static booleanneedsRestart(int ec, int elg) Whether the sampling window is full and both counters should start over, so the ordering tracks recent traffic rather than the whole session.(package private) booleanShould we try the Ratchet slow decrypt before ElG slow decrypt? Adaptive test based on previous mix of traffic for this SKM, as reported by reportDecryptResult().(package private) static booleanpreferRatchet(int ec, int elg) The ordering the current window favours, with the ElGamal count discounted because the ratchet slow decrypt is the cheaper of the two to try first.voidrenderStatusHTML(Writer out) Renders debug status for both key managers.(package private) voidreportDecryptResult(boolean isRatchet, boolean success) Report the result of a slow decrypt attempt.(package private) static booleanrollOver(AtomicInteger counter, int expected) Reset one counter to start a fresh window, only if nothing was recorded since the value the decision was taken on.booleanshouldSendTags(PublicKey target, SessionKey key) ElG only.booleanshouldSendTags(PublicKey target, SessionKey key, int lowThreshold) ElG only.voidshutdown()Shuts down both ElGamal and ECIES key managers.voidtagsAcked(PublicKey target, SessionKey key, TagSetHandle ts) ElG only.tagsDelivered(PublicKey target, SessionKey key, Set<SessionTag> sessionTags) ElG only.voidtagsReceived(SessionKey key, Set<SessionTag> sessionTags) ElG only.voidtagsReceived(SessionKey key, Set<SessionTag> sessionTags, long expire) ElG only.voidtagsReceived(SessionKey key, RatchetSessionTag tag, long expire) EC only One time session.Methods inherited from class SessionKeyManager
failTags
Field Details
_elg
The ElGamal session keys._ec
The ratcheted ECIES session keys._elgCounter
Counts the ElGamal keys handed out._ecCounter
Counts the ratcheted keys handed out.ELG_SLOW_FACTOR
static final int ELG_SLOW_FACTORHow much slower the ElGamal slow decrypt is than the ratchet one, so its success count is divided by this much before the two are compared.- See Also:
RESTART_COUNTERS
static final int RESTART_COUNTERSSize of the sampling window. Once both counters are individually meaningful and their sum passes this, the window rolls over so the ordering tracks recent traffic instead of the whole session.- See Also:
Constructor Details
MuxedSKM
Combines ElGamal and ECIES SKMs with adaptive decrypt ordering.- Parameters:
elg- the ElGamal key manager handling legacy transient sessionsec- the ratchet key manager handling ECIES-X25519 sessions
Method Details
getElgSKM
Return the ElGamal key manager that handles legacy transient sessions.- Returns:
- the ElGamal session key manager this instance multiplexes
getECSKM
Return the ratchet key manager that handles ECIES-X25519 sessions.- Returns:
- the ratchet session key manager this instance multiplexes
preferRatchet
boolean preferRatchet()Should we try the Ratchet slow decrypt before ElG slow decrypt? Adaptive test based on previous mix of traffic for this SKM, as reported by reportDecryptResult().- Returns:
- true if the ratchet slow decrypt should be tried before the ElGamal one
needsRestart
static boolean needsRestart(int ec, int elg) Whether the sampling window is full and both counters should start over, so the ordering tracks recent traffic rather than the whole session. Both counters have to be individually meaningful, or a one-sided flood would reset a window that still says something about the other path.- Parameters:
ec- successful ratchet decrypts in the current windowelg- successful ElGamal decrypts in the current window- Returns:
- true if the window has run its course
preferRatchet
static boolean preferRatchet(int ec, int elg) The ordering the current window favours, with the ElGamal count discounted because the ratchet slow decrypt is the cheaper of the two to try first.- Parameters:
ec- successful ratchet decrypts in the current windowelg- successful ElGamal decrypts in the current window- Returns:
- true if the ratchet slow decrypt should go first
rollOver
Reset one counter to start a fresh window, only if nothing was recorded since the value the decision was taken on. A plain set(0) would discard any success logged between that read and the reset, which is how the counters used to lose counts under concurrent decrypts.- Parameters:
counter- the counter to roll overexpected- the value read when the decision was taken- Returns:
- true if the counter was reset, false if it moved in the meantime
reportDecryptResult
void reportDecryptResult(boolean isRatchet, boolean success) Report the result of a slow decrypt attempt.- Parameters:
isRatchet- true for EC, false for ElGsuccess- true for successful decrypt
getCurrentKey
ElG only.- Overrides:
getCurrentKeyin classSessionKeyManager- Parameters:
target- the destination whose current session key is wanted- Returns:
- the current key
getCurrentOrNewKey
ElG only.- Overrides:
getCurrentOrNewKeyin classSessionKeyManager- Parameters:
target- the destination to start or continue a session with- Returns:
- the current or new key
createSession
ElG only.- Overrides:
createSessionin classSessionKeyManager- Parameters:
target- the destination the session is established withkey- the session key to associate, whose expiry metrics start at this call
createSession
ElG only.- Overrides:
createSessionin classSessionKeyManager- Parameters:
target- the destination to establish a freshly generated session with- Returns:
- the session key
consumeNextAvailableTag
ElG only.- Overrides:
consumeNextAvailableTagin classSessionKeyManager- Parameters:
target- the destination the tag was sent tokey- the session key whose use the tag identifies- Returns:
- the next available tag, or null
consumeNextAvailableTag
EC only.- Parameters:
target- the destination to take an available session tag from- Returns:
- the oldest unconsumed tag, or null if the target is not an ECIES-X25519 key
getTagsToSend
public int getTagsToSend()Not used; tag management is handled by the ratchet protocol.- Overrides:
getTagsToSendin classSessionKeyManager- Returns:
- 0, tag management is handled by ratchet protocol
getLowThreshold
public int getLowThreshold()Not used; thresholds are not used for ratchet sessions.- Overrides:
getLowThresholdin classSessionKeyManager- Returns:
- 0, threshold not used for ratchet sessions
shouldSendTags
ElG only.- Overrides:
shouldSendTagsin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session key- Returns:
- whether send tags
shouldSendTags
ElG only.- Overrides:
shouldSendTagsin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session keylowThreshold- the low threshold- Returns:
- whether send tags
getAvailableTags
Delegates to the appropriate key manager by encryption type.- Overrides:
getAvailableTagsin classSessionKeyManager- Parameters:
target- the destination the tags were sent tokey- the session key those tags were issued under- Returns:
- the available tags
getAvailableTimeLeft
Delegates to the appropriate key manager by encryption type.- Overrides:
getAvailableTimeLeftin classSessionKeyManager- Parameters:
target- the destination the tags were sent tokey- the session key those tags were issued under- Returns:
- the available time left
tagsDelivered
ElG only.- Overrides:
tagsDeliveredin classSessionKeyManager- Parameters:
target- the destination that acknowledged the tagskey- the session key the acknowledged tags were issued undersessionTags- modifiable; NOT copied- Returns:
- the tag set handle
tagsReceived
ElG only.- Overrides:
tagsReceivedin classSessionKeyManager- Parameters:
key- the session key the tags were received forsessionTags- modifiable; NOT copied
tagsReceived
ElG only.- Overrides:
tagsReceivedin classSessionKeyManager- Parameters:
key- the session key the tags were received forsessionTags- modifiable; NOT copiedexpire- time from now
tagsReceived
EC only One time session.- Parameters:
key- the session the tag was received ontag- the one-time tag receivedexpire- time from now
consumeTag
Tries ElGamal tag lookup first, falls back to ratchet lookup.- Overrides:
consumeTagin classSessionKeyManager- Parameters:
tag- the session tag whose delivered key is consumed- Returns:
- the session key, or null
shutdown
public void shutdown()Shuts down both ElGamal and ECIES key managers.- Overrides:
shutdownin classSessionKeyManager
renderStatusHTML
Renders debug status for both key managers.- Overrides:
renderStatusHTMLin classSessionKeyManager- Parameters:
out- the writer to render to- Throws:
IOException- if an I/O error occurs
getDebugStats
public long[] getDebugStats()Sums the debug stats of both key managers, null if neither tracks them.- Overrides:
getDebugStatsin classSessionKeyManager- Returns:
- the stats, or null
failTags
ElG only.- Overrides:
failTagsin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session keyts- the tag set handle
tagsAcked
ElG only.- Overrides:
tagsAckedin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session keyts- the tag set handle