]> nmode's Git Repositories - signal-cli/commitdiff
Fix issue with incorrectly saving signalingKey
authorAsamK <asamk@gmx.de>
Tue, 19 Jan 2021 15:54:44 +0000 (16:54 +0100)
committerAsamK <asamk@gmx.de>
Tue, 19 Jan 2021 15:58:28 +0000 (16:58 +0100)
Fixes #442, #447

src/main/java/org/asamk/signal/manager/storage/SignalAccount.java
src/main/java/org/asamk/signal/manager/storage/groups/JsonGroupStore.java
src/main/java/org/asamk/signal/manager/storage/protocol/JsonIdentityKeyStore.java
src/main/java/org/asamk/signal/manager/util/Utils.java

index c1aaa788a2f7466ebbdce001e9266fb8eb0be83d..78e30db80850211917d0aabc7fe93c33f025612d 100644 (file)
@@ -244,50 +244,50 @@ public class SignalAccount implements Closeable {
             rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
         }
 
             rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
         }
 
-        JsonNode uuidNode = rootNode.get("uuid");
-        if (uuidNode != null && !uuidNode.isNull()) {
+        if (rootNode.hasNonNull("uuid")) {
             try {
             try {
-                uuid = UUID.fromString(uuidNode.asText());
+                uuid = UUID.fromString(rootNode.get("uuid").asText());
             } catch (IllegalArgumentException e) {
                 throw new IOException("Config file contains an invalid uuid, needs to be a valid UUID", e);
             }
         }
             } catch (IllegalArgumentException e) {
                 throw new IOException("Config file contains an invalid uuid, needs to be a valid UUID", e);
             }
         }
-        JsonNode node = rootNode.get("deviceId");
-        if (node != null) {
-            deviceId = node.asInt();
+        if (rootNode.hasNonNull("deviceId")) {
+            deviceId = rootNode.get("deviceId").asInt();
         }
         }
-        if (rootNode.has("isMultiDevice")) {
-            isMultiDevice = Utils.getNotNullNode(rootNode, "isMultiDevice").asBoolean();
+        if (rootNode.hasNonNull("isMultiDevice")) {
+            isMultiDevice = rootNode.get("isMultiDevice").asBoolean();
         }
         username = Utils.getNotNullNode(rootNode, "username").asText();
         password = Utils.getNotNullNode(rootNode, "password").asText();
         }
         username = Utils.getNotNullNode(rootNode, "username").asText();
         password = Utils.getNotNullNode(rootNode, "password").asText();
-        JsonNode pinNode = rootNode.get("registrationLockPin");
-        registrationLockPin = pinNode == null || pinNode.isNull() ? null : pinNode.asText();
-        JsonNode pinMasterKeyNode = rootNode.get("pinMasterKey");
-        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();
-        }
-        if (rootNode.has("preKeyIdOffset")) {
-            preKeyIdOffset = Utils.getNotNullNode(rootNode, "preKeyIdOffset").asInt(0);
+        if (rootNode.hasNonNull("registrationLockPin")) {
+            registrationLockPin = rootNode.get("registrationLockPin").asText();
+        }
+        if (rootNode.hasNonNull("pinMasterKey")) {
+            pinMasterKey = new MasterKey(Base64.getDecoder().decode(rootNode.get("pinMasterKey").asText()));
+        }
+        if (rootNode.hasNonNull("storageKey")) {
+            storageKey = new StorageKey(Base64.getDecoder().decode(rootNode.get("storageKey").asText()));
+        }
+        if (rootNode.hasNonNull("signalingKey")) {
+            signalingKey = rootNode.get("signalingKey").asText();
+            if (signalingKey.equals("null")) {
+                // Workaround for load bug in older versions
+                signalingKey = null;
+            }
+        }
+        if (rootNode.hasNonNull("preKeyIdOffset")) {
+            preKeyIdOffset = rootNode.get("preKeyIdOffset").asInt(0);
         } else {
             preKeyIdOffset = 0;
         }
         } else {
             preKeyIdOffset = 0;
         }
