Remove server-side tracking of "supports SMS." Nobody does!

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-06-17 16:45:23 -07:00
parent 53bdd946d6
commit 75ee398633
16 changed files with 37 additions and 78 deletions

View File

@ -285,7 +285,6 @@ public class AccountController {
Account account = new Account();
account.setNumber(number);
account.setSupportsSms(accountAttributes.getSupportsSms());
account.addDevice(device);
accounts.create(account);

View File

@ -150,7 +150,7 @@ public class FederationControllerV1 extends FederationController {
for (Account account : accountList) {
byte[] token = Util.getContactToken(account.getNumber());
ClientContact clientContact = new ClientContact(token, null, account.getSupportsSms());
ClientContact clientContact = new ClientContact(token, null);
if (!account.isActive()) {
clientContact.setInactive(true);

View File

@ -25,9 +25,6 @@ public class AccountAttributes {
@NotEmpty
private String signalingKey;
@JsonProperty
private boolean supportsSms;
@JsonProperty
private boolean fetchesMessages;
@ -36,9 +33,8 @@ public class AccountAttributes {
public AccountAttributes() {}
public AccountAttributes(String signalingKey, boolean supportsSms, boolean fetchesMessages, int registrationId) {
public AccountAttributes(String signalingKey, boolean fetchesMessages, int registrationId) {
this.signalingKey = signalingKey;
this.supportsSms = supportsSms;
this.fetchesMessages = fetchesMessages;
this.registrationId = registrationId;
}
@ -47,10 +43,6 @@ public class AccountAttributes {
return signalingKey;
}
public boolean getSupportsSms() {
return supportsSms;
}
public boolean getFetchesMessages() {
return fetchesMessages;
}

View File

@ -34,12 +34,10 @@ public class ClientContact {
private String relay;
private boolean inactive;
private boolean supportsSms;
public ClientContact(byte[] token, String relay, boolean supportsSms) {
this.token = token;
this.relay = relay;
this.supportsSms = supportsSms;
public ClientContact(byte[] token, String relay) {
this.token = token;
this.relay = relay;
}
public ClientContact() {}
@ -56,10 +54,6 @@ public class ClientContact {
this.relay = relay;
}
public boolean isSupportsSms() {
return supportsSms;
}
public boolean isInactive() {
return inactive;
}
@ -81,7 +75,6 @@ public class ClientContact {
return
Arrays.equals(this.token, that.token) &&
this.supportsSms == that.supportsSms &&
this.inactive == that.inactive &&
(this.relay == null ? (that.relay == null) : this.relay.equals(that.relay));
}

View File

@ -32,9 +32,6 @@ public class Account {
@JsonProperty
private String number;
@JsonProperty
private boolean supportsSms;
@JsonProperty
private Set<Device> devices = new HashSet<>();
@ -47,10 +44,9 @@ public class Account {
public Account() {}
@VisibleForTesting
public Account(String number, boolean supportsSms, Set<Device> devices) {
this.number = number;
this.supportsSms = supportsSms;
this.devices = devices;
public Account(String number, Set<Device> devices) {
this.number = number;
this.devices = devices;
}
public Optional<Device> getAuthenticatedDevice() {
@ -69,14 +65,6 @@ public class Account {
return number;
}
public boolean getSupportsSms() {
return supportsSms;
}
public void setSupportsSms(boolean supportsSms) {
this.supportsSms = supportsSms;
}
public void addDevice(Device device) {
this.devices.remove(device);
this.devices.add(device);

View File

@ -100,7 +100,7 @@ public class AccountsManager {
private void updateDirectory(Account account) {
if (account.isActive()) {
byte[] token = Util.getContactToken(account.getNumber());
ClientContact clientContact = new ClientContact(token, null, account.getSupportsSms());
ClientContact clientContact = new ClientContact(token, null);
directory.add(clientContact);
} else {
directory.remove(account.getNumber());

View File

@ -72,7 +72,7 @@ public class DirectoryManager {
}
public void add(ClientContact contact) {
TokenValue tokenValue = new TokenValue(contact.getRelay(), contact.isSupportsSms());
TokenValue tokenValue = new TokenValue(contact.getRelay());
try (Jedis jedis = redisPool.getResource()) {
jedis.hset(DIRECTORY_KEY, contact.getToken(), objectMapper.writeValueAsBytes(tokenValue));
@ -84,7 +84,7 @@ public class DirectoryManager {
public void add(BatchOperationHandle handle, ClientContact contact) {
try {
Pipeline pipeline = handle.pipeline;
TokenValue tokenValue = new TokenValue(contact.getRelay(), contact.isSupportsSms());
TokenValue tokenValue = new TokenValue(contact.getRelay());
pipeline.hset(DIRECTORY_KEY, contact.getToken(), objectMapper.writeValueAsBytes(tokenValue));
} catch (JsonProcessingException e) {
@ -106,7 +106,7 @@ public class DirectoryManager {
}
TokenValue tokenValue = objectMapper.readValue(result, TokenValue.class);
return Optional.of(new ClientContact(token, tokenValue.relay, tokenValue.supportsSms));
return Optional.of(new ClientContact(token, tokenValue.relay));
} catch (IOException e) {
logger.warn("JSON Error", e);
return Optional.absent();
@ -133,7 +133,7 @@ public class DirectoryManager {
try {
if (pair.second().get() != null) {
TokenValue tokenValue = objectMapper.readValue(pair.second().get(), TokenValue.class);
ClientContact clientContact = new ClientContact(pair.first(), tokenValue.relay, tokenValue.supportsSms);
ClientContact clientContact = new ClientContact(pair.first(), tokenValue.relay);
results.add(clientContact);
}
@ -175,14 +175,10 @@ public class DirectoryManager {
@JsonProperty(value = "r")
private String relay;
@JsonProperty(value = "s")
private boolean supportsSms;
public TokenValue() {}
public TokenValue(String relay, boolean supportsSms) {
this.relay = relay;
this.supportsSms = supportsSms;
public TokenValue(String relay) {
this.relay = relay;
}
}
@ -205,7 +201,7 @@ public class DirectoryManager {
}
TokenValue tokenValue = objectMapper.readValue(result, TokenValue.class);
return Optional.of(new ClientContact(token, tokenValue.relay, tokenValue.supportsSms));
return Optional.of(new ClientContact(token, tokenValue.relay));
}
}

View File

@ -73,7 +73,7 @@ public class DirectoryUpdater {
for (Account account : accounts) {
if (account.isActive()) {
byte[] token = Util.getContactToken(account.getNumber());
ClientContact clientContact = new ClientContact(token, null, account.getSupportsSms());
ClientContact clientContact = new ClientContact(token, null);
directory.add(batchOperation, clientContact);
contactsAdded++;

View File

@ -83,7 +83,7 @@ public class AccountControllerTest {
ClientResponse response =
resources.client().resource(String.format("/v1/accounts/code/%s", "1234"))
.header("Authorization", AuthHelper.getAuthHeader(SENDER, "bar"))
.entity(new AccountAttributes("keykeykeykey", false, false, 2222))
.entity(new AccountAttributes("keykeykeykey", false, 2222))
.type(MediaType.APPLICATION_JSON_TYPE)
.put(ClientResponse.class);
@ -97,7 +97,7 @@ public class AccountControllerTest {
ClientResponse response =
resources.client().resource(String.format("/v1/accounts/code/%s", "1111"))
.header("Authorization", AuthHelper.getAuthHeader(SENDER, "bar"))
.entity(new AccountAttributes("keykeykeykey", false, false, 3333))
.entity(new AccountAttributes("keykeykeykey", false, 3333))
.type(MediaType.APPLICATION_JSON_TYPE)
.put(ClientResponse.class);
@ -115,7 +115,7 @@ public class AccountControllerTest {
ClientResponse response =
resources.client().resource(String.format("/v1/accounts/token/%s", token))
.header("Authorization", AuthHelper.getAuthHeader(SENDER, "bar"))
.entity(new AccountAttributes("keykeykeykey", false, false, 4444))
.entity(new AccountAttributes("keykeykeykey", false, 4444))
.type(MediaType.APPLICATION_JSON_TYPE)
.put(ClientResponse.class);
@ -133,7 +133,7 @@ public class AccountControllerTest {
ClientResponse response =
resources.client().resource(String.format("/v1/accounts/token/%s", token))
.header("Authorization", AuthHelper.getAuthHeader(SENDER, "bar"))
.entity(new AccountAttributes("keykeykeykey", false, false, 4444))
.entity(new AccountAttributes("keykeykeykey", false, 4444))
.type(MediaType.APPLICATION_JSON_TYPE)
.put(ClientResponse.class);
@ -151,7 +151,7 @@ public class AccountControllerTest {
ClientResponse response =
resources.client().resource(String.format("/v1/accounts/token/%s", token))
.header("Authorization", AuthHelper.getAuthHeader("+14151111111", "bar"))
.entity(new AccountAttributes("keykeykeykey", false, false, 4444))
.entity(new AccountAttributes("keykeykeykey", false, 4444))
.type(MediaType.APPLICATION_JSON_TYPE)
.put(ClientResponse.class);
@ -169,7 +169,7 @@ public class AccountControllerTest {
ClientResponse response =
resources.client().resource(String.format("/v1/accounts/token/%s", token))
.header("Authorization", AuthHelper.getAuthHeader(SENDER, "bar"))
.entity(new AccountAttributes("keykeykeykey", false, false, 4444))
.entity(new AccountAttributes("keykeykeykey", false, 4444))
.type(MediaType.APPLICATION_JSON_TYPE)
.put(ClientResponse.class);

View File

@ -90,7 +90,7 @@ public class DeviceControllerTest {
DeviceResponse response = resources.client().resource("/v1/devices/5678901")
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, "password1"))
.entity(new AccountAttributes("keykeykeykey", false, true, 1234))
.entity(new AccountAttributes("keykeykeykey", false, 1234))
.type(MediaType.APPLICATION_JSON_TYPE)
.put(DeviceResponse.class);

View File

@ -82,8 +82,8 @@ public class FederatedControllerTest {
add(new Device(2, "foo", "bar", "baz", "isgcm", null, null, false, 333, null, System.currentTimeMillis()));
}};
Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, false, singleDeviceList);
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, false, multiDeviceList);
Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, singleDeviceList);
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, multiDeviceList);
when(accountsManager.get(eq(SINGLE_DEVICE_RECIPIENT))).thenReturn(Optional.of(singleDeviceAccount));
when(accountsManager.get(eq(MULTI_DEVICE_RECIPIENT))).thenReturn(Optional.of(multiDeviceAccount));

View File

@ -78,8 +78,8 @@ public class MessageControllerTest {
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);
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, false, multiDeviceList);
Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, singleDeviceList);
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, multiDeviceList);
when(accountsManager.get(eq(SINGLE_DEVICE_RECIPIENT))).thenReturn(Optional.of(singleDeviceAccount));
when(accountsManager.get(eq(MULTI_DEVICE_RECIPIENT))).thenReturn(Optional.of(multiDeviceAccount));

View File

@ -55,8 +55,8 @@ public class ReceiptControllerTest {
add(new Device(2, "foo", "bar", "baz", "isgcm", null, null, false, 333, null, System.currentTimeMillis()));
}};
Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, false, singleDeviceList);
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, false, multiDeviceList);
Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, singleDeviceList);
Account multiDeviceAccount = new Account(MULTI_DEVICE_RECIPIENT, multiDeviceList);
when(accountsManager.get(eq(SINGLE_DEVICE_RECIPIENT))).thenReturn(Optional.of(singleDeviceAccount));
when(accountsManager.get(eq(MULTI_DEVICE_RECIPIENT))).thenReturn(Optional.of(multiDeviceAccount));

View File

@ -17,9 +17,9 @@ public class ClientContactTest {
@Test
public void serializeToJSON() throws Exception {
byte[] token = Util.getContactToken("+14152222222");
ClientContact contact = new ClientContact(token, null, false);
ClientContact contactWithRelay = new ClientContact(token, "whisper", false);
ClientContact contactWithRelaySms = new ClientContact(token, "whisper", true );
ClientContact contact = new ClientContact(token, null);
ClientContact contactWithRelay = new ClientContact(token, "whisper");
ClientContact contactWithRelaySms = new ClientContact(token, "whisper");
assertThat("Basic Contact Serialization works",
asJson(contact),
@ -28,19 +28,15 @@ public class ClientContactTest {
assertThat("Contact Relay Serialization works",
asJson(contactWithRelay),
is(equalTo(jsonFixture("fixtures/contact.relay.json"))));
assertThat("Contact Relay+SMS Serialization works",
asJson(contactWithRelaySms),
is(equalTo(jsonFixture("fixtures/contact.relay.sms.json"))));
}
@Test
public void deserializeFromJSON() throws Exception {
ClientContact contact = new ClientContact(Util.getContactToken("+14152222222"),
"whisper", true);
"whisper");
assertThat("a ClientContact can be deserialized from JSON",
fromJson(jsonFixture("fixtures/contact.relay.sms.json"), ClientContact.class),
fromJson(jsonFixture("fixtures/contact.relay.json"), ClientContact.class),
is(contact));
}

View File

@ -26,10 +26,10 @@ public class PreKeyTest {
@Test
public void deserializeFromJSONV() throws Exception {
ClientContact contact = new ClientContact(Util.getContactToken("+14152222222"),
"whisper", true);
"whisper");
assertThat("a ClientContact can be deserialized from JSON",
fromJson(jsonFixture("fixtures/contact.relay.sms.json"), ClientContact.class),
fromJson(jsonFixture("fixtures/contact.relay.json"), ClientContact.class),
is(contact));
}

View File

@ -1,5 +0,0 @@
{
"relay" : "whisper",
"supportsSms" : true,
"token" : "BQVVHxMt5zAFXA"
}