Renamed 'device key' to 'signed prekey'.
This commit is contained in:
parent
06f80c320d
commit
b724ea8d3b
|
@ -130,8 +130,8 @@ public class FederationController {
|
|||
throws IOException
|
||||
{
|
||||
try {
|
||||
return keysControllerV2.getDeviceKey(new NonLimitedAccount("Unknown", -1, peer.getName()),
|
||||
number, device, Optional.<String>absent());
|
||||
return keysControllerV2.getDeviceKeys(new NonLimitedAccount("Unknown", -1, peer.getName()),
|
||||
number, device, Optional.<String>absent());
|
||||
} catch (RateLimitExceededException e) {
|
||||
logger.warn("Rate limiting on federated channel", e);
|
||||
throw new IOException(e);
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.whispersystems.textsecuregcm.controllers;
|
|||
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import com.google.common.base.Optional;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceKey;
|
||||
import org.whispersystems.textsecuregcm.entities.SignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKeyResponseItemV2;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKeyResponseV2;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKeyStateV2;
|
||||
|
@ -66,8 +66,8 @@ public class KeysControllerV2 extends KeysController {
|
|||
Device device = account.getAuthenticatedDevice().get();
|
||||
boolean updateAccount = false;
|
||||
|
||||
if (!preKeys.getDeviceKey().equals(device.getDeviceKey())) {
|
||||
device.setDeviceKey(preKeys.getDeviceKey());
|
||||
if (!preKeys.getSignedPreKey().equals(device.getSignedPreKey())) {
|
||||
device.setSignedPreKey(preKeys.getSignedPreKey());
|
||||
updateAccount = true;
|
||||
}
|
||||
|
||||
|
@ -85,11 +85,11 @@ public class KeysControllerV2 extends KeysController {
|
|||
|
||||
@Timed
|
||||
@PUT
|
||||
@Path("/device")
|
||||
@Path("/signed")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public void setDeviceKey(@Auth Account account, @Valid DeviceKey deviceKey) {
|
||||
public void setSignedKey(@Auth Account account, @Valid SignedPreKey signedPreKey) {
|
||||
Device device = account.getAuthenticatedDevice().get();
|
||||
device.setDeviceKey(deviceKey);
|
||||
device.setSignedPreKey(signedPreKey);
|
||||
accounts.update(account);
|
||||
}
|
||||
|
||||
|
@ -97,10 +97,10 @@ public class KeysControllerV2 extends KeysController {
|
|||
@GET
|
||||
@Path("/{number}/{device_id}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Optional<PreKeyResponseV2> getDeviceKey(@Auth Account account,
|
||||
@PathParam("number") String number,
|
||||
@PathParam("device_id") String deviceId,
|
||||
@QueryParam("relay") Optional<String> relay)
|
||||
public Optional<PreKeyResponseV2> getDeviceKeys(@Auth Account account,
|
||||
@PathParam("number") String number,
|
||||
@PathParam("device_id") String deviceId,
|
||||
@QueryParam("relay") Optional<String> relay)
|
||||
throws RateLimitExceededException
|
||||
{
|
||||
try {
|
||||
|
@ -118,8 +118,8 @@ public class KeysControllerV2 extends KeysController {
|
|||
|
||||
for (Device device : destination.getDevices()) {
|
||||
if (device.isActive() && (deviceId.equals("*") || device.getId() == Long.parseLong(deviceId))) {
|
||||
DeviceKey deviceKey = device.getDeviceKey();
|
||||
PreKeyV2 preKey = null;
|
||||
SignedPreKey signedPreKey = device.getSignedPreKey();
|
||||
PreKeyV2 preKey = null;
|
||||
|
||||
if (targetKeys.getKeys().isPresent()) {
|
||||
for (KeyRecord keyRecord : targetKeys.getKeys().get()) {
|
||||
|
@ -129,8 +129,8 @@ public class KeysControllerV2 extends KeysController {
|
|||
}
|
||||
}
|
||||
|
||||
if (deviceKey != null || preKey != null) {
|
||||
devices.add(new PreKeyResponseItemV2(device.getId(), device.getRegistrationId(), deviceKey, preKey));
|
||||
if (signedPreKey != null || preKey != null) {
|
||||
devices.add(new PreKeyResponseItemV2(device.getId(), device.getRegistrationId(), signedPreKey, preKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,23 +28,23 @@ public class PreKeyResponseItemV2 {
|
|||
private int registrationId;
|
||||
|
||||
@JsonProperty
|
||||
private DeviceKey deviceKey;
|
||||
private SignedPreKey signedPreKey;
|
||||
|
||||
@JsonProperty
|
||||
private PreKeyV2 preKey;
|
||||
|
||||
public PreKeyResponseItemV2() {}
|
||||
|
||||
public PreKeyResponseItemV2(long deviceId, int registrationId, DeviceKey deviceKey, PreKeyV2 preKey) {
|
||||
public PreKeyResponseItemV2(long deviceId, int registrationId, SignedPreKey signedPreKey, PreKeyV2 preKey) {
|
||||
this.deviceId = deviceId;
|
||||
this.registrationId = registrationId;
|
||||
this.deviceKey = deviceKey;
|
||||
this.signedPreKey = signedPreKey;
|
||||
this.preKey = preKey;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public DeviceKey getDeviceKey() {
|
||||
return deviceKey;
|
||||
public SignedPreKey getSignedPreKey() {
|
||||
return signedPreKey;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
@ -35,7 +35,7 @@ public class PreKeyStateV2 {
|
|||
@JsonProperty
|
||||
@NotNull
|
||||
@Valid
|
||||
private DeviceKey deviceKey;
|
||||
private SignedPreKey signedPreKey;
|
||||
|
||||
@JsonProperty
|
||||
@NotNull
|
||||
|
@ -49,9 +49,11 @@ public class PreKeyStateV2 {
|
|||
public PreKeyStateV2() {}
|
||||
|
||||
@VisibleForTesting
|
||||
public PreKeyStateV2(String identityKey, DeviceKey deviceKey, List<PreKeyV2> keys, PreKeyV2 lastResortKey) {
|
||||
public PreKeyStateV2(String identityKey, SignedPreKey signedPreKey,
|
||||
List<PreKeyV2> keys, PreKeyV2 lastResortKey)
|
||||
{
|
||||
this.identityKey = identityKey;
|
||||
this.deviceKey = deviceKey;
|
||||
this.signedPreKey = signedPreKey;
|
||||
this.preKeys = keys;
|
||||
this.lastResortKey = lastResortKey;
|
||||
}
|
||||
|
@ -60,8 +62,8 @@ public class PreKeyStateV2 {
|
|||
return preKeys;
|
||||
}
|
||||
|
||||
public DeviceKey getDeviceKey() {
|
||||
return deviceKey;
|
||||
public SignedPreKey getSignedPreKey() {
|
||||
return signedPreKey;
|
||||
}
|
||||
|
||||
public String getIdentityKey() {
|
||||
|
|
|
@ -5,15 +5,15 @@ import org.hibernate.validator.constraints.NotEmpty;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceKey extends PreKeyV2 implements Serializable {
|
||||
public class SignedPreKey extends PreKeyV2 implements Serializable {
|
||||
|
||||
@JsonProperty
|
||||
@NotEmpty
|
||||
private String signature;
|
||||
|
||||
public DeviceKey() {}
|
||||
public SignedPreKey() {}
|
||||
|
||||
public DeviceKey(long keyId, String publicKey, String signature) {
|
||||
public SignedPreKey(long keyId, String publicKey, String signature) {
|
||||
super(keyId, publicKey);
|
||||
this.signature = signature;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ public class DeviceKey extends PreKeyV2 implements Serializable {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == null || !(object instanceof DeviceKey)) return false;
|
||||
DeviceKey that = (DeviceKey) object;
|
||||
if (object == null || !(object instanceof SignedPreKey)) return false;
|
||||
SignedPreKey that = (SignedPreKey) object;
|
||||
|
||||
if (signature == null) {
|
||||
return super.equals(object) && that.signature == null;
|
|
@ -19,8 +19,7 @@ package org.whispersystems.textsecuregcm.storage;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.whispersystems.textsecuregcm.auth.AuthenticationCredentials;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceKey;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKeyV2;
|
||||
import org.whispersystems.textsecuregcm.entities.SignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -54,14 +53,14 @@ public class Device implements Serializable {
|
|||
private int registrationId;
|
||||
|
||||
@JsonProperty
|
||||
private DeviceKey deviceKey;
|
||||
private SignedPreKey signedPreKey;
|
||||
|
||||
public Device() {}
|
||||
|
||||
public Device(long id, String authToken, String salt,
|
||||
String signalingKey, String gcmId, String apnId,
|
||||
boolean fetchesMessages, int registrationId,
|
||||
DeviceKey deviceKey)
|
||||
SignedPreKey signedPreKey)
|
||||
{
|
||||
this.id = id;
|
||||
this.authToken = authToken;
|
||||
|
@ -71,7 +70,7 @@ public class Device implements Serializable {
|
|||
this.apnId = apnId;
|
||||
this.fetchesMessages = fetchesMessages;
|
||||
this.registrationId = registrationId;
|
||||
this.deviceKey = deviceKey;
|
||||
this.signedPreKey = signedPreKey;
|
||||
}
|
||||
|
||||
public String getApnId() {
|
||||
|
@ -139,11 +138,11 @@ public class Device implements Serializable {
|
|||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
public DeviceKey getDeviceKey() {
|
||||
return deviceKey;
|
||||
public SignedPreKey getSignedPreKey() {
|
||||
return signedPreKey;
|
||||
}
|
||||
|
||||
public void setDeviceKey(DeviceKey deviceKey) {
|
||||
this.deviceKey = deviceKey;
|
||||
public void setSignedPreKey(SignedPreKey signedPreKey) {
|
||||
this.signedPreKey = signedPreKey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Test;
|
|||
import org.mockito.ArgumentCaptor;
|
||||
import org.whispersystems.textsecuregcm.controllers.KeysControllerV1;
|
||||
import org.whispersystems.textsecuregcm.controllers.KeysControllerV2;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceKey;
|
||||
import org.whispersystems.textsecuregcm.entities.SignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKeyCount;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKeyResponseV1;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKeyResponseV2;
|
||||
|
@ -48,9 +48,9 @@ public class KeyControllerTest {
|
|||
private final KeyRecord SAMPLE_KEY4 = new KeyRecord(4, EXISTS_NUMBER, 4, 336, "test6", false );
|
||||
|
||||
|
||||
private final DeviceKey SAMPLE_DEVICE_KEY = new DeviceKey(1111, "foofoo", "sig11");
|
||||
private final DeviceKey SAMPLE_DEVICE_KEY2 = new DeviceKey(2222, "foobar", "sig22");
|
||||
private final DeviceKey SAMPLE_DEVICE_KEY3 = new DeviceKey(3333, "barfoo", "sig33");
|
||||
private final SignedPreKey SAMPLE_SIGNED_KEY = new SignedPreKey(1111, "foofoo", "sig11");
|
||||
private final SignedPreKey SAMPLE_SIGNED_KEY2 = new SignedPreKey(2222, "foobar", "sig22");
|
||||
private final SignedPreKey SAMPLE_SIGNED_KEY3 = new SignedPreKey(3333, "barfoo", "sig33");
|
||||
|
||||
private final Keys keys = mock(Keys.class );
|
||||
private final AccountsManager accounts = mock(AccountsManager.class);
|
||||
|
@ -88,10 +88,10 @@ public class KeyControllerTest {
|
|||
when(sampleDevice2.isActive()).thenReturn(true);
|
||||
when(sampleDevice3.isActive()).thenReturn(false);
|
||||
when(sampleDevice4.isActive()).thenReturn(true);
|
||||
when(sampleDevice.getDeviceKey()).thenReturn(SAMPLE_DEVICE_KEY);
|
||||
when(sampleDevice2.getDeviceKey()).thenReturn(SAMPLE_DEVICE_KEY2);
|
||||
when(sampleDevice3.getDeviceKey()).thenReturn(SAMPLE_DEVICE_KEY3);
|
||||
when(sampleDevice4.getDeviceKey()).thenReturn(null);
|
||||
when(sampleDevice.getSignedPreKey()).thenReturn(SAMPLE_SIGNED_KEY);
|
||||
when(sampleDevice2.getSignedPreKey()).thenReturn(SAMPLE_SIGNED_KEY2);
|
||||
when(sampleDevice3.getSignedPreKey()).thenReturn(SAMPLE_SIGNED_KEY3);
|
||||
when(sampleDevice4.getSignedPreKey()).thenReturn(null);
|
||||
when(sampleDevice.getId()).thenReturn(1L);
|
||||
when(sampleDevice2.getId()).thenReturn(2L);
|
||||
when(sampleDevice3.getId()).thenReturn(3L);
|
||||
|
@ -126,7 +126,7 @@ public class KeyControllerTest {
|
|||
|
||||
when(keys.getCount(eq(AuthHelper.VALID_NUMBER), eq(1L))).thenReturn(5);
|
||||
|
||||
when(AuthHelper.VALID_DEVICE.getDeviceKey()).thenReturn(new DeviceKey(89898, "zoofarb", "sigvalid"));
|
||||
when(AuthHelper.VALID_DEVICE.getSignedPreKey()).thenReturn(new SignedPreKey(89898, "zoofarb", "sigvalid"));
|
||||
when(AuthHelper.VALID_ACCOUNT.getIdentityKey()).thenReturn(null);
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ public class KeyControllerTest {
|
|||
assertThat(result.getDevices().size()).isEqualTo(1);
|
||||
assertThat(result.getDevices().get(0).getPreKey().getKeyId()).isEqualTo(SAMPLE_KEY.getKeyId());
|
||||
assertThat(result.getDevices().get(0).getPreKey().getPublicKey()).isEqualTo(SAMPLE_KEY.getPublicKey());
|
||||
assertThat(result.getDevices().get(0).getDeviceKey()).isEqualTo(existsAccount.getDevice(1).get().getDeviceKey());
|
||||
assertThat(result.getDevices().get(0).getSignedPreKey()).isEqualTo(existsAccount.getDevice(1).get().getSignedPreKey());
|
||||
|
||||
verify(keys).get(eq(EXISTS_NUMBER), eq(1L));
|
||||
verifyNoMoreInteractions(keys);
|
||||
|
@ -226,7 +226,7 @@ public class KeyControllerTest {
|
|||
assertThat(results.getDevices().size()).isEqualTo(3);
|
||||
assertThat(results.getIdentityKey()).isEqualTo(existsAccount.getIdentityKey());
|
||||
|
||||
PreKeyV2 deviceKey = results.getDevices().get(0).getDeviceKey();
|
||||
PreKeyV2 signedPreKey = results.getDevices().get(0).getSignedPreKey();
|
||||
PreKeyV2 preKey = results.getDevices().get(0).getPreKey();
|
||||
long registrationId = results.getDevices().get(0).getRegistrationId();
|
||||
long deviceId = results.getDevices().get(0).getDeviceId();
|
||||
|
@ -234,11 +234,11 @@ public class KeyControllerTest {
|
|||
assertThat(preKey.getKeyId()).isEqualTo(SAMPLE_KEY.getKeyId());
|
||||
assertThat(preKey.getPublicKey()).isEqualTo(SAMPLE_KEY.getPublicKey());
|
||||
assertThat(registrationId).isEqualTo(SAMPLE_REGISTRATION_ID);
|
||||
assertThat(deviceKey.getKeyId()).isEqualTo(SAMPLE_DEVICE_KEY.getKeyId());
|
||||
assertThat(deviceKey.getPublicKey()).isEqualTo(SAMPLE_DEVICE_KEY.getPublicKey());
|
||||
assertThat(signedPreKey.getKeyId()).isEqualTo(SAMPLE_SIGNED_KEY.getKeyId());
|
||||
assertThat(signedPreKey.getPublicKey()).isEqualTo(SAMPLE_SIGNED_KEY.getPublicKey());
|
||||
assertThat(deviceId).isEqualTo(1);
|
||||
|
||||
deviceKey = results.getDevices().get(1).getDeviceKey();
|
||||
signedPreKey = results.getDevices().get(1).getSignedPreKey();
|
||||
preKey = results.getDevices().get(1).getPreKey();
|
||||
registrationId = results.getDevices().get(1).getRegistrationId();
|
||||
deviceId = results.getDevices().get(1).getDeviceId();
|
||||
|
@ -246,11 +246,11 @@ public class KeyControllerTest {
|
|||
assertThat(preKey.getKeyId()).isEqualTo(SAMPLE_KEY2.getKeyId());
|
||||
assertThat(preKey.getPublicKey()).isEqualTo(SAMPLE_KEY2.getPublicKey());
|
||||
assertThat(registrationId).isEqualTo(SAMPLE_REGISTRATION_ID2);
|
||||
assertThat(deviceKey.getKeyId()).isEqualTo(SAMPLE_DEVICE_KEY2.getKeyId());
|
||||
assertThat(deviceKey.getPublicKey()).isEqualTo(SAMPLE_DEVICE_KEY2.getPublicKey());
|
||||
assertThat(signedPreKey.getKeyId()).isEqualTo(SAMPLE_SIGNED_KEY2.getKeyId());
|
||||
assertThat(signedPreKey.getPublicKey()).isEqualTo(SAMPLE_SIGNED_KEY2.getPublicKey());
|
||||
assertThat(deviceId).isEqualTo(2);
|
||||
|
||||
deviceKey = results.getDevices().get(2).getDeviceKey();
|
||||
signedPreKey = results.getDevices().get(2).getSignedPreKey();
|
||||
preKey = results.getDevices().get(2).getPreKey();
|
||||
registrationId = results.getDevices().get(2).getRegistrationId();
|
||||
deviceId = results.getDevices().get(2).getDeviceId();
|
||||
|
@ -258,7 +258,7 @@ public class KeyControllerTest {
|
|||
assertThat(preKey.getKeyId()).isEqualTo(SAMPLE_KEY4.getKeyId());
|
||||
assertThat(preKey.getPublicKey()).isEqualTo(SAMPLE_KEY4.getPublicKey());
|
||||
assertThat(registrationId).isEqualTo(SAMPLE_REGISTRATION_ID4);
|
||||
assertThat(deviceKey).isNull();
|
||||
assertThat(signedPreKey).isNull();
|
||||
assertThat(deviceId).isEqualTo(4);
|
||||
|
||||
verify(keys).get(eq(EXISTS_NUMBER));
|
||||
|
@ -365,16 +365,16 @@ public class KeyControllerTest {
|
|||
|
||||
@Test
|
||||
public void putKeysTestV2() throws Exception {
|
||||
final PreKeyV2 preKey = new PreKeyV2(31337, "foobar");
|
||||
final PreKeyV2 lastResortKey = new PreKeyV2(31339, "barbar");
|
||||
final DeviceKey deviceKey = new DeviceKey(31338, "foobaz", "myvalidsig");
|
||||
final String identityKey = "barbar";
|
||||
final PreKeyV2 preKey = new PreKeyV2(31337, "foobar");
|
||||
final PreKeyV2 lastResortKey = new PreKeyV2(31339, "barbar");
|
||||
final SignedPreKey signedPreKey = new SignedPreKey(31338, "foobaz", "myvalidsig");
|
||||
final String identityKey = "barbar";
|
||||
|
||||
List<PreKeyV2> preKeys = new LinkedList<PreKeyV2>() {{
|
||||
add(preKey);
|
||||
}};
|
||||
|
||||
PreKeyStateV2 preKeyState = new PreKeyStateV2(identityKey, deviceKey, preKeys, lastResortKey);
|
||||
PreKeyStateV2 preKeyState = new PreKeyStateV2(identityKey, signedPreKey, preKeys, lastResortKey);
|
||||
|
||||
ClientResponse response =
|
||||
resources.client().resource("/v2/keys")
|
||||
|
@ -393,7 +393,7 @@ public class KeyControllerTest {
|
|||
assertThat(capturedList.get(0).getPublicKey().equals("foobar"));
|
||||
|
||||
verify(AuthHelper.VALID_ACCOUNT).setIdentityKey(eq("barbar"));
|
||||
verify(AuthHelper.VALID_DEVICE).setDeviceKey(eq(deviceKey));
|
||||
verify(AuthHelper.VALID_DEVICE).setSignedPreKey(eq(signedPreKey));
|
||||
verify(accounts).update(AuthHelper.VALID_ACCOUNT);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue