public class InMemorySignalProtocolStore extends java.lang.Object implements SignalProtocolStore
IdentityKeyStore.Direction| Constructor and Description |
|---|
InMemorySignalProtocolStore(IdentityKeyPair identityKeyPair,
int registrationId) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsPreKey(int preKeyId) |
boolean |
containsSession(SignalProtocolAddress address)
Determine whether there is a committed
SessionRecord for a recipientId + deviceId tuple. |
boolean |
containsSignedPreKey(int signedPreKeyId) |
void |
deleteAllSessions(java.lang.String name)
Remove the
SessionRecords corresponding to all devices of a recipientId. |
void |
deleteSession(SignalProtocolAddress address)
Remove a
SessionRecord for a recipientId + deviceId tuple. |
IdentityKey |
getIdentity(SignalProtocolAddress address)
Return the saved public identity key for a remote client
|
IdentityKeyPair |
getIdentityKeyPair()
Get the local client's identity key pair.
|
int |
getLocalRegistrationId()
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 recipient
|
boolean |
isTrustedIdentity(SignalProtocolAddress address,
IdentityKey identityKey,
IdentityKeyStore.Direction direction)
Verify a remote client's identity key.
|
PreKeyRecord |
loadPreKey(int preKeyId)
Load a local PreKeyRecord.
|
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. |
SignedPreKeyRecord |
loadSignedPreKey(int signedPreKeyId)
Load a local SignedPreKeyRecord.
|
java.util.List<SignedPreKeyRecord> |
loadSignedPreKeys()
Load all local SignedPreKeyRecords.
|
void |
removePreKey(int preKeyId)
Delete a PreKeyRecord from local storage.
|
void |
removeSignedPreKey(int signedPreKeyId)
Delete a SignedPreKeyRecord from local storage.
|
boolean |
saveIdentity(SignalProtocolAddress address,
IdentityKey identityKey)
Save a remote client's identity key
|
void |
storePreKey(int preKeyId,
PreKeyRecord record)
Store a local PreKeyRecord.
|
void |
storeSession(SignalProtocolAddress address,
SessionRecord record)
Commit to storage the
SessionRecord for a given recipientId + deviceId tuple. |
void |
storeSignedPreKey(int signedPreKeyId,
SignedPreKeyRecord record)
Store a local SignedPreKeyRecord.
|
public InMemorySignalProtocolStore(IdentityKeyPair identityKeyPair, int registrationId)
public IdentityKeyPair getIdentityKeyPair()
IdentityKeyStoregetIdentityKeyPair in interface IdentityKeyStorepublic int getLocalRegistrationId()
IdentityKeyStoreClients should maintain a registration ID, a random number between 1 and 16380 that's generated once at install time.
getLocalRegistrationId in interface IdentityKeyStorepublic boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey)
IdentityKeyStoreStore a remote client's identity key as trusted.
saveIdentity in interface IdentityKeyStoreaddress - The address of the remote client.identityKey - The remote client's identity key.public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, IdentityKeyStore.Direction direction)
IdentityKeyStoreDetermine 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.
isTrustedIdentity in interface IdentityKeyStoreaddress - The address of the remote client.identityKey - The identity key to verify.direction - The direction (sending or receiving) this identity is being used for.public IdentityKey getIdentity(SignalProtocolAddress address)
IdentityKeyStoregetIdentity in interface IdentityKeyStoreaddress - The address of the remote clientpublic PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException
PreKeyStoreloadPreKey in interface PreKeyStorepreKeyId - the ID of the local PreKeyRecord.InvalidKeyIdException - when there is no corresponding PreKeyRecord.public void storePreKey(int preKeyId,
PreKeyRecord record)
PreKeyStorestorePreKey in interface PreKeyStorepreKeyId - the ID of the PreKeyRecord to store.record - the PreKeyRecord.public boolean containsPreKey(int preKeyId)
containsPreKey in interface PreKeyStorepreKeyId - A PreKeyRecord ID.public void removePreKey(int preKeyId)
PreKeyStoreremovePreKey in interface PreKeyStorepreKeyId - The ID of the PreKeyRecord to remove.public SessionRecord loadSession(SignalProtocolAddress address)
SessionStoreSessionRecord 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.
loadSession in interface SessionStoreaddress - The name and device ID of the remote client.public java.util.List<java.lang.Integer> getSubDeviceSessions(java.lang.String name)
SessionStoregetSubDeviceSessions in interface SessionStorename - the name of the client.public void storeSession(SignalProtocolAddress address, SessionRecord record)
SessionStoreSessionRecord for a given recipientId + deviceId tuple.storeSession in interface SessionStoreaddress - the address of the remote client.record - the current SessionRecord for the remote client.public boolean containsSession(SignalProtocolAddress address)
SessionStoreSessionRecord for a recipientId + deviceId tuple.containsSession in interface SessionStoreaddress - the address of the remote client.SessionRecord exists, false otherwise.public void deleteSession(SignalProtocolAddress address)
SessionStoreSessionRecord for a recipientId + deviceId tuple.deleteSession in interface SessionStoreaddress - the address of the remote client.public void deleteAllSessions(java.lang.String name)
SessionStoreSessionRecords corresponding to all devices of a recipientId.deleteAllSessions in interface SessionStorename - the name of the remote client.public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException
SignedPreKeyStoreloadSignedPreKey in interface SignedPreKeyStoresignedPreKeyId - the ID of the local SignedPreKeyRecord.InvalidKeyIdException - when there is no corresponding SignedPreKeyRecord.public java.util.List<SignedPreKeyRecord> loadSignedPreKeys()
SignedPreKeyStoreloadSignedPreKeys in interface SignedPreKeyStorepublic void storeSignedPreKey(int signedPreKeyId,
SignedPreKeyRecord record)
SignedPreKeyStorestoreSignedPreKey in interface SignedPreKeyStoresignedPreKeyId - the ID of the SignedPreKeyRecord to store.record - the SignedPreKeyRecord.public boolean containsSignedPreKey(int signedPreKeyId)
containsSignedPreKey in interface SignedPreKeyStoresignedPreKeyId - A SignedPreKeyRecord ID.public void removeSignedPreKey(int signedPreKeyId)
SignedPreKeyStoreremoveSignedPreKey in interface SignedPreKeyStoresignedPreKeyId - The ID of the SignedPreKeyRecord to remove.