mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 11:45:28 +00:00
Handle invalid registrationIds during sender key sends.
This commit is contained in:
committed by
Cody Henthorne
parent
f71accea06
commit
45a6894da1
@@ -19,6 +19,7 @@ import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyStore;
|
||||
import org.whispersystems.signalservice.api.SignalServiceDataStore;
|
||||
import org.whispersystems.signalservice.api.SignalServiceSessionStore;
|
||||
import org.whispersystems.signalservice.api.messages.InvalidRegistrationIdException;
|
||||
import org.whispersystems.signalservice.api.push.DistributionId;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -105,7 +106,7 @@ public class SignalProtocolStoreImpl implements SignalServiceDataStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SignalProtocolAddress> getAllAddressesWithActiveSessions(List<String> addressNames) {
|
||||
public Set<SignalProtocolAddress> getAllAddressesWithActiveSessions(List<String> addressNames) throws InvalidRegistrationIdException {
|
||||
return sessionStore.getAllAddressesWithActiveSessions(addressNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
import org.whispersystems.libsignal.protocol.CiphertextMessage;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.signalservice.api.SignalServiceSessionStore;
|
||||
import org.whispersystems.signalservice.api.messages.InvalidRegistrationIdException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -26,7 +27,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
|
||||
private static final Object LOCK = new Object();
|
||||
|
||||
@NonNull private final Context context;
|
||||
@NonNull private final Context context;
|
||||
|
||||
public TextSecureSessionStore(@NonNull Context context) {
|
||||
this.context = context;
|
||||
@@ -101,9 +102,17 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SignalProtocolAddress> getAllAddressesWithActiveSessions(List<String> addressNames) {
|
||||
public Set<SignalProtocolAddress> getAllAddressesWithActiveSessions(List<String> addressNames) throws InvalidRegistrationIdException {
|
||||
synchronized (LOCK) {
|
||||
List<SessionDatabase.SessionRow> rows = DatabaseFactory.getSessionDatabase(context).getAllFor(addressNames);
|
||||
|
||||
boolean hasInvalidRegistrationId = rows.stream()
|
||||
.map(SessionDatabase.SessionRow::getRecord)
|
||||
.anyMatch(record -> !isValidRegistrationId(record.getRemoteRegistrationId()));
|
||||
if (hasInvalidRegistrationId) {
|
||||
throw new InvalidRegistrationIdException();
|
||||
}
|
||||
|
||||
return rows.stream()
|
||||
.filter(row -> isActive(row.getRecord()))
|
||||
.map(row -> new SignalProtocolAddress(row.getAddress(), row.getDeviceId()))
|
||||
@@ -165,4 +174,8 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
record.hasSenderChain() &&
|
||||
record.getSessionVersion() == CiphertextMessage.CURRENT_VERSION;
|
||||
}
|
||||
|
||||
private static boolean isValidRegistrationId(int registrationId) {
|
||||
return (registrationId & 0x3fff) == registrationId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.whispersystems.signalservice.api.crypto.ContentHint;
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
|
||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||
import org.whispersystems.signalservice.api.messages.InvalidRegistrationIdException;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
||||
@@ -237,7 +238,10 @@ public final class GroupSendUtil {
|
||||
Log.w(TAG, "No session. Falling back to legacy sends.", e);
|
||||
legacyTargets.addAll(senderKeyTargets);
|
||||
} catch (InvalidKeyException e) {
|
||||
Log.w(TAG, "Invalid Key. Falling back to legacy sends.", e);
|
||||
Log.w(TAG, "Invalid key. Falling back to legacy sends.", e);
|
||||
legacyTargets.addAll(senderKeyTargets);
|
||||
} catch (InvalidRegistrationIdException e) {
|
||||
Log.w(TAG, "Invalid registrationId. Falling back to legacy sends.", e);
|
||||
legacyTargets.addAll(senderKeyTargets);
|
||||
}
|
||||
}
|
||||
@@ -308,7 +312,7 @@ public final class GroupSendUtil {
|
||||
@NonNull List<SignalServiceAddress> targets,
|
||||
@NonNull List<UnidentifiedAccess> access,
|
||||
boolean isRecipientUpdate)
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException;
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException, InvalidRegistrationIdException;
|
||||
|
||||
@NonNull List<SendMessageResult> sendLegacy(@NonNull SignalServiceMessageSender messageSender,
|
||||
@NonNull List<SignalServiceAddress> targets,
|
||||
@@ -355,7 +359,7 @@ public final class GroupSendUtil {
|
||||
@NonNull List<SignalServiceAddress> targets,
|
||||
@NonNull List<UnidentifiedAccess> access,
|
||||
boolean isRecipientUpdate)
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException, InvalidRegistrationIdException
|
||||
{
|
||||
return messageSender.sendGroupDataMessage(distributionId, targets, access, isRecipientUpdate, contentHint, message);
|
||||
}
|
||||
@@ -411,7 +415,7 @@ public final class GroupSendUtil {
|
||||
@NonNull List<SignalServiceAddress> targets,
|
||||
@NonNull List<UnidentifiedAccess> access,
|
||||
boolean isRecipientUpdate)
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException, InvalidRegistrationIdException
|
||||
{
|
||||
messageSender.sendGroupTyping(distributionId, targets, access, message);
|
||||
return targets.stream().map(a -> SendMessageResult.success(a, Collections.emptyList(), true, false, -1, Optional.absent())).collect(Collectors.toList());
|
||||
@@ -465,7 +469,7 @@ public final class GroupSendUtil {
|
||||
@NonNull List<SignalServiceAddress> targets,
|
||||
@NonNull List<UnidentifiedAccess> access,
|
||||
boolean isRecipientUpdate)
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException
|
||||
throws NoSessionException, UntrustedIdentityException, InvalidKeyException, IOException, InvalidRegistrationIdException
|
||||
{
|
||||
return messageSender.sendCallMessage(distributionId, targets, access, message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user