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;
identityKey,
registrationId,
profileKey);
- account.save();
return new RegistrationManager(account, pathConfig, serviceConfiguration, userAgent);
}
}
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),
} 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;
} 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(
) throws IOException {
return accountManager.verifyAccountWithCode(verificationCode,
null,
- account.getSignalProtocolStore().getLocalRegistrationId(),
+ account.getLocalRegistrationId(),
true,
legacyPin,
registrationLock,