Class InMemorySignalProtocolStore

  • All Implemented Interfaces:
    org.signal.libsignal.protocol.groups.state.SenderKeyStore , org.signal.libsignal.protocol.state.IdentityKeyStore , org.signal.libsignal.protocol.state.KyberPreKeyStore , org.signal.libsignal.protocol.state.PreKeyStore , org.signal.libsignal.protocol.state.SessionStore , org.signal.libsignal.protocol.state.SignalProtocolStore , org.signal.libsignal.protocol.state.SignedPreKeyStore

    
    public class InMemorySignalProtocolStore
     implements SignalProtocolStore
                        
    • Constructor Detail

      • InMemorySignalProtocolStore

        InMemorySignalProtocolStore(IdentityKeyPair identityKeyPair, int registrationId)
    • Method Detail

      • getLocalRegistrationId

         int getLocalRegistrationId()

        Return the local client's registration ID.

        Clients should maintain a registration ID, a random number between 1 and 16380 that's generated once at install time.

        Returns:

        the local client's registration ID.

      • saveIdentity

         IdentityKeyStore.IdentityChange saveIdentity(SignalProtocolAddress address, IdentityKey identityKey)

        Save a remote client's identity key

        Store a remote client's identity key as trusted.

        Parameters:
        address - The address of the remote client.
        identityKey - The remote client's identity key.
        Returns:

        True if the identity key replaces a previous identity, false if not

      • isTrustedIdentity

         boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, IdentityKeyStore.Direction direction)

        Verify a remote client's identity key.

        Determine whether a remote client's identity is trusted. Convention is that the Signal Protocol is 'trust on first use.' This means that an identity key is considered 'trusted' if there is no entry for the recipient in the local store, or if it matches the saved key for a recipient in the local store. Only if it mismatches an entry in the local store is it considered 'untrusted.'

        Clients may wish to make a distinction as to how keys are trusted based on the direction of travel. For instance, clients may wish to accept all 'incoming' identity key changes, while only blocking identity key changes when sending a message.

        Parameters:
        address - The address of the remote client.
        identityKey - The identity key to verify.
        direction - The direction (sending or receiving) this identity is being used for.
        Returns:

        true if trusted, false if untrusted.

      • getIdentity

         IdentityKey getIdentity(SignalProtocolAddress address)

        Return the saved public identity key for a remote client

        Parameters:
        address - The address of the remote client
        Returns:

        The public identity key, or null if absent

      • loadPreKey

         PreKeyRecord loadPreKey(int preKeyId)

        Load a local PreKeyRecord.

        Parameters:
        preKeyId - the ID of the local PreKeyRecord.
        Returns:

        the corresponding PreKeyRecord.

      • storePreKey

         void storePreKey(int preKeyId, PreKeyRecord record)

        Store a local PreKeyRecord.

        Parameters:
        preKeyId - the ID of the PreKeyRecord to store.
        record - the PreKeyRecord.
      • containsPreKey

         boolean containsPreKey(int preKeyId)
        Parameters:
        preKeyId - A PreKeyRecord ID.
        Returns:

        true if the store has a record for the preKeyId, otherwise false.

      • removePreKey

         void removePreKey(int preKeyId)

        Delete a PreKeyRecord from local storage.

        Parameters:
        preKeyId - The ID of the PreKeyRecord to remove.
      • loadSession

         SessionRecord loadSession(SignalProtocolAddress address)

        Returns a copy of the SessionRecord corresponding to the recipientId + deviceId tuple, or a new SessionRecord if one does not currently exist.

        It is important that implementations return a copy of the current durable information. The returned SessionRecord may be modified, but those changes should not have an effect on the durable session state (what is returned by subsequent calls to this method) without the store method being called here first.

        Parameters:
        address - The name and device ID of the remote client.
        Returns:

        a copy of the SessionRecord corresponding to the recipientId + deviceId tuple, or a new SessionRecord if one does not currently exist.

      • getSubDeviceSessions

         List<Integer> getSubDeviceSessions(String name)

        Returns all known devices with active sessions for a recipient

        Parameters:
        name - the name of the client.
        Returns:

        all known sub-devices with active sessions.

      • loadSignedPreKey

         SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId)

        Load a local SignedPreKeyRecord.

        Parameters:
        signedPreKeyId - the ID of the local SignedPreKeyRecord.
        Returns:

        the corresponding SignedPreKeyRecord.

      • storeSignedPreKey

         void storeSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record)

        Store a local SignedPreKeyRecord.

        Parameters:
        signedPreKeyId - the ID of the SignedPreKeyRecord to store.
        record - the SignedPreKeyRecord.
      • containsSignedPreKey

         boolean containsSignedPreKey(int signedPreKeyId)
        Parameters:
        signedPreKeyId - A SignedPreKeyRecord ID.
        Returns:

        true if the store has a record for the signedPreKeyId, otherwise false.

      • removeSignedPreKey

         void removeSignedPreKey(int signedPreKeyId)

        Delete a SignedPreKeyRecord from local storage.

        Parameters:
        signedPreKeyId - The ID of the SignedPreKeyRecord to remove.
      • loadSenderKey

         SenderKeyRecord loadSenderKey(SignalProtocolAddress sender, UUID distributionId)

        Returns a copy of the org.signal.libsignal.protocol.groups.state.SenderKeyRecord corresponding to the (distributionId + senderName + deviceId) tuple, or `null` if one does not exist.

        It is important that implementations return a copy of the current durable information. The returned SenderKeyRecord may be modified, but those changes should not have an effect on the durable session state (what is returned by subsequent calls to this method) without the store method being called here first.

        Parameters:
        sender - The address of the current client.
        distributionId - An opaque identifier that uniquely identifies the group (but isn't the group ID).
        Returns:

        a copy of the SenderKeyRecord corresponding to the (id + senderName + deviceId tuple, or `null` if one does not currently exist.

      • loadKyberPreKey

         KyberPreKeyRecord loadKyberPreKey(int kyberPreKeyId)

        Load a local KyberPreKeyRecord.

        Parameters:
        kyberPreKeyId - the ID of the local KyberPreKeyRecord.
        Returns:

        the corresponding KyberPreKeyRecord.

      • storeKyberPreKey

         void storeKyberPreKey(int kyberPreKeyId, KyberPreKeyRecord record)

        Store a local KyberPreKeyRecord.

        Parameters:
        kyberPreKeyId - the ID of the KyberPreKeyRecord to store.
        record - the KyberPreKeyRecord.
      • containsKyberPreKey

         boolean containsKyberPreKey(int kyberPreKeyId)
        Parameters:
        kyberPreKeyId - A KyberPreKeyRecord ID.
        Returns:

        true if the store has a record for the kyberPreKeyId, otherwise false.

      • markKyberPreKeyUsed

         void markKyberPreKeyUsed(int kyberPreKeyId)

        Mark a KyberPreKeyRecord in the local storage as used.

        Remove if it is a one-time pre key and noop if it is last-resort.

        Parameters:
        kyberPreKeyId - The ID of the KyberPreKeyRecord to marked.