-        if (rootNode.has("nextSignedPreKeyId")) {
-            nextSignedPreKeyId = Utils.getNotNullNode(rootNode, "nextSignedPreKeyId").asInt();
+        if (rootNode.hasNonNull("nextSignedPreKeyId")) {
+            nextSignedPreKeyId = rootNode.get("nextSignedPreKeyId").asInt();
         } else {
             nextSignedPreKeyId = 0;
         }
         } else {
             nextSignedPreKeyId = 0;
         }
-        if (rootNode.has("profileKey")) {
+        if (rootNode.hasNonNull("profileKey")) {
             try {
             try {
-                profileKey = new ProfileKey(Base64.getDecoder()
-                        .decode(Utils.getNotNullNode(rootNode, "profileKey").asText()));
+                profileKey = new ProfileKey(Base64.getDecoder().decode(rootNode.get("profileKey").asText()));
             } catch (InvalidInputException e) {
                 throw new IOException(
                         "Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",
             } catch (InvalidInputException e) {
                 throw new IOException(
                         "Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",
index 8d0ae6301603e457307c9668716b4eea5b65aa19..f729259650a24d4bde5b8a4cd6278446ea240f3c 100644 (file)
@@ -183,7 +183,7 @@ public class JsonGroupStore {
             JsonNode node = jsonParser.getCodec().readTree(jsonParser);
             for (JsonNode n : node) {
                 GroupInfo g;
             JsonNode node = jsonParser.getCodec().readTree(jsonParser);
             for (JsonNode n : node) {
                 GroupInfo g;
-                if (n.has("masterKey")) {
+                if (n.hasNonNull("masterKey")) {
                     // a v2 group
                     GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
                     try {
                     // a v2 group
                     GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
                     try {
index 06db55600bc3569f7b0407f8cd09730489cb27bf..28d64cbf9729ba7e52d1a12fde93666835717df9 100644 (file)
@@ -219,10 +219,11 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
                         try {
                             IdentityKey id = new IdentityKey(Base64.getDecoder()
                                     .decode(trustedKey.get("identityKey").asText()), 0);
                         try {
                             IdentityKey id = new IdentityKey(Base64.getDecoder()
                                     .decode(trustedKey.get("identityKey").asText()), 0);
-                            TrustLevel trustLevel = trustedKey.has("trustLevel") ? TrustLevel.fromInt(trustedKey.get(
-                                    "trustLevel").asInt()) : TrustLevel.TRUSTED_UNVERIFIED;
-                            Date added = trustedKey.has("addedTimestamp") ? new Date(trustedKey.get("addedTimestamp")
-                                    .asLong()) : new Date();
+                            TrustLevel trustLevel = trustedKey.hasNonNull("trustLevel")
+                                    ? TrustLevel.fromInt(trustedKey.get("trustLevel").asInt())
+                                    : TrustLevel.TRUSTED_UNVERIFIED;
+                            Date added = trustedKey.hasNonNull("addedTimestamp") ? new Date(trustedKey.get(
+                                    "addedTimestamp").asLong()) : new Date();
                             keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
                         } catch (InvalidKeyException e) {
                             logger.warn("Error while decoding key for {}: {}", trustedKeyName, e.getMessage());
                             keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
                         } catch (InvalidKeyException e) {
                             logger.warn("Error while decoding key for {}: {}", trustedKeyName, e.getMessage());
index 65f2811bee45d3e49e1da9119a1d947e9ed7b275..fb38d01a58212b9dc716179c5ea05039bfbe6cb1 100644 (file)
@@ -84,7 +84,7 @@ public class Utils {
 
     public static JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
         JsonNode node = parent.get(name);
 
     public static JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
         JsonNode node = parent.get(name);
-        if (node == null) {
+        if (node == null || node.isNull()) {
             throw new InvalidObjectException(String.format("Incorrect file format: expected parameter %s not found ",
                     name));
         }
             throw new InvalidObjectException(String.format("Incorrect file format: expected parameter %s not found ",
                     name));
         }