X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/76c400d2c3d38382103ba640f4bd3fd0d129062f..14b07be0dcc9d61eeebc857338367515a3e338b3:/lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java diff --git a/lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java b/lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java index 9d0b344a..4072a9df 100644 --- a/lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java +++ b/lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java @@ -2,14 +2,18 @@ package org.asamk.signal.manager; import org.asamk.signal.manager.api.AccountCheckException; import org.asamk.signal.manager.api.NotRegisteredException; +import org.asamk.signal.manager.api.ServiceEnvironment; import org.asamk.signal.manager.config.ServiceConfig; -import org.asamk.signal.manager.config.ServiceEnvironment; import org.asamk.signal.manager.config.ServiceEnvironmentConfig; +import org.asamk.signal.manager.internal.AccountFileUpdaterImpl; +import org.asamk.signal.manager.internal.ManagerImpl; +import org.asamk.signal.manager.internal.MultiAccountManagerImpl; +import org.asamk.signal.manager.internal.PathConfig; +import org.asamk.signal.manager.internal.ProvisioningManagerImpl; +import org.asamk.signal.manager.internal.RegistrationManagerImpl; import org.asamk.signal.manager.storage.SignalAccount; import org.asamk.signal.manager.storage.accounts.AccountsStore; -import org.asamk.signal.manager.storage.identities.TrustNewIdentity; import org.asamk.signal.manager.util.KeyUtils; -import org.signal.libsignal.protocol.util.KeyHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException; @@ -28,27 +32,27 @@ public class SignalAccountFiles { private final ServiceEnvironment serviceEnvironment; private final ServiceEnvironmentConfig serviceEnvironmentConfig; private final String userAgent; - private final TrustNewIdentity trustNewIdentity; + private final Settings settings; private final AccountsStore accountsStore; public SignalAccountFiles( final File settingsPath, final ServiceEnvironment serviceEnvironment, final String userAgent, - final TrustNewIdentity trustNewIdentity + final Settings settings ) throws IOException { this.pathConfig = PathConfig.createDefault(settingsPath); this.serviceEnvironment = serviceEnvironment; this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(this.serviceEnvironment, userAgent); this.userAgent = userAgent; - this.trustNewIdentity = trustNewIdentity; + this.settings = settings; this.accountsStore = new AccountsStore(pathConfig.dataPath(), serviceEnvironment, accountPath -> { if (accountPath == null || !SignalAccount.accountFileExists(pathConfig.dataPath(), accountPath)) { return null; } try { - return SignalAccount.load(pathConfig.dataPath(), accountPath, false, trustNewIdentity); + return SignalAccount.load(pathConfig.dataPath(), accountPath, false, settings); } catch (Exception e) { return null; } @@ -81,7 +85,8 @@ public class SignalAccountFiles { } private Manager initManager( - String number, String accountPath + String number, + String accountPath ) throws IOException, NotRegisteredException, AccountCheckException { if (accountPath == null) { throw new NotRegisteredException(); @@ -90,7 +95,7 @@ public class SignalAccountFiles { throw new NotRegisteredException(); } - var account = SignalAccount.load(pathConfig.dataPath(), accountPath, true, trustNewIdentity); + var account = SignalAccount.load(pathConfig.dataPath(), accountPath, true, settings); if (!number.equals(account.getNumber())) { account.close(); throw new IOException("Number in account file doesn't match expected number: " + account.getNumber()); @@ -148,15 +153,14 @@ public class SignalAccountFiles { } public RegistrationManager initRegistrationManager( - String number, Consumer newManagerListener + String number, + Consumer newManagerListener ) throws IOException { final var accountPath = accountsStore.getPathByNumber(number); if (accountPath == null || !SignalAccount.accountFileExists(pathConfig.dataPath(), accountPath)) { final var newAccountPath = accountPath == null ? accountsStore.addAccount(number, null) : accountPath; var aciIdentityKey = KeyUtils.generateIdentityKeyPair(); var pniIdentityKey = KeyUtils.generateIdentityKeyPair(); - var registrationId = KeyHelper.generateRegistrationId(false); - var pniRegistrationId = KeyHelper.generateRegistrationId(false); var profileKey = KeyUtils.createProfileKey(); var account = SignalAccount.create(pathConfig.dataPath(), @@ -165,10 +169,9 @@ public class SignalAccountFiles { serviceEnvironment, aciIdentityKey, pniIdentityKey, - registrationId, - pniRegistrationId, profileKey, - trustNewIdentity); + settings); + account.initDatabase(); return new RegistrationManagerImpl(account, pathConfig, @@ -178,11 +181,12 @@ public class SignalAccountFiles { new AccountFileUpdaterImpl(accountsStore, newAccountPath)); } - var account = SignalAccount.load(pathConfig.dataPath(), accountPath, true, trustNewIdentity); + var account = SignalAccount.load(pathConfig.dataPath(), accountPath, true, settings); if (!number.equals(account.getNumber())) { account.close(); throw new IOException("Number in account file doesn't match expected number: " + account.getNumber()); } + account.initDatabase(); return new RegistrationManagerImpl(account, pathConfig,