From 456164fc243d6d7a2a81e2282ba23c397096dd55 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 24 Mar 2015 10:12:19 -0700 Subject: [PATCH] Support registering a 'voip' APN ID. // FREEBIE --- .../controllers/AccountController.java | 2 ++ .../entities/ApnRegistrationId.java | 7 +++++++ .../federation/NonLimitedAccount.java | 2 +- .../textsecuregcm/storage/Device.java | 16 ++++++++++++++-- .../controllers/FederatedControllerTest.java | 8 +++----- .../tests/controllers/MessageControllerTest.java | 10 ++++------ .../tests/controllers/ReceiptControllerTest.java | 14 +++----------- 7 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java b/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java index 7ca3b6240..0561a9fbb 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java +++ b/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java @@ -200,6 +200,7 @@ public class AccountController { public void setGcmRegistrationId(@Auth Account account, @Valid GcmRegistrationId registrationId) { Device device = account.getAuthenticatedDevice().get(); device.setApnId(null); + device.setVoipApnId(null); device.setGcmId(registrationId.getGcmRegistrationId()); if (registrationId.isWebSocketChannel()) device.setFetchesMessages(true); @@ -225,6 +226,7 @@ public class AccountController { public void setApnRegistrationId(@Auth Account account, @Valid ApnRegistrationId registrationId) { Device device = account.getAuthenticatedDevice().get(); device.setApnId(registrationId.getApnRegistrationId()); + device.setVoipApnId(registrationId.getVoipRegistrationId()); device.setGcmId(null); device.setFetchesMessages(true); accounts.update(account); diff --git a/src/main/java/org/whispersystems/textsecuregcm/entities/ApnRegistrationId.java b/src/main/java/org/whispersystems/textsecuregcm/entities/ApnRegistrationId.java index 6057236fc..f64a7b73b 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/entities/ApnRegistrationId.java +++ b/src/main/java/org/whispersystems/textsecuregcm/entities/ApnRegistrationId.java @@ -25,7 +25,14 @@ public class ApnRegistrationId { @NotEmpty private String apnRegistrationId; + @JsonProperty + String voipRegistrationId; + public String getApnRegistrationId() { return apnRegistrationId; } + + public String getVoipRegistrationId() { + return voipRegistrationId; + } } diff --git a/src/main/java/org/whispersystems/textsecuregcm/federation/NonLimitedAccount.java b/src/main/java/org/whispersystems/textsecuregcm/federation/NonLimitedAccount.java index 2bcfcd1a9..909b651bc 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/federation/NonLimitedAccount.java +++ b/src/main/java/org/whispersystems/textsecuregcm/federation/NonLimitedAccount.java @@ -40,6 +40,6 @@ public class NonLimitedAccount extends Account { @Override public Optional getAuthenticatedDevice() { - return Optional.of(new Device(deviceId, null, null, null, null, null, false, 0, null, System.currentTimeMillis())); + return Optional.of(new Device(deviceId, null, null, null, null, null, null, false, 0, null, System.currentTimeMillis())); } } diff --git a/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java b/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java index 0554cc8d4..d5190b24a 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java +++ b/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java @@ -46,6 +46,9 @@ public class Device { @JsonProperty private String apnId; + @JsonProperty + private String voipApnId; + @JsonProperty private long pushTimestamp; @@ -65,8 +68,8 @@ public class Device { public Device(long id, String authToken, String salt, String signalingKey, String gcmId, String apnId, - boolean fetchesMessages, int registrationId, - SignedPreKey signedPreKey, long lastSeen) + String voipApnId, boolean fetchesMessages, + int registrationId, SignedPreKey signedPreKey, long lastSeen) { this.id = id; this.authToken = authToken; @@ -74,6 +77,7 @@ public class Device { this.signalingKey = signalingKey; this.gcmId = gcmId; this.apnId = apnId; + this.voipApnId = voipApnId; this.fetchesMessages = fetchesMessages; this.registrationId = registrationId; this.signedPreKey = signedPreKey; @@ -92,6 +96,14 @@ public class Device { } } + public String getVoipApnId() { + return voipApnId; + } + + public void setVoipApnId(String voipApnId) { + this.voipApnId = voipApnId; + } + public void setLastSeen(long lastSeen) { this.lastSeen = lastSeen; } diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/FederatedControllerTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/FederatedControllerTest.java index c4e84bad0..c3cc05c59 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/FederatedControllerTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/FederatedControllerTest.java @@ -4,7 +4,6 @@ package org.whispersystems.textsecuregcm.tests.controllers; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Optional; import com.sun.jersey.api.client.ClientResponse; -import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -29,7 +28,6 @@ import org.whispersystems.textsecuregcm.tests.util.AuthHelper; import javax.ws.rs.core.MediaType; import java.util.HashSet; import java.util.LinkedList; -import java.util.List; import java.util.Set; import io.dropwizard.testing.junit.ResourceTestRule; @@ -72,12 +70,12 @@ public class FederatedControllerTest { @Before public void setup() throws Exception { Set singleDeviceList = new HashSet() {{ - add(new Device(1, "foo", "bar", "baz", "isgcm", null, false, 111, null, System.currentTimeMillis())); + add(new Device(1, "foo", "bar", "baz", "isgcm", null, null, false, 111, null, System.currentTimeMillis())); }}; Set multiDeviceList = new HashSet() {{ - add(new Device(1, "foo", "bar", "baz", "isgcm", null, false, 222, null, System.currentTimeMillis())); - add(new Device(2, "foo", "bar", "baz", "isgcm", null, false, 333, null, System.currentTimeMillis())); + add(new Device(1, "foo", "bar", "baz", "isgcm", null, null, false, 222, null, System.currentTimeMillis())); + add(new Device(2, "foo", "bar", "baz", "isgcm", null, null, false, 333, null, System.currentTimeMillis())); }}; Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, false, singleDeviceList); diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java index 5d648510b..dadd5cd47 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java @@ -6,8 +6,6 @@ import com.sun.jersey.api.client.ClientResponse; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.whispersystems.textsecuregcm.controllers.MessageController; import org.whispersystems.textsecuregcm.entities.IncomingMessageList; import org.whispersystems.textsecuregcm.entities.MessageProtos; @@ -62,13 +60,13 @@ public class MessageControllerTest { @Before public void setup() throws Exception { Set singleDeviceList = new HashSet() {{ - add(new Device(1, "foo", "bar", "baz", "isgcm", null, false, 111, null, System.currentTimeMillis())); + add(new Device(1, "foo", "bar", "baz", "isgcm", null, null, false, 111, null, System.currentTimeMillis())); }}; Set multiDeviceList = new HashSet() {{ - add(new Device(1, "foo", "bar", "baz", "isgcm", null, false, 222, new SignedPreKey(111, "foo", "bar"), System.currentTimeMillis())); - add(new Device(2, "foo", "bar", "baz", "isgcm", null, false, 333, new SignedPreKey(222, "oof", "rab"), System.currentTimeMillis())); - add(new Device(3, "foo", "bar", "baz", "isgcm", null, false, 444, null, System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31))); + add(new Device(1, "foo", "bar", "baz", "isgcm", null, null, false, 222, new SignedPreKey(111, "foo", "bar"), System.currentTimeMillis())); + add(new Device(2, "foo", "bar", "baz", "isgcm", null, null, false, 333, new SignedPreKey(222, "oof", "rab"), System.currentTimeMillis())); + add(new Device(3, "foo", "bar", "baz", "isgcm", null, null, false, 444, null, System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31))); }}; Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, false, singleDeviceList); diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ReceiptControllerTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ReceiptControllerTest.java index bb8fd5839..cd6cfec4b 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ReceiptControllerTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ReceiptControllerTest.java @@ -6,12 +6,9 @@ import com.sun.jersey.api.client.ClientResponse; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.whispersystems.textsecuregcm.controllers.MessageController; import org.whispersystems.textsecuregcm.controllers.ReceiptController; import org.whispersystems.textsecuregcm.entities.MessageProtos; import org.whispersystems.textsecuregcm.federation.FederatedClientManager; -import org.whispersystems.textsecuregcm.limits.RateLimiter; -import org.whispersystems.textsecuregcm.limits.RateLimiters; import org.whispersystems.textsecuregcm.push.PushSender; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; @@ -19,15 +16,10 @@ import org.whispersystems.textsecuregcm.storage.Device; import org.whispersystems.textsecuregcm.tests.util.AuthHelper; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Set; -import java.util.concurrent.TimeUnit; import io.dropwizard.testing.junit.ResourceTestRule; import static org.fest.assertions.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.core.IsEqual.equalTo; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; @@ -51,12 +43,12 @@ public class ReceiptControllerTest { @Before public void setup() throws Exception { Set singleDeviceList = new HashSet() {{ - add(new Device(1, "foo", "bar", "baz", "isgcm", null, false, 111, null, System.currentTimeMillis())); + add(new Device(1, "foo", "bar", "baz", "isgcm", null, null, false, 111, null, System.currentTimeMillis())); }}; Set multiDeviceList = new HashSet() {{ - add(new Device(1, "foo", "bar", "baz", "isgcm", null, false, 222, null, System.currentTimeMillis())); - add(new Device(2, "foo", "bar", "baz", "isgcm", null, false, 333, null, System.currentTimeMillis())); + add(new Device(1, "foo", "bar", "baz", "isgcm", null, null, false, 222, null, System.currentTimeMillis())); + add(new Device(2, "foo", "bar", "baz", "isgcm", null, null, false, 333, null, System.currentTimeMillis())); }}; Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, false, singleDeviceList);