Do a timestamp comparison on unregister events.

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2014-12-03 11:09:01 -08:00
parent ac96f906b3
commit b802994809
3 changed files with 36 additions and 6 deletions

View File

@ -19,6 +19,9 @@ public class UnregisteredEvent {
@Min(1)
private int deviceId;
@JsonProperty
private long timestamp;
public String getRegistrationId() {
return registrationId;
}
@ -30,4 +33,8 @@ public class UnregisteredEvent {
public int getDeviceId() {
return deviceId;
}
public long getTimestamp() {
return timestamp;
}
}

View File

@ -72,8 +72,13 @@ public class FeedbackHandler implements Managed, Runnable {
if (device.isPresent()) {
if (event.getRegistrationId().equals(device.get().getGcmId())) {
logger.warn("GCM Unregister GCM ID matches!");
device.get().setGcmId(null);
accountsManager.update(account.get());
if (device.get().getPushTimestamp() == 0 ||
event.getTimestamp() < device.get().getPushTimestamp())
{
logger.warn("GCM Unregister Timestamp matches!");
device.get().setGcmId(null);
accountsManager.update(account.get());
}
}
}
}
@ -90,8 +95,13 @@ public class FeedbackHandler implements Managed, Runnable {
if (device.isPresent()) {
if (event.getRegistrationId().equals(device.get().getApnId())) {
logger.warn("APN Unregister APN ID matches!");
device.get().setApnId(null);
accountsManager.update(account.get());
if (device.get().getPushTimestamp() == 0 ||
event.getTimestamp() < device.get().getPushTimestamp())
{
logger.warn("APN Unregister timestamp matches!");
device.get().setApnId(null);
accountsManager.update(account.get());
}
}
}
}

View File

@ -22,8 +22,6 @@ import org.whispersystems.textsecuregcm.auth.AuthenticationCredentials;
import org.whispersystems.textsecuregcm.entities.SignedPreKey;
import org.whispersystems.textsecuregcm.util.Util;
import java.io.Serializable;
public class Device {
public static final long MASTER_ID = 1;
@ -46,6 +44,9 @@ public class Device {
@JsonProperty
private String apnId;
@JsonProperty
private long pushTimestamp;
@JsonProperty
private boolean fetchesMessages;
@ -79,6 +80,10 @@ public class Device {
public void setApnId(String apnId) {
this.apnId = apnId;
if (apnId != null) {
this.pushTimestamp = System.currentTimeMillis();
}
}
public String getGcmId() {
@ -87,6 +92,10 @@ public class Device {
public void setGcmId(String gcmId) {
this.gcmId = gcmId;
if (gcmId != null) {
this.pushTimestamp = System.currentTimeMillis();
}
}
public long getId() {
@ -145,4 +154,8 @@ public class Device {
public void setSignedPreKey(SignedPreKey signedPreKey) {
this.signedPreKey = signedPreKey;
}
public long getPushTimestamp() {
return pushTimestamp;
}
}