X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/1856e79a507e97c523f40426e0e30c5c72b50ad7..1d4ed233948eefdd34cd68f2466b3ec7111e4a03:/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 3478239f..b892e935 100644 --- a/lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java +++ b/lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java @@ -3,8 +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.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations; import org.whispersystems.signalservice.api.KeyBackupService; import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.SignalServiceDataStore; @@ -18,11 +17,13 @@ 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.Collection; +import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.function.Supplier; @@ -34,7 +35,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; @@ -52,10 +53,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 @@ -68,6 +69,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(), @@ -77,14 +87,28 @@ 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, + ServiceConfig.GROUP_MAX_SIZE); + } + public GroupsV2Api getGroupsV2Api() { return getOrCreate(() -> groupsV2Api, () -> groupsV2Api = getAccountManager().getGroupsV2Api()); } public GroupsV2Operations getGroupsV2Operations() { return getOrCreate(() -> groupsV2Operations, - () -> groupsV2Operations = capabilities.isGv2() ? new GroupsV2Operations(ClientZkOperations.create( - serviceEnvironmentConfig.getSignalServiceConfiguration())) : null); + () -> groupsV2Operations = capabilities.isGv2() + ? new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()), + ServiceConfig.GROUP_MAX_SIZE) + : null); } private ClientZkOperations getClientZkOperations() { @@ -117,7 +141,7 @@ public class SignalDependencies { public WebSocketConnection createUnidentifiedWebSocket() { return new WebSocketConnection("unidentified", serviceEnvironmentConfig.getSignalServiceConfiguration(), - Optional.absent(), + Optional.empty(), userAgent, healthMonitor); } @@ -144,7 +168,7 @@ public class SignalDependencies { sessionLock, userAgent, getSignalWebSocket(), - Optional.absent(), + Optional.empty(), getClientZkProfileOperations(), executor, ServiceConfig.MAX_ENVELOPE_SIZE, @@ -160,6 +184,17 @@ public class SignalDependencies { 10)); } + public Collection getFallbackKeyBackupServices() { + return serviceEnvironmentConfig.getFallbackKeyBackupConfigs() + .stream() + .map(config -> getAccountManager().getKeyBackupService(ServiceConfig.getIasKeyStore(), + config.getEnclaveName(), + config.getServiceId(), + config.getMrenclave(), + 10)) + .toList(); + } + public ProfileService getProfileService() { return getOrCreate(() -> profileService, () -> profileService = new ProfileService(getClientZkProfileOperations(), @@ -170,8 +205,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); }); }