X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/f77519445cb81b0911b89b232edf17187ea8cef5..b7f05a1c806c37a044ce21f87e72598fcd342bb3:/lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java diff --git a/lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java b/lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java index a16ead37..612984ed 100644 --- a/lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java +++ b/lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java @@ -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 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,33 +148,23 @@ 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.setDeviceId(SignalServiceAddress.DEFAULT_DEVICE_ID); - account.setMultiDevice(false); - account.setRegistered(true); - account.setUuid(UuidUtil.parseOrNull(response.getUuid())); - account.setRegistrationLockPin(pin); - account.getSessionStore().archiveAllSessions(); - account.getSignalProtocolStore() - .saveIdentity(account.getSelfAddress(), - account.getIdentityKeyPair().getPublicKey(), - TrustLevel.TRUSTED_VERIFIED); + account.finishRegistration(UuidUtil.parseOrNull(response.getUuid()), masterKey, pin); Manager m = null; try { m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent); + account = null; m.refreshPreKeys(); - - account.save(); + // Set an initial empty profile so user can be added to groups + m.setProfile(null, null, null, null, null); final var result = m; - account = null; m = null; return result;