]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/manager/storage/SignalAccount.java
Store storage key from keys sync message
[signal-cli] / src / main / java / org / asamk / signal / manager / storage / SignalAccount.java
index cb6f7461dd0c5234f8498a8e4f5cbc48dcb0349c..c1aaa788a2f7466ebbdce001e9266fb8eb0be83d 100644 (file)
@@ -41,6 +41,7 @@ import org.whispersystems.libsignal.util.Pair;
 import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
 import org.whispersystems.signalservice.api.kbs.MasterKey;
 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
+import org.whispersystems.signalservice.api.storage.StorageKey;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -71,6 +72,7 @@ public class SignalAccount implements Closeable {
     private String password;
     private String registrationLockPin;
     private MasterKey pinMasterKey;
+    private StorageKey storageKey;
     private String signalingKey;
     private ProfileKey profileKey;
     private int preKeyIdOffset;
@@ -265,6 +267,10 @@ public class SignalAccount implements Closeable {
         pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull()
                 ? null
                 : new MasterKey(Base64.getDecoder().decode(pinMasterKeyNode.asText()));
+        JsonNode storageKeyNode = rootNode.get("storageKey");
+        storageKey = storageKeyNode == null || storageKeyNode.isNull()
+                ? null
+                : new StorageKey(Base64.getDecoder().decode(storageKeyNode.asText()));
         if (rootNode.has("signalingKey")) {
             signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText();
         }
@@ -398,6 +404,8 @@ public class SignalAccount implements Closeable {
                 .put("registrationLockPin", registrationLockPin)
                 .put("pinMasterKey",
                         pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
+                .put("storageKey",
+                        storageKey == null ? null : Base64.getEncoder().encodeToString(storageKey.serialize()))
                 .put("signalingKey", signalingKey)
                 .put("preKeyIdOffset", preKeyIdOffset)
                 .put("nextSignedPreKeyId", nextSignedPreKeyId)
@@ -533,6 +541,17 @@ public class SignalAccount implements Closeable {
         this.pinMasterKey = pinMasterKey;
     }
 
+    public StorageKey getStorageKey() {
+        if (pinMasterKey != null) {
+            return pinMasterKey.deriveStorageServiceKey();
+        }
+        return storageKey;
+    }
+
+    public void setStorageKey(final StorageKey storageKey) {
+        this.storageKey = storageKey;
+    }
+
     public String getSignalingKey() {
         return signalingKey;
     }