Require exact device id match on message deliver.
This commit is contained in:
parent
866f8bf1ef
commit
8e763f62f5
|
@ -26,7 +26,7 @@ import org.whispersystems.textsecuregcm.entities.IncomingMessage;
|
||||||
import org.whispersystems.textsecuregcm.entities.IncomingMessageList;
|
import org.whispersystems.textsecuregcm.entities.IncomingMessageList;
|
||||||
import org.whispersystems.textsecuregcm.entities.MessageProtos.OutgoingMessageSignal;
|
import org.whispersystems.textsecuregcm.entities.MessageProtos.OutgoingMessageSignal;
|
||||||
import org.whispersystems.textsecuregcm.entities.MessageResponse;
|
import org.whispersystems.textsecuregcm.entities.MessageResponse;
|
||||||
import org.whispersystems.textsecuregcm.entities.MissingDevices;
|
import org.whispersystems.textsecuregcm.entities.MismatchedDevices;
|
||||||
import org.whispersystems.textsecuregcm.federation.FederatedClient;
|
import org.whispersystems.textsecuregcm.federation.FederatedClient;
|
||||||
import org.whispersystems.textsecuregcm.federation.FederatedClientManager;
|
import org.whispersystems.textsecuregcm.federation.FederatedClientManager;
|
||||||
import org.whispersystems.textsecuregcm.federation.NoSuchPeerException;
|
import org.whispersystems.textsecuregcm.federation.NoSuchPeerException;
|
||||||
|
@ -92,15 +92,15 @@ public class MessageController {
|
||||||
else sendRelayMessage(source, destinationName, messages);
|
else sendRelayMessage(source, destinationName, messages);
|
||||||
} catch (NoSuchUserException e) {
|
} catch (NoSuchUserException e) {
|
||||||
throw new WebApplicationException(Response.status(404).build());
|
throw new WebApplicationException(Response.status(404).build());
|
||||||
} catch (MissingDevicesException e) {
|
} catch (MismatchedDevicesException e) {
|
||||||
throw new WebApplicationException(Response.status(409)
|
throw new WebApplicationException(Response.status(409)
|
||||||
.entity(new MissingDevices(e.getMissingDevices()))
|
.entity(new MismatchedDevices(e.getMissingDevices(),
|
||||||
|
e.getExtraDevices()))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Timed
|
@Timed
|
||||||
@Path("/")
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@ -123,7 +123,7 @@ public class MessageController {
|
||||||
private void sendLocalMessage(Account source,
|
private void sendLocalMessage(Account source,
|
||||||
String destinationName,
|
String destinationName,
|
||||||
IncomingMessageList messages)
|
IncomingMessageList messages)
|
||||||
throws NoSuchUserException, MissingDevicesException, IOException
|
throws NoSuchUserException, MismatchedDevicesException, IOException
|
||||||
{
|
{
|
||||||
Account destination = getDestinationAccount(destinationName);
|
Account destination = getDestinationAccount(destinationName);
|
||||||
|
|
||||||
|
@ -196,23 +196,34 @@ public class MessageController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateCompleteDeviceList(Account account, List<IncomingMessage> messages)
|
private void validateCompleteDeviceList(Account account, List<IncomingMessage> messages)
|
||||||
throws MissingDevicesException
|
throws MismatchedDevicesException
|
||||||
{
|
{
|
||||||
Set<Long> destinationDeviceIds = new HashSet<>();
|
Set<Long> messageDeviceIds = new HashSet<>();
|
||||||
|
Set<Long> accountDeviceIds = new HashSet<>();
|
||||||
|
|
||||||
List<Long> missingDeviceIds = new LinkedList<>();
|
List<Long> missingDeviceIds = new LinkedList<>();
|
||||||
|
List<Long> extraDeviceIds = new LinkedList<>();
|
||||||
|
|
||||||
for (IncomingMessage message : messages) {
|
for (IncomingMessage message : messages) {
|
||||||
destinationDeviceIds.add(message.getDestinationDeviceId());
|
messageDeviceIds.add(message.getDestinationDeviceId());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Device device : account.getDevices()) {
|
for (Device device : account.getDevices()) {
|
||||||
if (!destinationDeviceIds.contains(device.getId())) {
|
accountDeviceIds.add(device.getId());
|
||||||
|
|
||||||
|
if (!messageDeviceIds.contains(device.getId())) {
|
||||||
missingDeviceIds.add(device.getId());
|
missingDeviceIds.add(device.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!missingDeviceIds.isEmpty()) {
|
for (IncomingMessage message : messages) {
|
||||||
throw new MissingDevicesException(missingDeviceIds);
|
if (!accountDeviceIds.contains(message.getDestinationDeviceId())) {
|
||||||
|
extraDeviceIds.add(message.getDestinationDeviceId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!missingDeviceIds.isEmpty() || !extraDeviceIds.isEmpty()) {
|
||||||
|
throw new MismatchedDevicesException(missingDeviceIds, extraDeviceIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.whispersystems.textsecuregcm.controllers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class MismatchedDevicesException extends Exception {
|
||||||
|
|
||||||
|
private final List<Long> missingDevices;
|
||||||
|
private final List<Long> extraDevices;
|
||||||
|
|
||||||
|
public MismatchedDevicesException(List<Long> missingDevices, List<Long> extraDevices) {
|
||||||
|
this.missingDevices = missingDevices;
|
||||||
|
this.extraDevices = extraDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Long> getMissingDevices() {
|
||||||
|
return missingDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Long> getExtraDevices() {
|
||||||
|
return extraDevices;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +0,0 @@
|
||||||
package org.whispersystems.textsecuregcm.controllers;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class MissingDevicesException extends Exception {
|
|
||||||
private final List<Long> missingDevices;
|
|
||||||
|
|
||||||
public MissingDevicesException(List<Long> missingDevices) {
|
|
||||||
this.missingDevices = missingDevices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Long> getMissingDevices() {
|
|
||||||
return missingDevices;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,13 +4,17 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MissingDevices {
|
public class MismatchedDevices {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
public List<Long> missingDevices;
|
public List<Long> missingDevices;
|
||||||
|
|
||||||
public MissingDevices(List<Long> missingDevices) {
|
@JsonProperty
|
||||||
|
public List<Long> extraDevices;
|
||||||
|
|
||||||
|
public MismatchedDevices(List<Long> missingDevices, List<Long> extraDevices) {
|
||||||
this.missingDevices = missingDevices;
|
this.missingDevices = missingDevices;
|
||||||
|
this.extraDevices = extraDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -19,19 +19,11 @@ package org.whispersystems.textsecuregcm.storage;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import net.spy.memcached.MemcachedClient;
|
import net.spy.memcached.MemcachedClient;
|
||||||
import org.whispersystems.textsecuregcm.controllers.MissingDevicesException;
|
|
||||||
import org.whispersystems.textsecuregcm.entities.ClientContact;
|
import org.whispersystems.textsecuregcm.entities.ClientContact;
|
||||||
import org.whispersystems.textsecuregcm.util.Pair;
|
|
||||||
import org.whispersystems.textsecuregcm.util.Util;
|
import org.whispersystems.textsecuregcm.util.Util;
|
||||||
import sun.util.logging.resources.logging_zh_CN;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class AccountsManager {
|
public class AccountsManager {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue