X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/aaa6412469c0af93a226ba805e6dbe74b4ea9773..8a31b7f2c153e89532010b9ab58eb045ddfe43fe:/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 f397b534..12eb3d99 100644 --- a/lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java +++ b/lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java @@ -7,11 +7,11 @@ import org.asamk.signal.manager.config.ServiceEnvironment; import org.asamk.signal.manager.config.ServiceEnvironmentConfig; 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; import java.io.File; import java.io.IOException; @@ -27,27 +27,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; } @@ -65,6 +65,9 @@ public class SignalAccountFiles { } catch (NotRegisteredException | IOException | AccountCheckException e) { logger.warn("Ignoring {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName()); return null; + } catch (Throwable e) { + logger.error("Failed to load {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName()); + throw e; } }).filter(Objects::nonNull).toList(); @@ -86,7 +89,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()); @@ -111,6 +114,9 @@ public class SignalAccountFiles { try { manager.checkAccountState(); + } catch (DeprecatedVersionException e) { + manager.close(); + throw new AccountCheckException("signal-cli version is too old for the Signal-Server, please update."); } catch (IOException e) { manager.close(); throw new AccountCheckException("Error while checking account " + number + ": " + e.getMessage(), e); @@ -149,6 +155,7 @@ public class SignalAccountFiles { 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(), @@ -158,8 +165,9 @@ public class SignalAccountFiles { aciIdentityKey, pniIdentityKey, registrationId, + pniRegistrationId, profileKey, - trustNewIdentity); + settings); return new RegistrationManagerImpl(account, pathConfig, @@ -169,7 +177,7 @@ 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());