]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java
Extend updateProfile command to set family name
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / RegistrationManager.java
index 6ded4d0bb550ae0e8abdabe91270135df6634193..612984edbdd78f50e047eb44b931bb922277b3fb 100644 (file)
@@ -29,6 +29,7 @@ import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
 import org.whispersystems.signalservice.api.SignalServiceAccountManager;
 import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
 import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
+import org.whispersystems.signalservice.api.kbs.MasterKey;
 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
 import org.whispersystems.signalservice.api.util.SleepTimer;
 import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
@@ -102,7 +103,6 @@ public class RegistrationManager implements Closeable {
                     identityKey,
                     registrationId,
                     profileKey);
-            account.save();
 
             return new RegistrationManager(account, pathConfig, serviceConfiguration, userAgent);
         }
@@ -113,10 +113,6 @@ public class RegistrationManager implements Closeable {
     }
 
     public void register(boolean voiceVerification, String captcha) throws IOException {
-        if (account.getPassword() == null) {
-            account.setPassword(KeyUtils.createPassword());
-        }
-
         if (voiceVerification) {
             accountManager.requestVoiceVerificationCode(Locale.getDefault(),
                     Optional.fromNullable(captcha),
@@ -124,18 +120,18 @@ public class RegistrationManager implements Closeable {
         } else {
             accountManager.requestSmsVerificationCode(false, Optional.fromNullable(captcha), Optional.absent());
         }
-
-        account.save();
     }
 
-    public void verifyAccount(
+    public Manager verifyAccount(
             String verificationCode, String pin
-    ) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
+    ) throws IOException, LockedException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
         verificationCode = verificationCode.replace("-", "");
         VerifyAccountResponse response;
+        MasterKey masterKey;
         try {
             response = verifyAccountWithCode(verificationCode, pin, null);
-            account.setPinMasterKey(null);
+
+            masterKey = null;
         } catch (LockedException e) {
             if (pin == null) {
                 throw e;
@@ -152,31 +148,31 @@ public class RegistrationManager implements Closeable {
             } catch (LockedException _e) {
                 throw new AssertionError("KBS Pin appeared to matched but reg lock still failed!");
             }
-            account.setPinMasterKey(registrationLockData.getMasterKey());
+            masterKey = registrationLockData.getMasterKey();
         }
 
         // TODO response.isStorageCapable()
         //accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
+        account.finishRegistration(UuidUtil.parseOrNull(response.getUuid()), masterKey, pin);
 
-        account.setDeviceId(SignalServiceAddress.DEFAULT_DEVICE_ID);
-        account.setMultiDevice(false);
-        account.setRegistered(true);
-        account.setUuid(UuidUtil.parseOrNull(response.getUuid()));
-        account.setRegistrationLockPin(pin);
-        account.getSignalProtocolStore().archiveAllSessions();
-        account.getSignalProtocolStore()
-                .saveIdentity(account.getSelfAddress(),
-                        account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey(),
-                        TrustLevel.TRUSTED_VERIFIED);
-
-        try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
+        Manager m = null;
+        try {
+            m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
+            account = null;
 
             m.refreshPreKeys();
+            // Set an initial empty profile so user can be added to groups
+            m.setProfile(null, null, null, null, null);
 
-            m.close(false);
-        }
+            final var result = m;
+            m = null;
 
-        account.save();
+            return result;
+        } finally {
+            if (m != null) {
+                m.close();
+            }
+        }
     }
 
     private VerifyAccountResponse verifyAccountWithCode(
@@ -184,7 +180,7 @@ public class RegistrationManager implements Closeable {
     ) throws IOException {
         return accountManager.verifyAccountWithCode(verificationCode,
                 null,
-                account.getSignalProtocolStore().getLocalRegistrationId(),
+                account.getLocalRegistrationId(),
                 true,
                 legacyPin,
                 registrationLock,