Skip to content

Commit

Permalink
Remove use of PNI Credential.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal committed Jun 30, 2022
1 parent fc55b5d commit 7b805e4
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import androidx.annotation.Nullable;

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.ProfileKeyCredential;
import org.thoughtcrime.securesms.badges.BadgeRepository;
Expand Down Expand Up @@ -34,7 +33,6 @@
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription;
import org.whispersystems.signalservice.internal.ServiceResponse;
import org.whispersystems.signalservice.internal.ServiceResponseProcessor;

import java.io.IOException;
import java.util.Comparator;
Expand Down Expand Up @@ -136,17 +134,6 @@ protected void onRun() throws Exception {
if (profileKeyCredential.isPresent()) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.signal.libsignal.protocol.IdentityKey
import org.signal.libsignal.protocol.IdentityKeyPair
import org.signal.libsignal.protocol.ecc.Curve
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.MasterCipher
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
Expand Down Expand Up @@ -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_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_CREDENTIAL = "account.pni_credential"

@VisibleForTesting
const val KEY_E164 = "account.e164"
Expand Down Expand Up @@ -307,10 +305,6 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
val isLinkedDevice: Boolean
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) {
putString(KEY_SERVICE_PASSWORD, Util.getSecret(18))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand Down Expand Up @@ -111,10 +110,6 @@ public ListenableFuture<ProfileAndCredential> retrieveProfile(SignalServiceAddre
}
}

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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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;
Expand Down Expand Up @@ -64,9 +63,6 @@ public enum RequestType {
@JsonProperty
private List<Badge> badges;

@JsonProperty
private byte[] pniCredential;

@JsonIgnore
private RequestType requestType;

Expand Down Expand Up @@ -120,10 +116,6 @@ public RequestType getRequestType() {
return requestType;
}

public byte[] getPniCredential() {
return pniCredential;
}

public void setRequestType(RequestType requestType) {
this.requestType = requestType;
}
Expand Down Expand Up @@ -263,15 +255,4 @@ public ProfileKeyCredentialResponse getProfileKeyCredentialResponse() {
return null;
}
}

public PniCredentialResponse getPniCredentialResponse() {
if (pniCredential == null) return null;

try {
return new PniCredentialResponse(pniCredential);
} catch (InvalidInputException e) {
Log.w(TAG, e);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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;
Expand All @@ -15,8 +13,6 @@
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;
Expand All @@ -35,10 +31,7 @@
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,
Expand Down Expand Up @@ -118,40 +111,6 @@ private Single<ServiceResponse<ProfileAndCredential>> restFallback(SignalService
.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.
*/
Expand Down Expand Up @@ -182,42 +141,6 @@ public ServiceResponse<ProfileAndCredential> map(int status, String body, Functi
}
}

/**
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,20 +814,6 @@ public ListenableFuture<SignalServiceProfile> retrieveVersionedProfile(UUID targ
});
}

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
{
Expand Down

0 comments on commit 7b805e4

Please sign in to comment.