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 Summary
Constructors Constructor Description InMemorySignalProtocolStore(IdentityKeyPair identityKeyPair, int registrationId)
-
Method Summary
Modifier and Type Method Description IdentityKeyPairgetIdentityKeyPair()Get the local client's identity key pair. intgetLocalRegistrationId()Return the local client's registration ID. IdentityKeyStore.IdentityChangesaveIdentity(SignalProtocolAddress address, IdentityKey identityKey)Save a remote client's identity key Store a remote client's identity key as trusted. booleanisTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, IdentityKeyStore.Direction direction)Verify a remote client's identity key. IdentityKeygetIdentity(SignalProtocolAddress address)Return the saved public identity key for a remote client PreKeyRecordloadPreKey(int preKeyId)Load a local PreKeyRecord. voidstorePreKey(int preKeyId, PreKeyRecord record)Store a local PreKeyRecord. booleancontainsPreKey(int preKeyId)voidremovePreKey(int preKeyId)Delete a PreKeyRecord from local storage. SessionRecordloadSession(SignalProtocolAddress address)Returns a copy of the SessionRecord corresponding to the recipientId + deviceId tuple, or a new SessionRecord if one does not currently exist. List<SessionRecord>loadExistingSessions(List<SignalProtocolAddress> addresses)Returns the SessionRecords corresponding to the given addresses. List<Integer>getSubDeviceSessions(String name)Returns all known devices with active sessions for a recipient voidstoreSession(SignalProtocolAddress address, SessionRecord record)Commit to storage the SessionRecord for a given recipientId + deviceId tuple. booleancontainsSession(SignalProtocolAddress address)Determine whether there is a committed SessionRecord for a recipientId + deviceId tuple. voiddeleteSession(SignalProtocolAddress address)Remove a SessionRecord for a recipientId + deviceId tuple. voiddeleteAllSessions(String name)Remove the SessionRecords corresponding to all devices of a recipientId. SignedPreKeyRecordloadSignedPreKey(int signedPreKeyId)Load a local SignedPreKeyRecord. List<SignedPreKeyRecord>loadSignedPreKeys()Load all local SignedPreKeyRecords. voidstoreSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record)Store a local SignedPreKeyRecord. booleancontainsSignedPreKey(int signedPreKeyId)voidremoveSignedPreKey(int signedPreKeyId)Delete a SignedPreKeyRecord from local storage. voidstoreSenderKey(SignalProtocolAddress sender, UUID distributionId, SenderKeyRecord record)Commit to storage the org.signal.libsignal.protocol.groups.state.SenderKeyRecord for a given (distributionId + senderName + deviceId) tuple. SenderKeyRecordloadSenderKey(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. KyberPreKeyRecordloadKyberPreKey(int kyberPreKeyId)Load a local KyberPreKeyRecord. List<KyberPreKeyRecord>loadKyberPreKeys()Load all local KyberPreKeyRecords. voidstoreKyberPreKey(int kyberPreKeyId, KyberPreKeyRecord record)Store a local KyberPreKeyRecord. booleancontainsKyberPreKey(int kyberPreKeyId)voidmarkKyberPreKeyUsed(int kyberPreKeyId)Mark a KyberPreKeyRecord in the local storage as used. booleanhasKyberPreKeyBeenUsed(int kyberPreKeyId)-
-
Constructor Detail
-
InMemorySignalProtocolStore
InMemorySignalProtocolStore(IdentityKeyPair identityKeyPair, int registrationId)
-
-
Method Detail
-
getIdentityKeyPair
IdentityKeyPair getIdentityKeyPair()
Get the local client's identity key pair.
- Returns:
The local client's persistent identity key pair.
-
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.
-
loadExistingSessions
List<SessionRecord> loadExistingSessions(List<SignalProtocolAddress> addresses)
Returns the SessionRecords corresponding to the given addresses.
- Parameters:
addresses- The name and device ID of each remote client.- Returns:
the SessionRecords corresponding to each recipientId + deviceId tuple.
-
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.
-
storeSession
void storeSession(SignalProtocolAddress address, SessionRecord record)
Commit to storage the SessionRecord for a given recipientId + deviceId tuple.
- Parameters:
address- the address of the remote client.record- the current SessionRecord for the remote client.
-
containsSession
boolean containsSession(SignalProtocolAddress address)
Determine whether there is a committed SessionRecord for a recipientId + deviceId tuple.
- Parameters:
address- the address of the remote client.- Returns:
true if a SessionRecord exists, false otherwise.
-
deleteSession
void deleteSession(SignalProtocolAddress address)
Remove a SessionRecord for a recipientId + deviceId tuple.
- Parameters:
address- the address of the remote client.
-
deleteAllSessions
void deleteAllSessions(String name)
Remove the SessionRecords corresponding to all devices of a recipientId.
- Parameters:
name- the name of the remote client.
-
loadSignedPreKey
SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId)
Load a local SignedPreKeyRecord.
- Parameters:
signedPreKeyId- the ID of the local SignedPreKeyRecord.- Returns:
the corresponding SignedPreKeyRecord.
-
loadSignedPreKeys
List<SignedPreKeyRecord> loadSignedPreKeys()
Load all local SignedPreKeyRecords.
- Returns:
All stored SignedPreKeyRecords.
-
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.
-
storeSenderKey
void storeSenderKey(SignalProtocolAddress sender, UUID distributionId, SenderKeyRecord record)
Commit to storage the org.signal.libsignal.protocol.groups.state.SenderKeyRecord for a given (distributionId + senderName + deviceId) tuple.
- 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
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.
-
loadKyberPreKeys
List<KyberPreKeyRecord> loadKyberPreKeys()
Load all local KyberPreKeyRecords.
- Returns:
All stored KyberPreKeyRecords.
-
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.
-
hasKyberPreKeyBeenUsed
boolean hasKyberPreKeyBeenUsed(int kyberPreKeyId)
-
-
-
-