mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Remove use of PNI Credential.
This commit is contained in:
@@ -19,7 +19,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest;
|
||||
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
|
||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
||||
@@ -111,10 +110,6 @@ public class SignalServiceMessageReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
public ListenableFuture<SignalServiceProfile> retrievePniProfile(ACI aci, String version, String credentialRequest, Locale locale) {
|
||||
return socket.retrievePniCredential(aci.uuid(), version, credentialRequest, locale);
|
||||
}
|
||||
|
||||
public SignalServiceProfile retrieveProfileByUsername(String username, Optional<UnidentifiedAccess> unidentifiedAccess, Locale locale)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import org.signal.libsignal.protocol.logging.Log;
|
||||
import org.signal.libsignal.zkgroup.InvalidInputException;
|
||||
import org.signal.libsignal.zkgroup.profiles.PniCredentialResponse;
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredentialResponse;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.internal.util.JsonUtil;
|
||||
@@ -64,9 +63,6 @@ public class SignalServiceProfile {
|
||||
@JsonProperty
|
||||
private List<Badge> badges;
|
||||
|
||||
@JsonProperty
|
||||
private byte[] pniCredential;
|
||||
|
||||
@JsonIgnore
|
||||
private RequestType requestType;
|
||||
|
||||
@@ -120,10 +116,6 @@ public class SignalServiceProfile {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
public byte[] getPniCredential() {
|
||||
return pniCredential;
|
||||
}
|
||||
|
||||
public void setRequestType(RequestType requestType) {
|
||||
this.requestType = requestType;
|
||||
}
|
||||
@@ -263,15 +255,4 @@ public class SignalServiceProfile {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public PniCredentialResponse getPniCredentialResponse() {
|
||||
if (pniCredential == null) return null;
|
||||
|
||||
try {
|
||||
return new PniCredentialResponse(pniCredential);
|
||||
} catch (InvalidInputException e) {
|
||||
Log.w(TAG, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.whispersystems.signalservice.api.services;
|
||||
import org.signal.libsignal.protocol.util.Pair;
|
||||
import org.signal.libsignal.zkgroup.VerificationFailedException;
|
||||
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations;
|
||||
import org.signal.libsignal.zkgroup.profiles.PniCredential;
|
||||
import org.signal.libsignal.zkgroup.profiles.PniCredentialRequestContext;
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredential;
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredentialRequest;
|
||||
@@ -15,8 +13,6 @@ import org.whispersystems.signalservice.api.SignalWebSocket;
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
|
||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.PNI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
|
||||
@@ -35,10 +31,7 @@ import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
import io.reactivex.rxjava3.core.Scheduler;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import io.reactivex.rxjava3.core.SingleSource;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Provide Profile-related API services, encapsulating the logic to make the request, parse the response,
|
||||
@@ -118,40 +111,6 @@ public final class ProfileService {
|
||||
.map(p -> ServiceResponse.forResult(p, 0, null));
|
||||
}
|
||||
|
||||
public Single<ServiceResponse<PniCredential>> getPniProfileCredential(ACI aci,
|
||||
PNI pni,
|
||||
ProfileKey profileKey)
|
||||
{
|
||||
SecureRandom random = new SecureRandom();
|
||||
ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(aci.uuid());
|
||||
String version = profileKeyIdentifier.serialize();
|
||||
PniCredentialRequestContext requestContext = clientZkProfileOperations.createPniCredentialRequestContext(random, aci.uuid(), pni.uuid(), profileKey);
|
||||
ProfileKeyCredentialRequest request = requestContext.getRequest();
|
||||
String credentialRequest = Hex.toStringCondensed(request.serialize());
|
||||
|
||||
WebSocketRequestMessage requestMessage = WebSocketRequestMessage.newBuilder()
|
||||
.setId(random.nextLong())
|
||||
.setVerb("GET")
|
||||
.setPath(String.format("/v1/profile/%s/%s/%s?credentialType=pni", aci.uuid(), version, credentialRequest))
|
||||
.addHeaders(AcceptLanguagesUtil.getAcceptLanguageHeader(Locale.getDefault()))
|
||||
.build();
|
||||
|
||||
PniCredentialMapper pniCredentialMapper = new PniCredentialMapper(requestContext);
|
||||
ResponseMapper<PniCredential> responseMapper = DefaultResponseMapper.extend(PniCredential.class)
|
||||
.withResponseMapper(pniCredentialMapper)
|
||||
.build();
|
||||
|
||||
return signalWebSocket.request(requestMessage, Optional.empty())
|
||||
.map(responseMapper::map)
|
||||
.onErrorResumeNext(t -> restFallbackForPni(pniCredentialMapper, aci, version, credentialRequest, Locale.getDefault()))
|
||||
.onErrorReturn(ServiceResponse::forUnknownError);
|
||||
}
|
||||
|
||||
private Single<ServiceResponse<PniCredential>> restFallbackForPni(PniCredentialMapper responseMapper, ACI aci, String version, String credentialRequest, Locale locale) {
|
||||
return Single.fromFuture(receiver.retrievePniProfile(aci, version, credentialRequest, locale), 10, TimeUnit.SECONDS)
|
||||
.map(responseMapper::map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the API {@link SignalServiceProfile} model into the desired {@link ProfileAndCredential} domain model.
|
||||
*/
|
||||
@@ -182,42 +141,6 @@ public final class ProfileService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the API {@link SignalServiceProfile} model into the desired {@link org.signal.libsignal.zkgroup.profiles.PniCredential} domain model.
|
||||
*/
|
||||
private class PniCredentialMapper implements DefaultResponseMapper.CustomResponseMapper<PniCredential> {
|
||||
private final PniCredentialRequestContext requestContext;
|
||||
|
||||
public PniCredentialMapper(PniCredentialRequestContext requestContext) {
|
||||
this.requestContext = requestContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceResponse<PniCredential> map(int status, String body, Function<String, String> getHeader, boolean unidentified)
|
||||
throws MalformedResponseException
|
||||
{
|
||||
SignalServiceProfile signalServiceProfile = JsonUtil.fromJsonResponse(body, SignalServiceProfile.class);
|
||||
return map(signalServiceProfile);
|
||||
}
|
||||
|
||||
public ServiceResponse<PniCredential> map(SignalServiceProfile signalServiceProfile) {
|
||||
try {
|
||||
PniCredential pniCredential = null;
|
||||
if (requestContext != null && signalServiceProfile.getPniCredentialResponse() != null) {
|
||||
pniCredential = clientZkProfileOperations.receivePniCredential(requestContext, signalServiceProfile.getPniCredentialResponse());
|
||||
}
|
||||
|
||||
if (pniCredential == null) {
|
||||
return ServiceResponse.forApplicationError(new MalformedResponseException("No PNI credential in response"), 0, null);
|
||||
} else {
|
||||
return ServiceResponse.forResult(pniCredential, 200, null);
|
||||
}
|
||||
} catch (VerificationFailedException e) {
|
||||
return ServiceResponse.forUnknownError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Response processor for {@link ProfileAndCredential} service response.
|
||||
*/
|
||||
|
||||
@@ -814,20 +814,6 @@ public class PushServiceSocket {
|
||||
});
|
||||
}
|
||||
|
||||
public ListenableFuture<SignalServiceProfile> retrievePniCredential(UUID target, String version, String credentialRequest, Locale locale) {
|
||||
String subPath = String.format("%s/%s/%s?credentialType=pni", target, version, credentialRequest);
|
||||
ListenableFuture<String> response = submitServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, AcceptLanguagesUtil.getHeadersWithAcceptLanguage(locale), Optional.empty());
|
||||
|
||||
return FutureTransformers.map(response, body -> {
|
||||
try {
|
||||
return JsonUtil.fromJson(body, SignalServiceProfile.class);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void retrieveProfileAvatar(String path, File destination, long maxSizeBytes)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user