Class InMemorySignalProtocolStore
- java.lang.Object
-
- org.signal.libsignal.protocol.state.impl.InMemorySignalProtocolStore
-
- All Implemented Interfaces:
SenderKeyStore,IdentityKeyStore,PreKeyStore,SessionStore,SignalProtocolStore,SignedPreKeyStore
public class InMemorySignalProtocolStore extends java.lang.Object implements SignalProtocolStore
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.signal.libsignal.protocol.state.IdentityKeyStore
IdentityKeyStore.Direction
-
-
Constructor Summary
Constructors Constructor Description InMemorySignalProtocolStore(IdentityKeyPair identityKeyPair, int registrationId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsPreKey(int preKeyId)booleancontainsSession(SignalProtocolAddress address)Determine whether there is a committedSessionRecordfor a recipientId + deviceId tuple.booleancontainsSignedPreKey(int signedPreKeyId)voiddeleteAllSessions(java.lang.String name)Remove theSessionRecords corresponding to all devices of a recipientId.voiddeleteSession(SignalProtocolAddress address)Remove aSessionRecordfor a recipientId + deviceId tuple.IdentityKeygetIdentity(SignalProtocolAddress address)Return the saved public identity key for a remote clientIdentityKeyPairgetIdentityKeyPair()Get the local client's identity key pair.intgetLocalRegistrationId()Return the local client's registration ID.java.util.List<java.lang.Integer>getSubDeviceSessions(java.lang.String name)Returns all known devices with active sessions for a recipientbooleanisTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, IdentityKeyStore.Direction direction)Verify a remote client's identity key.java.util.List<SessionRecord>loadExistingSessions(java.util.List<SignalProtocolAddress> addresses)Returns theSessionRecords corresponding to the given addresses.PreKeyRecordloadPreKey(int preKeyId)Load a local PreKeyRecord.SenderKeyRecordloadSenderKey(SignalProtocolAddress sender, java.util.UUID distributionId)Returns a copy of theSenderKeyRecordcorresponding to the (distributionId + senderName + deviceId) tuple, or `null` if one does not exist.SessionRecordloadSession(SignalProtocolAddress address)Returns a copy of theSessionRecordcorresponding to the recipientId + deviceId tuple, or a new SessionRecord if one does not currently exist.SignedPreKeyRecordloadSignedPreKey(int signedPreKeyId)Load a local SignedPreKeyRecord.java.util.List<SignedPreKeyRecord>loadSignedPreKeys()Load all local SignedPreKeyRecords.voidremovePreKey(int preKeyId)Delete a PreKeyRecord from local storage.voidremoveSignedPreKey(int signedPreKeyId)Delete a SignedPreKeyRecord from local storage.booleansaveIdentity(SignalProtocolAddress address, IdentityKey identityKey)Save a remote client's identity keyvoidstorePreKey(int preKeyId, PreKeyRecord record)Store a local PreKeyRecord.voidstoreSenderKey(SignalProtocolAddress sender, java.util.UUID distributionId, SenderKeyRecord record)Commit to storage theSenderKeyRecordfor a given (distributionId + senderName + deviceId) tuple.voidstoreSession(SignalProtocolAddress address, SessionRecord record)Commit to storage theSessionRecordfor a given recipientId + deviceId tuple.voidstoreSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record)Store a local SignedPreKeyRecord.
-
-
-
Constructor Detail
-
InMemorySignalProtocolStore
public InMemorySignalProtocolStore(IdentityKeyPair identityKeyPair, int registrationId)
-
-
Method Detail
-
getIdentityKeyPair
public IdentityKeyPair getIdentityKeyPair()
Description copied from interface:IdentityKeyStoreGet the local client's identity key pair.- Specified by:
getIdentityKeyPairin interfaceIdentityKeyStore- Returns:
- The local client's persistent identity key pair.
-
getLocalRegistrationId
public int getLocalRegistrationId()
Description copied from interface:IdentityKeyStoreReturn 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:
getLocalRegistrationIdin interfaceIdentityKeyStore- Returns:
- the local client's registration ID.
-
saveIdentity
public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey)
Description copied from interface:IdentityKeyStoreSave a remote client's identity keyStore a remote client's identity key as trusted.
- Specified by:
saveIdentityin interfaceIdentityKeyStore- 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:IdentityKeyStoreVerify 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:
isTrustedIdentityin interfaceIdentityKeyStore- 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
public IdentityKey getIdentity(SignalProtocolAddress address)
Description copied from interface:IdentityKeyStoreReturn the saved public identity key for a remote client- Specified by:
getIdentityin interfaceIdentityKeyStore- Parameters:
address- The address of the remote client- Returns:
- The public identity key, or null if absent
-
loadPreKey
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException
Description copied from interface:PreKeyStoreLoad a local PreKeyRecord.- Specified by:
loadPreKeyin interfacePreKeyStore- Parameters:
preKeyId- the ID of the local PreKeyRecord.- Returns:
- the corresponding PreKeyRecord.
- Throws:
InvalidKeyIdException- when there is no corresponding PreKeyRecord.
-
storePreKey
public void storePreKey(int preKeyId, PreKeyRecord record)Description copied from interface:PreKeyStoreStore a local PreKeyRecord.- Specified by:
storePreKeyin interfacePreKeyStore- Parameters:
preKeyId- the ID of the PreKeyRecord to store.record- the PreKeyRecord.
-
containsPreKey
public boolean containsPreKey(int preKeyId)
- Specified by:
containsPreKeyin interfacePreKeyStore- 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:PreKeyStoreDelete a PreKeyRecord from local storage.- Specified by:
removePreKeyin interfacePreKeyStore- Parameters:
preKeyId- The ID of the PreKeyRecord to remove.
-
loadSession
public SessionRecord loadSession(SignalProtocolAddress address)
Description copied from interface:SessionStoreReturns a copy of theSessionRecordcorresponding 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:
loadSessionin interfaceSessionStore- 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.
-
loadExistingSessions
public java.util.List<SessionRecord> loadExistingSessions(java.util.List<SignalProtocolAddress> addresses) throws NoSessionException
Description copied from interface:SessionStoreReturns theSessionRecords corresponding to the given addresses.- Specified by:
loadExistingSessionsin interfaceSessionStore- Parameters:
addresses- The name and device ID of each remote client.- Returns:
- the SessionRecords corresponding to each recipientId + deviceId tuple.
- Throws:
NoSessionException- if any address does not have an active session.
-
getSubDeviceSessions
public java.util.List<java.lang.Integer> getSubDeviceSessions(java.lang.String name)
Description copied from interface:SessionStoreReturns all known devices with active sessions for a recipient- Specified by:
getSubDeviceSessionsin interfaceSessionStore- Parameters:
name- the name of the client.- Returns:
- all known sub-devices with active sessions.
-
storeSession
public void storeSession(SignalProtocolAddress address, SessionRecord record)
Description copied from interface:SessionStoreCommit to storage theSessionRecordfor a given recipientId + deviceId tuple.- Specified by:
storeSessionin interfaceSessionStore- Parameters:
address- the address of the remote client.record- the current SessionRecord for the remote client.
-
containsSession
public boolean containsSession(SignalProtocolAddress address)
Description copied from interface:SessionStoreDetermine whether there is a committedSessionRecordfor a recipientId + deviceId tuple.- Specified by:
containsSessionin interfaceSessionStore- Parameters:
address- the address of the remote client.- Returns:
- true if a
SessionRecordexists, false otherwise.
-
deleteSession
public void deleteSession(SignalProtocolAddress address)
Description copied from interface:SessionStoreRemove aSessionRecordfor a recipientId + deviceId tuple.- Specified by:
deleteSessionin interfaceSessionStore- Parameters:
address- the address of the remote client.
-
deleteAllSessions
public void deleteAllSessions(java.lang.String name)
Description copied from interface:SessionStoreRemove theSessionRecords corresponding to all devices of a recipientId.- Specified by:
deleteAllSessionsin interfaceSessionStore- Parameters:
name- the name of the remote client.
-
loadSignedPreKey
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException
Description copied from interface:SignedPreKeyStoreLoad a local SignedPreKeyRecord.- Specified by:
loadSignedPreKeyin interfaceSignedPreKeyStore- Parameters:
signedPreKeyId- the ID of the local SignedPreKeyRecord.- Returns:
- the corresponding SignedPreKeyRecord.
- Throws:
InvalidKeyIdException- when there is no corresponding SignedPreKeyRecord.
-
loadSignedPreKeys
public java.util.List<SignedPreKeyRecord> loadSignedPreKeys()
Description copied from interface:SignedPreKeyStoreLoad all local SignedPreKeyRecords.- Specified by:
loadSignedPreKeysin interfaceSignedPreKeyStore- Returns:
- All stored SignedPreKeyRecords.
-
storeSignedPreKey
public void storeSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record)Description copied from interface:SignedPreKeyStoreStore a local SignedPreKeyRecord.- Specified by:
storeSignedPreKeyin interfaceSignedPreKeyStore- Parameters:
signedPreKeyId- the ID of the SignedPreKeyRecord to store.record- the SignedPreKeyRecord.
-
containsSignedPreKey
public boolean containsSignedPreKey(int signedPreKeyId)
- Specified by:
containsSignedPreKeyin interfaceSignedPreKeyStore- 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:SignedPreKeyStoreDelete a SignedPreKeyRecord from local storage.- Specified by:
removeSignedPreKeyin interfaceSignedPreKeyStore- 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:SenderKeyStoreCommit to storage theSenderKeyRecordfor a given (distributionId + senderName + deviceId) tuple.- Specified by:
storeSenderKeyin interfaceSenderKeyStore- 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:SenderKeyStoreReturns a copy of theSenderKeyRecordcorresponding 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:
loadSenderKeyin interfaceSenderKeyStore- 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.
-
-