Class RatchetSKM

    • Field Detail

      • SESSION_TAG_DURATION_MS

        static final long SESSION_TAG_DURATION_MS
        Let outbound session tags sit around for this long before expiring them. Inbound tag expiration is set by SESSION_LIFETIME_MAX_MS
        See Also:
        Constant Field Values
      • SESSION_LIFETIME_MAX_MS

        static final long SESSION_LIFETIME_MAX_MS
        Keep 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:
        Constant Field Values
      • SESSION_PENDING_DURATION_MS

        static final long SESSION_PENDING_DURATION_MS
        See Also:
        Constant Field Values
    • 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

      • isDuplicate

        boolean isDuplicate​(PublicKey pk)
        Returns:
        true if a dup
        Since:
        0.9.46
      • createSession

        boolean createSession​(PublicKey target,
                              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:
        callback - null for inbound, may be null for outbound
      • updateSession

        boolean updateSession​(PublicKey target,
                              HandshakeState oldState,
                              HandshakeState state,
                              ReplyCallback callback)
        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 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:
        getTagsToSend in class SessionKeyManager
        Returns:
        the configured value (not adjusted for current available)
      • 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:
        getAvailableTags in class SessionKeyManager
      • 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:
        tagsDelivered in class SessionKeyManager
        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 drastic
        Mark 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:
        failTags in class SessionKeyManager
      • tagsReceived

        public void tagsReceived​(SessionKey key,
                                 RatchetSessionTag tag,
                                 long expire)
        One time session
        Parameters:
        expire - time from now
      • consumeTag

        public SessionKey consumeTag​(SessionTag tag)
        Description copied from class: SessionKeyManager
        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(...)). returns null if no session key matches
        Overrides:
        consumeTag in class SessionKeyManager
        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
      • registerCallback

        void registerCallback​(PublicKey target,
                              int id,
                              int n,
                              ReplyCallback callback)
        Since:
        0.9.46
      • receivedACK

        void receivedACK​(PublicKey target,
                         int id,
                         int n)
        Since:
        0.9.46
      • ackRequested

        void ackRequested​(PublicKey target,
                          int id,
                          int n)
        Since:
        0.9.46