1 package org
.asamk
.textsecure
;
3 import com
.fasterxml
.jackson
.annotation
.JsonProperty
;
4 import com
.fasterxml
.jackson
.databind
.annotation
.JsonDeserialize
;
5 import com
.fasterxml
.jackson
.databind
.annotation
.JsonSerialize
;
6 import org
.whispersystems
.libsignal
.IdentityKey
;
7 import org
.whispersystems
.libsignal
.IdentityKeyPair
;
8 import org
.whispersystems
.libsignal
.InvalidKeyIdException
;
9 import org
.whispersystems
.libsignal
.SignalProtocolAddress
;
10 import org
.whispersystems
.libsignal
.state
.PreKeyRecord
;
11 import org
.whispersystems
.libsignal
.state
.SessionRecord
;
12 import org
.whispersystems
.libsignal
.state
.SignalProtocolStore
;
13 import org
.whispersystems
.libsignal
.state
.SignedPreKeyRecord
;
15 import java
.util
.List
;
17 class JsonSignalProtocolStore
implements SignalProtocolStore
{
19 @JsonProperty("preKeys")
20 @JsonDeserialize(using
= JsonPreKeyStore
.JsonPreKeyStoreDeserializer
.class)
21 @JsonSerialize(using
= JsonPreKeyStore
.JsonPreKeyStoreSerializer
.class)
22 protected JsonPreKeyStore preKeyStore
;
24 @JsonProperty("sessionStore")
25 @JsonDeserialize(using
= JsonSessionStore
.JsonSessionStoreDeserializer
.class)
26 @JsonSerialize(using
= JsonSessionStore
.JsonPreKeyStoreSerializer
.class)
27 protected JsonSessionStore sessionStore
;
29 @JsonProperty("signedPreKeyStore")
30 @JsonDeserialize(using
= JsonSignedPreKeyStore
.JsonSignedPreKeyStoreDeserializer
.class)
31 @JsonSerialize(using
= JsonSignedPreKeyStore
.JsonSignedPreKeyStoreSerializer
.class)
32 protected JsonSignedPreKeyStore signedPreKeyStore
;
34 @JsonProperty("identityKeyStore")
35 @JsonDeserialize(using
= JsonIdentityKeyStore
.JsonIdentityKeyStoreDeserializer
.class)
36 @JsonSerialize(using
= JsonIdentityKeyStore
.JsonIdentityKeyStoreSerializer
.class)
37 protected JsonIdentityKeyStore identityKeyStore
;
39 public JsonSignalProtocolStore() {
42 public JsonSignalProtocolStore(JsonPreKeyStore preKeyStore
, JsonSessionStore sessionStore
, JsonSignedPreKeyStore signedPreKeyStore
, JsonIdentityKeyStore identityKeyStore
) {
43 this.preKeyStore
= preKeyStore
;
44 this.sessionStore
= sessionStore
;
45 this.signedPreKeyStore
= signedPreKeyStore
;
46 this.identityKeyStore
= identityKeyStore
;
49 public JsonSignalProtocolStore(IdentityKeyPair identityKeyPair
, int registrationId
) {
50 preKeyStore
= new JsonPreKeyStore();
51 sessionStore
= new JsonSessionStore();
52 signedPreKeyStore
= new JsonSignedPreKeyStore();
53 this.identityKeyStore
= new JsonIdentityKeyStore(identityKeyPair
, registrationId
);
57 public IdentityKeyPair
getIdentityKeyPair() {
58 return identityKeyStore
.getIdentityKeyPair();
62 public int getLocalRegistrationId() {
63 return identityKeyStore
.getLocalRegistrationId();
67 public void saveIdentity(String name
, IdentityKey identityKey
) {
68 identityKeyStore
.saveIdentity(name
, identityKey
);
72 public boolean isTrustedIdentity(String name
, IdentityKey identityKey
) {
73 return identityKeyStore
.isTrustedIdentity(name
, identityKey
);
77 public PreKeyRecord
loadPreKey(int preKeyId
) throws InvalidKeyIdException
{
78 return preKeyStore
.loadPreKey(preKeyId
);
82 public void storePreKey(int preKeyId
, PreKeyRecord
record) {
83 preKeyStore
.storePreKey(preKeyId
, record);
87 public boolean containsPreKey(int preKeyId
) {
88 return preKeyStore
.containsPreKey(preKeyId
);
92 public void removePreKey(int preKeyId
) {
93 preKeyStore
.removePreKey(preKeyId
);
97 public SessionRecord
loadSession(SignalProtocolAddress address
) {
98 return sessionStore
.loadSession(address
);
102 public List
<Integer
> getSubDeviceSessions(String name
) {
103 return sessionStore
.getSubDeviceSessions(name
);
107 public void storeSession(SignalProtocolAddress address
, SessionRecord
record) {
108 sessionStore
.storeSession(address
, record);
112 public boolean containsSession(SignalProtocolAddress address
) {
113 return sessionStore
.containsSession(address
);
117 public void deleteSession(SignalProtocolAddress address
) {
118 sessionStore
.deleteSession(address
);
122 public void deleteAllSessions(String name
) {
123 sessionStore
.deleteAllSessions(name
);
127 public SignedPreKeyRecord
loadSignedPreKey(int signedPreKeyId
) throws InvalidKeyIdException
{
128 return signedPreKeyStore
.loadSignedPreKey(signedPreKeyId
);
132 public List
<SignedPreKeyRecord
> loadSignedPreKeys() {
133 return signedPreKeyStore
.loadSignedPreKeys();
137 public void storeSignedPreKey(int signedPreKeyId
, SignedPreKeyRecord
record) {
138 signedPreKeyStore
.storeSignedPreKey(signedPreKeyId
, record);
142 public boolean containsSignedPreKey(int signedPreKeyId
) {
143 return signedPreKeyStore
.containsSignedPreKey(signedPreKeyId
);
147 public void removeSignedPreKey(int signedPreKeyId
) {
148 signedPreKeyStore
.removeSignedPreKey(signedPreKeyId
);