Remove use of PNI Credential.

This commit is contained in:
Cody Henthorne 2022-06-30 12:11:44 -04:00
parent fc55b5d1ea
commit 7b805e4041
6 changed files with 0 additions and 134 deletions

View file

@ -6,7 +6,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.signal.core.util.logging.Log; import org.signal.core.util.logging.Log;
import org.signal.libsignal.zkgroup.profiles.PniCredential;
import org.signal.libsignal.zkgroup.profiles.ProfileKey; import org.signal.libsignal.zkgroup.profiles.ProfileKey;
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredential; import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredential;
import org.thoughtcrime.securesms.badges.BadgeRepository; import org.thoughtcrime.securesms.badges.BadgeRepository;
@ -34,7 +33,6 @@ import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription; import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription;
import org.whispersystems.signalservice.internal.ServiceResponse; import org.whispersystems.signalservice.internal.ServiceResponse;
import org.whispersystems.signalservice.internal.ServiceResponseProcessor;
import java.io.IOException; import java.io.IOException;
import java.util.Comparator; import java.util.Comparator;
@ -136,17 +134,6 @@ public class RefreshOwnProfileJob extends BaseJob {
if (profileKeyCredential.isPresent()) { if (profileKeyCredential.isPresent()) {
setProfileKeyCredential(self, ProfileKeyUtil.getSelfProfileKey(), profileKeyCredential.get()); setProfileKeyCredential(self, ProfileKeyUtil.getSelfProfileKey(), profileKeyCredential.get());
} }
if (SignalStore.account().getAci() != null) {
PniCredential pniCredential = ApplicationDependencies.getProfileService()
.getPniProfileCredential(SignalStore.account().requireAci(),
SignalStore.account().requirePni(),
ProfileKeyUtil.getSelfProfileKey())
.map(ServiceResponseProcessor.DefaultProcessor::new)
.blockingGet()
.getResultOrThrow();
SignalStore.account().setPniCredential(pniCredential);
}
} }
private void setProfileKeyCredential(@NonNull Recipient recipient, private void setProfileKeyCredential(@NonNull Recipient recipient,

View file

@ -9,7 +9,6 @@ import org.signal.libsignal.protocol.IdentityKey
import org.signal.libsignal.protocol.IdentityKeyPair import org.signal.libsignal.protocol.IdentityKeyPair
import org.signal.libsignal.protocol.ecc.Curve import org.signal.libsignal.protocol.ecc.Curve
import org.signal.libsignal.protocol.util.Medium import org.signal.libsignal.protocol.util.Medium
import org.signal.libsignal.zkgroup.profiles.PniCredential
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
import org.thoughtcrime.securesms.crypto.MasterCipher import org.thoughtcrime.securesms.crypto.MasterCipher
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
@ -54,7 +53,6 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
private const val KEY_PNI_ACTIVE_SIGNED_PREKEY_ID = "account.pni_active_signed_prekey_id" private const val KEY_PNI_ACTIVE_SIGNED_PREKEY_ID = "account.pni_active_signed_prekey_id"
private const val KEY_PNI_SIGNED_PREKEY_FAILURE_COUNT = "account.pni_signed_prekey_failure_count" private const val KEY_PNI_SIGNED_PREKEY_FAILURE_COUNT = "account.pni_signed_prekey_failure_count"
private const val KEY_PNI_NEXT_ONE_TIME_PREKEY_ID = "account.pni_next_one_time_prekey_id" private const val KEY_PNI_NEXT_ONE_TIME_PREKEY_ID = "account.pni_next_one_time_prekey_id"
private const val KEY_PNI_CREDENTIAL = "account.pni_credential"
@VisibleForTesting @VisibleForTesting
const val KEY_E164 = "account.e164" const val KEY_E164 = "account.e164"
@ -307,10 +305,6 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
val isLinkedDevice: Boolean val isLinkedDevice: Boolean
get() = !isPrimaryDevice get() = !isPrimaryDevice
var pniCredential: PniCredential?
set(value) = putBlob(KEY_PNI_CREDENTIAL, value?.serialize())
get() = getBlob(KEY_PNI_CREDENTIAL, null)?.let { PniCredential(it) }
private fun clearLocalCredentials(context: Context) { private fun clearLocalCredentials(context: Context) {
putString(KEY_SERVICE_PASSWORD, Util.getSecret(18)) putString(KEY_SERVICE_PASSWORD, Util.getSecret(18))

View file

@ -19,7 +19,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest; import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest;
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential; import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile; 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.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException; 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) public SignalServiceProfile retrieveProfileByUsername(String username, Optional<UnidentifiedAccess> unidentifiedAccess, Locale locale)
throws IOException throws IOException
{ {

View file

@ -9,7 +9,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.signal.libsignal.protocol.logging.Log; import org.signal.libsignal.protocol.logging.Log;
import org.signal.libsignal.zkgroup.InvalidInputException; import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.profiles.PniCredentialResponse;
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredentialResponse; import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredentialResponse;
import org.whispersystems.signalservice.api.push.ServiceId; import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.internal.util.JsonUtil; import org.whispersystems.signalservice.internal.util.JsonUtil;
@ -64,9 +63,6 @@ public class SignalServiceProfile {
@JsonProperty @JsonProperty
private List<Badge> badges; private List<Badge> badges;
@JsonProperty
private byte[] pniCredential;
@JsonIgnore @JsonIgnore
private RequestType requestType; private RequestType requestType;
@ -120,10 +116,6 @@ public class SignalServiceProfile {
return requestType; return requestType;
} }
public byte[] getPniCredential() {
return pniCredential;
}
public void setRequestType(RequestType requestType) { public void setRequestType(RequestType requestType) {
this.requestType = requestType; this.requestType = requestType;
} }
@ -263,15 +255,4 @@ public class SignalServiceProfile {
return null; return null;
} }
} }
public PniCredentialResponse getPniCredentialResponse() {
if (pniCredential == null) return null;
try {
return new PniCredentialResponse(pniCredential);
} catch (InvalidInputException e) {
Log.w(TAG, e);
return null;
}
}
} }

View file

@ -3,8 +3,6 @@ package org.whispersystems.signalservice.api.services;
import org.signal.libsignal.protocol.util.Pair; import org.signal.libsignal.protocol.util.Pair;
import org.signal.libsignal.zkgroup.VerificationFailedException; import org.signal.libsignal.zkgroup.VerificationFailedException;
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations; 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.ProfileKey;
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredential; import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredential;
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredentialRequest; 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.crypto.UnidentifiedAccess;
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential; import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile; 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.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException; import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
@ -35,10 +31,7 @@ import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.core.Single; 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, * 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)); .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. * 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. * Response processor for {@link ProfileAndCredential} service response.
*/ */

View file

@ -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) public void retrieveProfileAvatar(String path, File destination, long maxSizeBytes)
throws IOException throws IOException
{ {