Class InMemorySignalProtocolStore

    • Constructor Detail

      • InMemorySignalProtocolStore

        public InMemorySignalProtocolStore​(IdentityKeyPair identityKeyPair,
                                           int registrationId)
    • Method Detail

      • getLocalRegistrationId

        public int getLocalRegistrationId()
        Description copied from interface: IdentityKeyStore
        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.

        Specified by:
        getLocalRegistrationId in interface IdentityKeyStore
        Returns:
        the local client's registration ID.
      • saveIdentity

        public boolean saveIdentity​(SignalProtocolAddress address,
                                    IdentityKey identityKey)
        Description copied from interface: IdentityKeyStore
        Save a remote client's identity key

        Store a remote client's identity key as trusted.

        Specified by:
        saveIdentity in interface IdentityKeyStore
        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

        public boolean isTrustedIdentity​(SignalProtocolAddress address,
                                         IdentityKey identityKey,
                                         IdentityKeyStore.Direction direction)
        Description copied from interface: IdentityKeyStore
        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.

        Specified by:
        isTrustedIdentity in interface IdentityKeyStore
        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.
      • storePreKey

        public void storePreKey​(int preKeyId,
                                PreKeyRecord record)
        Description copied from interface: PreKeyStore
        Store a local PreKeyRecord.
        Specified by:
        storePreKey in interface PreKeyStore
        Parameters:
        preKeyId - the ID of the PreKeyRecord to store.
        record - the PreKeyRecord.
      • containsPreKey

        public boolean containsPreKey​(int preKeyId)
        Specified by:
        containsPreKey in interface PreKeyStore
        Parameters:
        preKeyId - A PreKeyRecord ID.
        Returns:
        true if the store has a record for the preKeyId, otherwise false.
      • removePreKey

        public void removePreKey​(int preKeyId)
        Description copied from interface: PreKeyStore
        Delete a PreKeyRecord from local storage.
        Specified by:
        removePreKey in interface PreKeyStore
        Parameters:
        preKeyId - The ID of the PreKeyRecord to remove.
      • loadSession

        public SessionRecord loadSession​(SignalProtocolAddress address)
        Description copied from interface: SessionStore
        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.

        Specified by:
        loadSession in interface SessionStore
        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

        public java.util.List<java.lang.Integer> getSubDeviceSessions​(java.lang.String name)
        Description copied from interface: SessionStore
        Returns all known devices with active sessions for a recipient
        Specified by:
        getSubDeviceSessions in interface SessionStore
        Parameters:
        name - the name of the client.
        Returns:
        all known sub-devices with active sessions.
      • deleteAllSessions

        public void deleteAllSessions​(java.lang.String name)
        Description copied from interface: SessionStore
        Remove the SessionRecords corresponding to all devices of a recipientId.
        Specified by:
        deleteAllSessions in interface SessionStore
        Parameters:
        name - the name of the remote client.
      • storeSignedPreKey

        public void storeSignedPreKey​(int signedPreKeyId,
                                      SignedPreKeyRecord record)
        Description copied from interface: SignedPreKeyStore
        Store a local SignedPreKeyRecord.
        Specified by:
        storeSignedPreKey in interface SignedPreKeyStore
        Parameters:
        signedPreKeyId - the ID of the SignedPreKeyRecord to store.
        record - the SignedPreKeyRecord.
      • containsSignedPreKey

        public boolean containsSignedPreKey​(int signedPreKeyId)
        Specified by:
        containsSignedPreKey in interface SignedPreKeyStore
        Parameters:
        signedPreKeyId - A SignedPreKeyRecord ID.
        Returns:
        true if the store has a record for the signedPreKeyId, otherwise false.
      • removeSignedPreKey

        public void removeSignedPreKey​(int signedPreKeyId)
        Description copied from interface: SignedPreKeyStore
        Delete a SignedPreKeyRecord from local storage.
        Specified by:
        removeSignedPreKey in interface SignedPreKeyStore
        Parameters:
        signedPreKeyId - The ID of the SignedPreKeyRecord to remove.
      • storeSenderKey

        public void storeSenderKey​(SignalProtocolAddress sender,
                                   java.util.UUID distributionId,
                                   SenderKeyRecord record)
        Description copied from interface: SenderKeyStore
        Commit to storage the SenderKeyRecord for a given (distributionId + senderName + deviceId) tuple.
        Specified by:
        storeSenderKey in interface SenderKeyStore
        Parameters:
        sender - The address of the current client.
        distributionId - An opaque identifier that uniquely identifies the group (but isn't the group ID).
        record - the current SenderKeyRecord for the specified (distributionId + senderName + deviceId) tuple.
      • loadSenderKey

        public SenderKeyRecord loadSenderKey​(SignalProtocolAddress sender,
                                             java.util.UUID distributionId)
        Description copied from interface: SenderKeyStore
        Returns a copy of the 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.
        Specified by:
        loadSenderKey in interface SenderKeyStore
        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.