]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/manager/Manager.java
Fix pin hash version to match android
[signal-cli] / src / main / java / org / asamk / signal / manager / Manager.java
index e964d21830694efb7a8ee07d6a5db140bd6a5ad8..576dbb5a68a5b61ede1d391aaba91ee9820a6b7d 100644 (file)
@@ -317,7 +317,7 @@ public class Manager implements Closeable {
         PathConfig pathConfig = PathConfig.createDefault(settingsPath);
 
         if (!SignalAccount.userExists(pathConfig.getDataPath(), username)) {
-            IdentityKeyPair identityKey = KeyHelper.generateIdentityKeyPair();
+            IdentityKeyPair identityKey = KeyUtils.generateIdentityKeyPair();
             int registrationId = KeyHelper.generateRegistrationId(false);
 
             ProfileKey profileKey = KeyUtils.createProfileKey();
@@ -394,15 +394,11 @@ public class Manager implements Closeable {
         // Note "contactDetails" has no optionals. It only gives us info on users who are registered
         List<ContactTokenDetails> contactDetails = this.accountManager.getContacts(numbers);
 
-        // Make the initial map with all numbers set to false for now
-        Map<String, Boolean> usersRegistered = numbers.stream().collect(Collectors.toMap(x -> x, x -> false));
+        Set<String> registeredUsers = contactDetails.stream()
+                .map(ContactTokenDetails::getNumber)
+                .collect(Collectors.toSet());
 
-        // Override the contacts we did obtain
-        for (ContactTokenDetails contactDetail : contactDetails) {
-            usersRegistered.put(contactDetail.getNumber(), true);
-        }
-
-        return usersRegistered;
+        return numbers.stream().collect(Collectors.toMap(x -> x, registeredUsers::contains));
     }
 
     public void register(boolean voiceVerification, String captcha) throws IOException {
@@ -524,8 +520,7 @@ public class Manager implements Closeable {
     }
 
     public void verifyAccount(
-            String verificationCode,
-            String pin
+            String verificationCode, String pin
     ) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
         verificationCode = verificationCode.replace("-", "");
         account.setSignalingKey(KeyUtils.createSignalingKey());
@@ -798,7 +793,7 @@ public class Manager implements Closeable {
     }
 
     private GroupInfo getGroupForSending(GroupId groupId) throws GroupNotFoundException, NotAGroupMemberException {
-        GroupInfo g = account.getGroupStore().getGroup(groupId);
+        GroupInfo g = getGroup(groupId);
         if (g == null) {
             throw new GroupNotFoundException(groupId);
         }
@@ -809,7 +804,7 @@ public class Manager implements Closeable {
     }
 
     private GroupInfo getGroupForUpdating(GroupId groupId) throws GroupNotFoundException, NotAGroupMemberException {
-        GroupInfo g = account.getGroupStore().getGroup(groupId);
+        GroupInfo g = getGroup(groupId);
         if (g == null) {
             throw new GroupNotFoundException(groupId);
         }
@@ -1241,7 +1236,7 @@ public class Manager implements Closeable {
      * Change the expiration timer for a group
      */
     public void setExpirationTimer(GroupId groupId, int messageExpirationTimer) {
-        GroupInfo g = account.getGroupStore().getGroup(groupId);
+        GroupInfo g = getGroup(groupId);
         if (g instanceof GroupInfoV1) {
             GroupInfoV1 groupInfoV1 = (GroupInfoV1) g;
             groupInfoV1.messageExpirationTime = messageExpirationTimer;
@@ -1654,7 +1649,7 @@ public class Manager implements Closeable {
             if (message.getGroupContext().get().getGroupV1().isPresent()) {
                 SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
                 GroupIdV1 groupId = GroupId.v1(groupInfo.getGroupId());
-                GroupInfo group = account.getGroupStore().getGroup(groupId);
+                GroupInfo group = getGroup(groupId);
                 if (group == null || group instanceof GroupInfoV1) {
                     GroupInfoV1 groupV1 = (GroupInfoV1) group;
                     switch (groupInfo.getType()) {
@@ -1825,7 +1820,7 @@ public class Manager implements Closeable {
         final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
 
         GroupIdV2 groupId = GroupUtils.getGroupIdV2(groupSecretParams);
-        GroupInfo groupInfo = account.getGroupStore().getGroup(groupId);
+        GroupInfo groupInfo = getGroup(groupId);
         final GroupInfoV2 groupInfoV2;
         if (groupInfo instanceof GroupInfoV1) {
             // Received a v2 group message for a v1 group, we need to locally migrate the group
@@ -2083,7 +2078,7 @@ public class Manager implements Closeable {
                     }
                 }
                 GroupId groupId = GroupUtils.getGroupId(message.getGroupContext().get());
-                GroupInfo group = account.getGroupStore().getGroup(groupId);
+                GroupInfo group = getGroup(groupId);
                 if (group != null && group.isBlocked()) {
                     return true;
                 }
@@ -2466,7 +2461,7 @@ public class Manager implements Closeable {
         try {
             try (OutputStream fos = new FileOutputStream(groupsFile)) {
                 DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(fos);
-                for (GroupInfo record : account.getGroupStore().getGroups()) {
+                for (GroupInfo record : getGroups()) {
                     if (record instanceof GroupInfoV1) {
                         GroupInfoV1 groupInfo = (GroupInfoV1) record;
                         out.write(new DeviceGroup(groupInfo.getGroupId().serialize(),
@@ -2575,7 +2570,7 @@ public class Manager implements Closeable {
             }
         }
         List<byte[]> groupIds = new ArrayList<>();
-        for (GroupInfo record : account.getGroupStore().getGroups()) {
+        for (GroupInfo record : getGroups()) {
             if (record.isBlocked()) {
                 groupIds.add(record.getGroupId().serialize());
             }
@@ -2602,7 +2597,13 @@ public class Manager implements Closeable {
     }
 
     public GroupInfo getGroup(GroupId groupId) {
-        return account.getGroupStore().getGroup(groupId);
+        final GroupInfo group = account.getGroupStore().getGroup(groupId);
+        if (group instanceof GroupInfoV2 && ((GroupInfoV2) group).getGroup() == null) {
+            final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(((GroupInfoV2) group).getMasterKey());
+            ((GroupInfoV2) group).setGroup(groupHelper.getDecryptedGroup(groupSecretParams));
+            account.getGroupStore().updateGroup(group);
+        }
+        return group;
     }
 
     public List<IdentityInfo> getIdentities() {