X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/626406a43c169105c3485749249ffbfd715e3441..942999b7b4beebf4519eed9b216587519b47e6c6:/lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java diff --git a/lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java b/lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java index 970a6741..244a110f 100644 --- a/lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java +++ b/lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java @@ -3,6 +3,7 @@ package org.asamk.signal.manager; import org.asamk.signal.manager.config.ServiceConfig; import org.asamk.signal.manager.config.ServiceEnvironmentConfig; import org.signal.libsignal.metadata.certificate.CertificateValidator; +import org.signal.zkgroup.profiles.ClientZkProfileOperations; import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.KeyBackupService; import org.whispersystems.signalservice.api.SignalServiceAccountManager; @@ -17,9 +18,9 @@ import org.whispersystems.signalservice.api.groupsv2.GroupsV2Api; import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.services.ProfileService; +import org.whispersystems.signalservice.api.util.CredentialsProvider; import org.whispersystems.signalservice.api.util.UptimeSleepTimer; import org.whispersystems.signalservice.api.websocket.WebSocketFactory; -import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider; import org.whispersystems.signalservice.internal.websocket.WebSocketConnection; import java.util.concurrent.ExecutorService; @@ -33,7 +34,7 @@ public class SignalDependencies { private final ServiceEnvironmentConfig serviceEnvironmentConfig; private final String userAgent; - private final DynamicCredentialsProvider credentialsProvider; + private final CredentialsProvider credentialsProvider; private final SignalServiceDataStore dataStore; private final ExecutorService executor; private final SignalSessionLock sessionLock; @@ -51,10 +52,10 @@ public class SignalDependencies { private ProfileService profileService; private SignalServiceCipher cipher; - public SignalDependencies( + SignalDependencies( final ServiceEnvironmentConfig serviceEnvironmentConfig, final String userAgent, - final DynamicCredentialsProvider credentialsProvider, + final CredentialsProvider credentialsProvider, final SignalServiceDataStore dataStore, final ExecutorService executor, final SignalSessionLock sessionLock @@ -67,6 +68,15 @@ public class SignalDependencies { this.sessionLock = sessionLock; } + public void resetAfterAddressChange() { + this.messageSender = null; + this.cipher = null; + } + + public ServiceEnvironmentConfig getServiceEnvironmentConfig() { + return serviceEnvironmentConfig; + } + public SignalServiceAccountManager getAccountManager() { return getOrCreate(() -> accountManager, () -> accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(), @@ -76,6 +86,17 @@ public class SignalDependencies { ServiceConfig.AUTOMATIC_NETWORK_RETRY)); } + public SignalServiceAccountManager createUnauthenticatedAccountManager(String number, String password) { + return new SignalServiceAccountManager(getServiceEnvironmentConfig().getSignalServiceConfiguration(), + null, + null, + number, + SignalServiceAddress.DEFAULT_DEVICE_ID, + password, + userAgent, + ServiceConfig.AUTOMATIC_NETWORK_RETRY); + } + public GroupsV2Api getGroupsV2Api() { return getOrCreate(() -> groupsV2Api, () -> groupsV2Api = getAccountManager().getGroupsV2Api()); } @@ -93,6 +114,11 @@ public class SignalDependencies { : null); } + private ClientZkProfileOperations getClientZkProfileOperations() { + final var clientZkOperations = getClientZkOperations(); + return clientZkOperations == null ? null : clientZkOperations.getProfileOperations(); + } + public SignalWebSocket getSignalWebSocket() { return getOrCreate(() -> signalWebSocket, () -> { final var timer = new UptimeSleepTimer(); @@ -126,7 +152,7 @@ public class SignalDependencies { () -> messageReceiver = new SignalServiceMessageReceiver(serviceEnvironmentConfig.getSignalServiceConfiguration(), credentialsProvider, userAgent, - getClientZkOperations().getProfileOperations(), + getClientZkProfileOperations(), ServiceConfig.AUTOMATIC_NETWORK_RETRY)); } @@ -139,7 +165,7 @@ public class SignalDependencies { userAgent, getSignalWebSocket(), Optional.absent(), - getClientZkOperations().getProfileOperations(), + getClientZkProfileOperations(), executor, ServiceConfig.MAX_ENVELOPE_SIZE, ServiceConfig.AUTOMATIC_NETWORK_RETRY)); @@ -156,7 +182,7 @@ public class SignalDependencies { public ProfileService getProfileService() { return getOrCreate(() -> profileService, - () -> profileService = new ProfileService(getClientZkOperations().getProfileOperations(), + () -> profileService = new ProfileService(getClientZkProfileOperations(), getMessageReceiver(), getSignalWebSocket())); } @@ -164,8 +190,9 @@ public class SignalDependencies { public SignalServiceCipher getCipher() { return getOrCreate(() -> cipher, () -> { final var certificateValidator = new CertificateValidator(serviceEnvironmentConfig.getUnidentifiedSenderTrustRoot()); - final var address = new SignalServiceAddress(credentialsProvider.getUuid(), credentialsProvider.getE164()); - cipher = new SignalServiceCipher(address, dataStore, sessionLock, certificateValidator); + final var address = new SignalServiceAddress(credentialsProvider.getAci(), credentialsProvider.getE164()); + final var deviceId = credentialsProvider.getDeviceId(); + cipher = new SignalServiceCipher(address, deviceId, dataStore.aci(), sessionLock, certificateValidator); }); }