import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
+import org.whispersystems.signalservice.api.push.ServiceIdType;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.internal.push.Envelope;
import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageException;
SignalServiceContent content = null;
if (!envelope.isReceipt()) {
account.getIdentityKeyStore().setRetryingDecryption(true);
+ final var destination = getDestination(envelope).serviceId();
try {
- final var cipherResult = dependencies.getCipher()
+ final var cipherResult = dependencies.getCipher(destination == null
+ || destination.equals(account.getAci()) ? ServiceIdType.ACI : ServiceIdType.PNI)
.decrypt(envelope.getProto(), envelope.getServerDeliveredTimestamp());
content = validate(envelope.getProto(), cipherResult, envelope.getServerDeliveredTimestamp());
if (content == null) {
// uuid in envelope is sent by server
.ifPresent(serviceId -> account.getRecipientResolver().resolveRecipient(serviceId));
if (!envelope.isReceipt()) {
+ final var destination = getDestination(envelope).serviceId();
try {
- final var cipherResult = dependencies.getCipher()
+ final var cipherResult = dependencies.getCipher(destination == null
+ || destination.equals(account.getAci()) ? ServiceIdType.ACI : ServiceIdType.PNI)
.decrypt(envelope.getProto(), envelope.getServerDeliveredTimestamp());
content = validate(envelope.getProto(), cipherResult, envelope.getServerDeliveredTimestamp());
if (content == null) {
.contains(Profile.Capability.senderKey);
final var isSelfSenderKeyCapable = selfProfile != null && selfProfile.getCapabilities()
.contains(Profile.Capability.senderKey);
- final var destination = getDestination(envelope).serviceId();
if (!isSelf && isSenderSenderKeyCapable && isSelfSenderKeyCapable) {
logger.debug("Received invalid message, requesting message resend.");
actions.add(new SendRetryMessageRequestAction(sender, serviceId, e, envelope, destination));
}
private DeviceAddress getDestination(SignalServiceEnvelope envelope) {
- if (!envelope.hasDestinationUuid()) {
+ final var destination = envelope.getDestinationServiceId();
+ if (destination == null) {
return new DeviceAddress(account.getSelfRecipientId(), account.getAci(), account.getDeviceId());
}
- final var addressOptional = SignalServiceAddress.fromRaw(envelope.getDestinationServiceId(), null);
- if (addressOptional.isEmpty()) {
- return new DeviceAddress(account.getSelfRecipientId(), account.getAci(), account.getDeviceId());
- }
- final var address = addressOptional.get();
- return new DeviceAddress(account.getRecipientResolver().resolveRecipient(address),
- address.getServiceId(),
+ return new DeviceAddress(account.getRecipientResolver().resolveRecipient(destination),
+ destination,
account.getDeviceId());
}
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.push.ServiceIdType;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.services.ProfileService;
import org.whispersystems.signalservice.api.svr.SecureValueRecovery;
private List<SecureValueRecovery> secureValueRecoveryV2;
private ProfileService profileService;
- private SignalServiceCipher cipher;
SignalDependencies(
final ServiceEnvironmentConfig serviceEnvironmentConfig,
this.pushServiceSocket = null;
}
this.messageSender = null;
- this.cipher = null;
getSignalWebSocket().forceNewWebSockets();
}
getSignalWebSocket()));
}
- public SignalServiceCipher getCipher() {
- return getOrCreate(() -> cipher, () -> {
- final var certificateValidator = new CertificateValidator(serviceEnvironmentConfig.unidentifiedSenderTrustRoot());
- final var address = new SignalServiceAddress(credentialsProvider.getAci(), credentialsProvider.getE164());
- final var deviceId = credentialsProvider.getDeviceId();
- cipher = new SignalServiceCipher(address, deviceId, dataStore.aci(), sessionLock, certificateValidator);
- });
+ public SignalServiceCipher getCipher(ServiceIdType serviceIdType) {
+ final var certificateValidator = new CertificateValidator(serviceEnvironmentConfig.unidentifiedSenderTrustRoot());
+ final var address = new SignalServiceAddress(credentialsProvider.getAci(), credentialsProvider.getE164());
+ final var deviceId = credentialsProvider.getDeviceId();
+ return new SignalServiceCipher(address,
+ deviceId,
+ serviceIdType == ServiceIdType.ACI ? dataStore.aci() : dataStore.pni(),
+ sessionLock,
+ certificateValidator);
}
private <T> T getOrCreate(Supplier<T> supplier, Callable creator) {