import java.io.Closeable;
import java.io.File;
import java.io.IOException;
+import java.util.Date;
import java.util.Locale;
public class RegistrationManager implements Closeable {
account.save();
}
- public void verifyAccount(
+ public Manager verifyAccount(
String verificationCode, String pin
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
verificationCode = verificationCode.replace("-", "");
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);
+ account.getSessionStore().archiveAllSessions();
+ final var recipientId = account.getRecipientStore().resolveRecipient(account.getSelfAddress());
+ final var publicKey = account.getIdentityKeyPair().getPublicKey();
+ account.getIdentityKeyStore().saveIdentity(recipientId, publicKey, new Date());
+ account.getIdentityKeyStore().setIdentityTrustLevel(recipientId, publicKey, TrustLevel.TRUSTED_VERIFIED);
- try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
+ Manager m = null;
+ try {
+ m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
m.refreshPreKeys();
- m.close(false);
- }
+ account.save();
- account.save();
+ final var result = m;
+ account = null;
+ m = null;
+
+ 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,