mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-28 18:10:38 +00:00
Update libsignal-service
This commit is contained in:
parent
69a9b30732
commit
db2182aa7d
10 changed files with 94 additions and 30 deletions
|
@ -30,7 +30,8 @@ public class ServiceConfig {
|
|||
public static AccountAttributes.Capabilities getCapabilities(boolean isPrimaryDevice) {
|
||||
final var deleteSync = !isPrimaryDevice;
|
||||
final var storageEncryptionV2 = !isPrimaryDevice;
|
||||
return new AccountAttributes.Capabilities(true, deleteSync, true, storageEncryptionV2);
|
||||
final var attachmentBackfill = !isPrimaryDevice;
|
||||
return new AccountAttributes.Capabilities(true, deleteSync, true, storageEncryptionV2, attachmentBackfill);
|
||||
}
|
||||
|
||||
public static ServiceEnvironmentConfig getServiceEnvironmentConfig(
|
||||
|
|
|
@ -11,17 +11,19 @@ import org.signal.libsignal.protocol.state.PreKeyRecord;
|
|||
import org.signal.libsignal.protocol.state.SignedPreKeyRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.NetworkResultUtil;
|
||||
import org.whispersystems.signalservice.api.account.PreKeyUpload;
|
||||
import org.whispersystems.signalservice.api.keys.OneTimePreKeyCounts;
|
||||
import org.whispersystems.signalservice.api.push.ServiceIdType;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
import org.whispersystems.signalservice.internal.push.OneTimePreKeyCounts;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.asamk.signal.manager.config.ServiceConfig.PREKEY_STALE_AGE;
|
||||
import static org.asamk.signal.manager.config.ServiceConfig.SIGNED_PREKEY_ROTATE_AGE;
|
||||
import static org.asamk.signal.manager.util.Utils.handleResponseException;
|
||||
|
||||
public class PreKeyHelper {
|
||||
|
||||
|
@ -82,7 +84,7 @@ public class PreKeyHelper {
|
|||
) throws IOException {
|
||||
OneTimePreKeyCounts preKeyCounts;
|
||||
try {
|
||||
preKeyCounts = dependencies.getAccountManager().getPreKeyCounts(serviceIdType);
|
||||
preKeyCounts = handleResponseException(dependencies.getKeysApi().getAvailablePreKeyCounts(serviceIdType));
|
||||
} catch (AuthorizationFailedException e) {
|
||||
logger.debug("Failed to get pre key count, ignoring: " + e.getClass().getSimpleName());
|
||||
preKeyCounts = new OneTimePreKeyCounts(0, 0);
|
||||
|
@ -143,7 +145,7 @@ public class PreKeyHelper {
|
|||
kyberPreKeyRecords);
|
||||
var needsReset = false;
|
||||
try {
|
||||
dependencies.getAccountManager().setPreKeys(preKeyUpload);
|
||||
NetworkResultUtil.toPreKeysLegacy(dependencies.getKeysApi().setPreKeys(preKeyUpload));
|
||||
try {
|
||||
if (preKeyRecords != null) {
|
||||
account.addPreKeys(serviceIdType, preKeyRecords);
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.signal.libsignal.zkgroup.profiles.ExpiringProfileKeyCredential;
|
|||
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.NetworkResultUtil;
|
||||
import org.whispersystems.signalservice.api.crypto.SealedSenderAccess;
|
||||
import org.whispersystems.signalservice.api.profiles.AvatarUploadParams;
|
||||
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
|
||||
|
@ -196,9 +197,10 @@ public final class ProfileHelper {
|
|||
: avatar == null ? AvatarUploadParams.unchanged(true) : AvatarUploadParams.unchanged(false);
|
||||
final var paymentsAddress = Optional.ofNullable(newProfile.getMobileCoinAddress())
|
||||
.map(address -> PaymentUtils.signPaymentsAddress(address,
|
||||
account.getAciIdentityKeyPair().getPrivateKey()));
|
||||
account.getAciIdentityKeyPair().getPrivateKey()))
|
||||
.orElse(null);
|
||||
logger.debug("Uploading new profile");
|
||||
final var avatarPath = dependencies.getAccountManager()
|
||||
final var avatarPath = NetworkResultUtil.toSetProfileLegacy(dependencies.getProfileApi()
|
||||
.setVersionedProfile(account.getAci(),
|
||||
account.getProfileKey(),
|
||||
newProfile.getInternalServiceName(),
|
||||
|
@ -208,9 +210,9 @@ public final class ProfileHelper {
|
|||
avatarUploadParams,
|
||||
List.of(/* TODO implement support for badges */),
|
||||
account.getConfigurationStore().getPhoneNumberSharingMode()
|
||||
== PhoneNumberSharingMode.EVERYBODY);
|
||||
== PhoneNumberSharingMode.EVERYBODY));
|
||||
if (!avatarUploadParams.keepTheSame) {
|
||||
builder.withAvatarUrlPath(avatarPath.orElse(null));
|
||||
builder.withAvatarUrlPath(avatarPath);
|
||||
}
|
||||
newProfile = builder.build();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.asamk.signal.manager.util.Utils.handleResponseException;
|
||||
|
||||
public class UnidentifiedAccessHelper {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(UnidentifiedAccessHelper.class);
|
||||
|
@ -109,7 +111,8 @@ public class UnidentifiedAccessHelper {
|
|||
return privacySenderCertificate.getSerialized();
|
||||
}
|
||||
try {
|
||||
final var certificate = dependencies.getAccountManager().getSenderCertificateForPhoneNumberPrivacy();
|
||||
final var certificate = handleResponseException(dependencies.getCertificateApi()
|
||||
.getSenderCertificateForPhoneNumberPrivacy());
|
||||
privacySenderCertificate = new SenderCertificate(certificate);
|
||||
return certificate;
|
||||
} catch (IOException | InvalidCertificateException e) {
|
||||
|
@ -125,7 +128,7 @@ public class UnidentifiedAccessHelper {
|
|||
return senderCertificate.getSerialized();
|
||||
}
|
||||
try {
|
||||
final var certificate = dependencies.getAccountManager().getSenderCertificate();
|
||||
final var certificate = handleResponseException(dependencies.getCertificateApi().getSenderCertificate());
|
||||
this.senderCertificate = new SenderCertificate(certificate);
|
||||
return certificate;
|
||||
} catch (IOException | InvalidCertificateException e) {
|
||||
|
|
|
@ -14,12 +14,17 @@ import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
|||
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
||||
import org.whispersystems.signalservice.api.SignalSessionLock;
|
||||
import org.whispersystems.signalservice.api.account.AccountApi;
|
||||
import org.whispersystems.signalservice.api.attachment.AttachmentApi;
|
||||
import org.whispersystems.signalservice.api.cds.CdsApi;
|
||||
import org.whispersystems.signalservice.api.certificate.CertificateApi;
|
||||
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
|
||||
import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Api;
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
||||
import org.whispersystems.signalservice.api.keys.KeysApi;
|
||||
import org.whispersystems.signalservice.api.link.LinkDeviceApi;
|
||||
import org.whispersystems.signalservice.api.message.MessageApi;
|
||||
import org.whispersystems.signalservice.api.profiles.ProfileApi;
|
||||
import org.whispersystems.signalservice.api.push.ServiceIdType;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.ratelimit.RateLimitChallengeApi;
|
||||
|
@ -68,6 +73,10 @@ public class SignalDependencies {
|
|||
private RegistrationApi registrationApi;
|
||||
private LinkDeviceApi linkDeviceApi;
|
||||
private StorageServiceApi storageServiceApi;
|
||||
private CertificateApi certificateApi;
|
||||
private AttachmentApi attachmentApi;
|
||||
private MessageApi messageApi;
|
||||
private KeysApi keysApi;
|
||||
private GroupsV2Operations groupsV2Operations;
|
||||
private ClientZkOperations clientZkOperations;
|
||||
|
||||
|
@ -80,6 +89,7 @@ public class SignalDependencies {
|
|||
|
||||
private List<SecureValueRecovery> secureValueRecovery;
|
||||
private ProfileService profileService;
|
||||
private ProfileApi profileApi;
|
||||
|
||||
SignalDependencies(
|
||||
final ServiceEnvironmentConfig serviceEnvironmentConfig,
|
||||
|
@ -174,7 +184,8 @@ public class SignalDependencies {
|
|||
|
||||
public SignalServiceAccountManager getAccountManager() {
|
||||
return getOrCreate(() -> accountManager,
|
||||
() -> accountManager = new SignalServiceAccountManager(getAccountApi(),
|
||||
() -> accountManager = new SignalServiceAccountManager(getAuthenticatedSignalWebSocket(),
|
||||
getAccountApi(),
|
||||
getPushServiceSocket(),
|
||||
getGroupsV2Operations()));
|
||||
}
|
||||
|
@ -231,6 +242,27 @@ public class SignalDependencies {
|
|||
return new StorageServiceRepository(getStorageServiceApi());
|
||||
}
|
||||
|
||||
public CertificateApi getCertificateApi() {
|
||||
return getOrCreate(() -> certificateApi,
|
||||
() -> certificateApi = new CertificateApi(getAuthenticatedSignalWebSocket()));
|
||||
}
|
||||
|
||||
public AttachmentApi getAttachmentApi() {
|
||||
return getOrCreate(() -> attachmentApi,
|
||||
() -> attachmentApi = new AttachmentApi(getAuthenticatedSignalWebSocket(), getPushServiceSocket()));
|
||||
}
|
||||
|
||||
public MessageApi getMessageApi() {
|
||||
return getOrCreate(() -> messageApi,
|
||||
() -> messageApi = new MessageApi(getAuthenticatedSignalWebSocket(),
|
||||
getUnauthenticatedSignalWebSocket()));
|
||||
}
|
||||
|
||||
public KeysApi getKeysApi() {
|
||||
return getOrCreate(() -> keysApi,
|
||||
() -> keysApi = new KeysApi(getAuthenticatedSignalWebSocket(), getUnauthenticatedSignalWebSocket()));
|
||||
}
|
||||
|
||||
public GroupsV2Operations getGroupsV2Operations() {
|
||||
return getOrCreate(() -> groupsV2Operations,
|
||||
() -> groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
|
||||
|
@ -289,8 +321,9 @@ public class SignalDependencies {
|
|||
() -> messageSender = new SignalServiceMessageSender(getPushServiceSocket(),
|
||||
dataStore,
|
||||
sessionLock,
|
||||
getAuthenticatedSignalWebSocket(),
|
||||
getUnauthenticatedSignalWebSocket(),
|
||||
getAttachmentApi(),
|
||||
getMessageApi(),
|
||||
getKeysApi(),
|
||||
Optional.empty(),
|
||||
executor,
|
||||
ServiceConfig.MAX_ENVELOPE_SIZE));
|
||||
|
@ -304,10 +337,14 @@ public class SignalDependencies {
|
|||
.toList());
|
||||
}
|
||||
|
||||
public ProfileApi getProfileApi() {
|
||||
return getOrCreate(() -> profileApi,
|
||||
() -> profileApi = new ProfileApi(getAuthenticatedSignalWebSocket(), getPushServiceSocket()));
|
||||
}
|
||||
|
||||
public ProfileService getProfileService() {
|
||||
return getOrCreate(() -> profileService,
|
||||
() -> profileService = new ProfileService(getClientZkProfileOperations(),
|
||||
getMessageReceiver(),
|
||||
getAuthenticatedSignalWebSocket(),
|
||||
getUnauthenticatedSignalWebSocket()));
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.signal.libsignal.protocol.fingerprint.NumericFingerprintGenerator;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.NetworkResult;
|
||||
import org.whispersystems.signalservice.api.NetworkResultUtil;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||
|
||||
|
@ -154,19 +155,7 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static <T> T handleResponseException(final NetworkResult<T> response) throws IOException {
|
||||
final var throwableOptional = response.getCause();
|
||||
if (throwableOptional != null) {
|
||||
if (throwableOptional instanceof IOException ioException) {
|
||||
throw ioException;
|
||||
} else {
|
||||
throw new IOException(throwableOptional);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return response.successOrThrow();
|
||||
} catch (Throwable e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return NetworkResultUtil.toBasicLegacy(response);
|
||||
}
|
||||
|
||||
public static ByteString firstNonEmpty(ByteString... strings) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue