Add PNI to `GroupCredentials` responses that contain `AuthCredentialWithPni` instances
This commit is contained in:
parent
7d4a8d03a4
commit
6b6f9b2405
|
@ -114,7 +114,7 @@ public class CertificateController {
|
||||||
i));
|
i));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GroupCredentials(credentials);
|
return new GroupCredentials(credentials, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Timed
|
@Timed
|
||||||
|
@ -153,6 +153,6 @@ public class CertificateController {
|
||||||
redemption = redemption.plus(Duration.ofDays(1));
|
redemption = redemption.plus(Duration.ofDays(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GroupCredentials(credentials);
|
return new GroupCredentials(credentials, pni);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,43 +5,12 @@
|
||||||
|
|
||||||
package org.whispersystems.textsecuregcm.entities;
|
package org.whispersystems.textsecuregcm.entities;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class GroupCredentials {
|
public record GroupCredentials(List<GroupCredential> credentials, @Nullable UUID pni) {
|
||||||
|
|
||||||
private final List<GroupCredential> credentials;
|
public record GroupCredential(byte[] credential, int redemptionTime) {
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public GroupCredentials(
|
|
||||||
@JsonProperty("credentials") List<GroupCredential> credentials) {
|
|
||||||
this.credentials = credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<GroupCredential> getCredentials() {
|
|
||||||
return credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class GroupCredential {
|
|
||||||
|
|
||||||
private final byte[] credential;
|
|
||||||
private final int redemptionTime;
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public GroupCredential(
|
|
||||||
@JsonProperty("credential") byte[] credential,
|
|
||||||
@JsonProperty("redemptionTime") int redemptionTime) {
|
|
||||||
this.credential = credential;
|
|
||||||
this.redemptionTime = redemptionTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getCredential() {
|
|
||||||
return credential;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRedemptionTime() {
|
|
||||||
return redemptionTime;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,13 +217,13 @@ class CertificateControllerTest {
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.get(GroupCredentials.class);
|
.get(GroupCredentials.class);
|
||||||
|
|
||||||
assertThat(credentials.getCredentials().size()).isEqualTo(1);
|
assertThat(credentials.credentials().size()).isEqualTo(1);
|
||||||
assertThat(credentials.getCredentials().get(0).getRedemptionTime()).isEqualTo(Util.currentDaysSinceEpoch());
|
assertThat(credentials.credentials().get(0).redemptionTime()).isEqualTo(Util.currentDaysSinceEpoch());
|
||||||
|
|
||||||
ClientZkAuthOperations clientZkAuthOperations = new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
ClientZkAuthOperations clientZkAuthOperations = new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
clientZkAuthOperations.receiveAuthCredential(AuthHelper.VALID_UUID, Util.currentDaysSinceEpoch(), new AuthCredentialResponse(credentials.getCredentials().get(0).getCredential())))
|
clientZkAuthOperations.receiveAuthCredential(AuthHelper.VALID_UUID, Util.currentDaysSinceEpoch(), new AuthCredentialResponse(credentials.credentials().get(0).credential())))
|
||||||
.doesNotThrowAnyException();
|
.doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,14 +236,14 @@ class CertificateControllerTest {
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.get(GroupCredentials.class);
|
.get(GroupCredentials.class);
|
||||||
|
|
||||||
assertThat(credentials.getCredentials().size()).isEqualTo(1);
|
assertThat(credentials.credentials().size()).isEqualTo(1);
|
||||||
assertThat(credentials.getCredentials().get(0).getRedemptionTime()).isEqualTo(Util.currentDaysSinceEpoch());
|
assertThat(credentials.credentials().get(0).redemptionTime()).isEqualTo(Util.currentDaysSinceEpoch());
|
||||||
|
|
||||||
ClientZkAuthOperations clientZkAuthOperations = new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
ClientZkAuthOperations clientZkAuthOperations = new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
||||||
|
|
||||||
assertThatExceptionOfType(VerificationFailedException.class)
|
assertThatExceptionOfType(VerificationFailedException.class)
|
||||||
.isThrownBy(() ->
|
.isThrownBy(() ->
|
||||||
clientZkAuthOperations.receiveAuthCredential(AuthHelper.VALID_UUID, Util.currentDaysSinceEpoch(), new AuthCredentialResponse(credentials.getCredentials().get(0).getCredential())));
|
clientZkAuthOperations.receiveAuthCredential(AuthHelper.VALID_UUID, Util.currentDaysSinceEpoch(), new AuthCredentialResponse(credentials.credentials().get(0).credential())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -254,17 +254,17 @@ class CertificateControllerTest {
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.get(GroupCredentials.class);
|
.get(GroupCredentials.class);
|
||||||
|
|
||||||
assertThat(credentials.getCredentials().size()).isEqualTo(8);
|
assertThat(credentials.credentials().size()).isEqualTo(8);
|
||||||
|
|
||||||
for (int i=0;i<=7;i++) {
|
for (int i=0;i<=7;i++) {
|
||||||
assertThat(credentials.getCredentials().get(i).getRedemptionTime()).isEqualTo(Util.currentDaysSinceEpoch() + i);
|
assertThat(credentials.credentials().get(i).redemptionTime()).isEqualTo(Util.currentDaysSinceEpoch() + i);
|
||||||
|
|
||||||
ClientZkAuthOperations clientZkAuthOperations = new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
ClientZkAuthOperations clientZkAuthOperations = new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
||||||
|
|
||||||
final int time = i;
|
final int time = i;
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
clientZkAuthOperations.receiveAuthCredential(AuthHelper.VALID_UUID, Util.currentDaysSinceEpoch() + time , new AuthCredentialResponse(credentials.getCredentials().get(time).getCredential())))
|
clientZkAuthOperations.receiveAuthCredential(AuthHelper.VALID_UUID, Util.currentDaysSinceEpoch() + time , new AuthCredentialResponse(credentials.credentials().get(time).credential())))
|
||||||
.doesNotThrowAnyException();
|
.doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,8 +314,9 @@ class CertificateControllerTest {
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.get(GroupCredentials.class);
|
.get(GroupCredentials.class);
|
||||||
|
|
||||||
assertEquals(1, credentials.getCredentials().size());
|
assertEquals(1, credentials.credentials().size());
|
||||||
assertEquals(startOfDay.getEpochSecond(), credentials.getCredentials().get(0).getRedemptionTime());
|
assertEquals(AuthHelper.VALID_PNI, credentials.pni());
|
||||||
|
assertEquals(startOfDay.getEpochSecond(), credentials.credentials().get(0).redemptionTime());
|
||||||
|
|
||||||
final ClientZkAuthOperations clientZkAuthOperations =
|
final ClientZkAuthOperations clientZkAuthOperations =
|
||||||
new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
||||||
|
@ -325,7 +326,7 @@ class CertificateControllerTest {
|
||||||
AuthHelper.VALID_UUID,
|
AuthHelper.VALID_UUID,
|
||||||
AuthHelper.VALID_PNI,
|
AuthHelper.VALID_PNI,
|
||||||
(int) startOfDay.getEpochSecond(),
|
(int) startOfDay.getEpochSecond(),
|
||||||
new AuthCredentialWithPniResponse(credentials.getCredentials().get(0).getCredential()));
|
new AuthCredentialWithPniResponse(credentials.credentials().get(0).credential()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,14 +342,15 @@ class CertificateControllerTest {
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.get(GroupCredentials.class);
|
.get(GroupCredentials.class);
|
||||||
|
|
||||||
assertEquals(8, credentials.getCredentials().size());
|
assertEquals(AuthHelper.VALID_PNI, credentials.pni());
|
||||||
|
assertEquals(8, credentials.credentials().size());
|
||||||
|
|
||||||
final ClientZkAuthOperations clientZkAuthOperations =
|
final ClientZkAuthOperations clientZkAuthOperations =
|
||||||
new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
new ClientZkAuthOperations(serverSecretParams.getPublicParams());
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
final Instant redemptionTime = startOfDay.plus(Duration.ofDays(i));
|
final Instant redemptionTime = startOfDay.plus(Duration.ofDays(i));
|
||||||
assertEquals(redemptionTime.getEpochSecond(), credentials.getCredentials().get(i).getRedemptionTime());
|
assertEquals(redemptionTime.getEpochSecond(), credentials.credentials().get(i).redemptionTime());
|
||||||
|
|
||||||
final int index = i;
|
final int index = i;
|
||||||
|
|
||||||
|
@ -357,7 +359,7 @@ class CertificateControllerTest {
|
||||||
AuthHelper.VALID_UUID,
|
AuthHelper.VALID_UUID,
|
||||||
AuthHelper.VALID_PNI,
|
AuthHelper.VALID_PNI,
|
||||||
redemptionTime.getEpochSecond(),
|
redemptionTime.getEpochSecond(),
|
||||||
new AuthCredentialWithPniResponse(credentials.getCredentials().get(index).getCredential()));
|
new AuthCredentialWithPniResponse(credentials.credentials().get(index).credential()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue