Include auth token in CDSH request.

This commit is contained in:
Greyson Parrelli
2021-11-15 14:18:28 -05:00
committed by Cody Henthorne
parent 54614e67aa
commit 732a6324d6
5 changed files with 38 additions and 5 deletions

View File

@@ -60,6 +60,7 @@ import org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequ
import org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse;
import org.whispersystems.signalservice.internal.crypto.ProvisioningCipher;
import org.whispersystems.signalservice.internal.push.AuthCredentials;
import org.whispersystems.signalservice.internal.push.CdshAuthResponse;
import org.whispersystems.signalservice.internal.push.ProfileAvatarData;
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import org.whispersystems.signalservice.internal.push.RemoteAttestationUtil;
@@ -493,8 +494,9 @@ public class SignalServiceAccountManager {
public Map<String, ACI> getRegisteredUsersWithCdsh(Set<String> e164numbers, String hexPublicKey, String hexCodeHash)
throws IOException
{
CdshAuthResponse auth = pushServiceSocket.getCdshAuth();
CdshService service = new CdshService(configuration, hexPublicKey, hexCodeHash);
Single<ServiceResponse<Map<String, ACI>>> result = service.getRegisteredUsers(e164numbers);
Single<ServiceResponse<Map<String, ACI>>> result = service.getRegisteredUsers(auth.getUsername(), auth.getPassword(), e164numbers);
ServiceResponse<Map<String, ACI>> response;
try {

View File

@@ -18,6 +18,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
@@ -82,7 +83,7 @@ public final class CdshService {
}
}
public Single<ServiceResponse<Map<String, ACI>>> getRegisteredUsers(Set<String> e164Numbers) {
public Single<ServiceResponse<Map<String, ACI>>> getRegisteredUsers(String username, String password, Set<String> e164Numbers) {
return Single.create(emitter -> {
AtomicReference<Stage> stage = new AtomicReference<>(Stage.WAITING_TO_INITIALIZE);
List<String> addressBook = e164Numbers.stream().map(e -> e.substring(1)).collect(Collectors.toList());
@@ -96,7 +97,7 @@ public final class CdshService {
case WAITING_TO_INITIALIZE:
enclave.completeHandshake(bytes.toByteArray());
byte[] request = enclave.establishedSend(buildPlaintextRequest(addressBook));
byte[] request = enclave.establishedSend(buildPlaintextRequest(username, password, addressBook));
stage.set(Stage.WAITING_FOR_RESPONSE);
webSocket.send(ByteString.of(request));
@@ -145,9 +146,11 @@ public final class CdshService {
});
}
private static byte[] buildPlaintextRequest(List<String> addressBook) {
private static byte[] buildPlaintextRequest(String username, String password, List<String> addressBook) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
outputStream.write(VERSION);
outputStream.write(username.getBytes(StandardCharsets.UTF_8));
outputStream.write(password.getBytes(StandardCharsets.UTF_8));
for (String e164 : addressBook) {
outputStream.write(ByteUtil.longToByteArray(Long.parseLong(e164)));

View File

@@ -0,0 +1,20 @@
package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
public class CdshAuthResponse {
@JsonProperty
private String username;
@JsonProperty
private String password;
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}

View File

@@ -258,6 +258,8 @@ public class PushServiceSocket {
private static final String BOOST_RECEIPT_CREDENTIALS = "/v1/subscription/boost/receipt_credentials";
private static final String BOOST_BADGES = "/v1/subscription/boost/badges";
private static final String CDSH_AUTH = "/v2/directory/auth";
private static final String REPORT_SPAM = "/v1/messages/report/%s/%s";
private static final String SERVER_DELIVERED_TIMESTAMP_HEADER = "X-Signal-Timestamp";
@@ -343,6 +345,11 @@ public class PushServiceSocket {
return JsonUtil.fromJson(makeServiceRequest(WHO_AM_I, "GET", null), WhoAmIResponse.class);
}
public CdshAuthResponse getCdshAuth() throws IOException {
String body = makeServiceRequest(CDSH_AUTH, "GET", null);
return JsonUtil.fromJsonResponse(body, CdshAuthResponse.class);
}
public VerifyAccountResponse verifyAccountCode(String verificationCode, String signalingKey, int registrationId, boolean fetchesMessages,
String pin, String registrationLock,
byte[] unidentifiedAccessKey, boolean unrestrictedUnidentifiedAccess,

View File

@@ -71,7 +71,8 @@ public class JsonUtil {
}
public static <T> T fromJsonResponse(String body, Class<T> clazz)
throws MalformedResponseException {
throws MalformedResponseException
{
try {
return JsonUtil.fromJson(body, clazz);
} catch (IOException e) {