mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-27 13:13:43 +00:00
Fetch PNI Credential during own profile refresh.
This commit is contained in:
@@ -184,12 +184,8 @@ class ContactDiscoveryRefreshV1 {
|
||||
.filter(ContactDiscoveryRefreshV1::hasCommunicatedWith)
|
||||
.toList();
|
||||
|
||||
ProfileService profileService = new ProfileService(ApplicationDependencies.getGroupsV2Operations().getProfileOperations(),
|
||||
ApplicationDependencies.getSignalServiceMessageReceiver(),
|
||||
ApplicationDependencies.getSignalWebSocket());
|
||||
|
||||
List<Observable<Pair<Recipient, ServiceResponse<ProfileAndCredential>>>> requests = Stream.of(possiblyUnlisted)
|
||||
.map(r -> ProfileUtil.retrieveProfile(context, r, SignalServiceProfile.RequestType.PROFILE, profileService)
|
||||
.map(r -> ProfileUtil.retrieveProfile(context, r, SignalServiceProfile.RequestType.PROFILE)
|
||||
.toObservable()
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.onErrorReturn(t -> new Pair<>(r, ServiceResponse.forUnknownError(t))))
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import org.signal.core.util.Hex;
|
||||
import org.signal.core.util.concurrent.DeadlockDetector;
|
||||
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations;
|
||||
import org.signal.libsignal.zkgroup.receipts.ClientZkReceiptOperations;
|
||||
import org.thoughtcrime.securesms.KbsEnclave;
|
||||
import org.thoughtcrime.securesms.components.TypingStatusRepository;
|
||||
@@ -53,6 +54,7 @@ import org.whispersystems.signalservice.api.SignalWebSocket;
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
||||
import org.whispersystems.signalservice.api.push.TrustStore;
|
||||
import org.whispersystems.signalservice.api.services.DonationsService;
|
||||
import org.whispersystems.signalservice.api.services.ProfileService;
|
||||
import org.whispersystems.signalservice.api.util.Tls12SocketFactory;
|
||||
import org.whispersystems.signalservice.internal.util.BlacklistingTrustManager;
|
||||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
@@ -120,6 +122,7 @@ public class ApplicationDependencies {
|
||||
private static volatile SimpleExoPlayerPool exoPlayerPool;
|
||||
private static volatile AudioManagerCompat audioManagerCompat;
|
||||
private static volatile DonationsService donationsService;
|
||||
private static volatile ProfileService profileService;
|
||||
private static volatile DeadlockDetector deadlockDetector;
|
||||
private static volatile ClientZkReceiptOperations clientZkReceiptOperations;
|
||||
|
||||
@@ -632,6 +635,19 @@ public class ApplicationDependencies {
|
||||
return donationsService;
|
||||
}
|
||||
|
||||
public static @NonNull ProfileService getProfileService() {
|
||||
if (profileService == null) {
|
||||
synchronized (LOCK) {
|
||||
if (profileService == null) {
|
||||
profileService = provider.provideProfileService(ApplicationDependencies.getGroupsV2Operations().getProfileOperations(),
|
||||
ApplicationDependencies.getSignalServiceMessageReceiver(),
|
||||
ApplicationDependencies.getSignalWebSocket());
|
||||
}
|
||||
}
|
||||
}
|
||||
return profileService;
|
||||
}
|
||||
|
||||
public static @NonNull ClientZkReceiptOperations getClientZkReceiptOperations() {
|
||||
if (clientZkReceiptOperations == null) {
|
||||
synchronized (LOCK) {
|
||||
@@ -688,6 +704,7 @@ public class ApplicationDependencies {
|
||||
@NonNull SimpleExoPlayerPool provideExoPlayerPool();
|
||||
@NonNull AudioManagerCompat provideAndroidCallAudioManager();
|
||||
@NonNull DonationsService provideDonationsService();
|
||||
@NonNull ProfileService provideProfileService(@NonNull ClientZkProfileOperations profileOperations, @NonNull SignalServiceMessageReceiver signalServiceMessageReceiver, @NonNull SignalWebSocket signalWebSocket);
|
||||
@NonNull DeadlockDetector provideDeadlockDetector();
|
||||
@NonNull ClientZkReceiptOperations provideClientZkReceiptOperations();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.concurrent.DeadlockDetector;
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations;
|
||||
import org.signal.libsignal.zkgroup.receipts.ClientZkReceiptOperations;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.components.TypingStatusRepository;
|
||||
@@ -79,6 +80,7 @@ import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.PNI;
|
||||
import org.whispersystems.signalservice.api.services.DonationsService;
|
||||
import org.whispersystems.signalservice.api.services.ProfileService;
|
||||
import org.whispersystems.signalservice.api.util.CredentialsProvider;
|
||||
import org.whispersystems.signalservice.api.util.SleepTimer;
|
||||
import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
|
||||
@@ -352,6 +354,14 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
|
||||
FeatureFlags.okHttpAutomaticRetry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ProfileService provideProfileService(@NonNull ClientZkProfileOperations clientZkProfileOperations,
|
||||
@NonNull SignalServiceMessageReceiver receiver,
|
||||
@NonNull SignalWebSocket signalWebSocket)
|
||||
{
|
||||
return new ProfileService(clientZkProfileOperations, receiver, signalWebSocket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull DeadlockDetector provideDeadlockDetector() {
|
||||
HandlerThread handlerThread = new HandlerThread("signal-DeadlockDetector");
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
|
||||
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;
|
||||
@@ -33,6 +34,7 @@ import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||
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;
|
||||
@@ -134,6 +136,17 @@ public class RefreshOwnProfileJob extends BaseJob {
|
||||
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,
|
||||
|
||||
@@ -253,13 +253,9 @@ public class RetrieveProfileJob extends BaseJob {
|
||||
List<Recipient> recipients = Recipient.resolvedList(recipientIds);
|
||||
stopwatch.split("resolve-ensure");
|
||||
|
||||
ProfileService profileService = new ProfileService(ApplicationDependencies.getGroupsV2Operations().getProfileOperations(),
|
||||
ApplicationDependencies.getSignalServiceMessageReceiver(),
|
||||
ApplicationDependencies.getSignalWebSocket());
|
||||
|
||||
List<Observable<Pair<Recipient, ServiceResponse<ProfileAndCredential>>>> requests = Stream.of(recipients)
|
||||
.filter(Recipient::hasServiceId)
|
||||
.map(r -> ProfileUtil.retrieveProfile(context, r, getRequestType(r), profileService).toObservable())
|
||||
.map(r -> ProfileUtil.retrieveProfile(context, r, getRequestType(r)).toObservable())
|
||||
.toList();
|
||||
stopwatch.split("requests");
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ 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
|
||||
@@ -53,6 +54,7 @@ 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"
|
||||
@@ -305,6 +307,10 @@ 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))
|
||||
|
||||
|
||||
@@ -102,28 +102,23 @@ public final class ProfileUtil {
|
||||
boolean allowUnidentifiedAccess)
|
||||
throws IOException
|
||||
{
|
||||
ProfileService profileService = new ProfileService(ApplicationDependencies.getGroupsV2Operations().getProfileOperations(),
|
||||
ApplicationDependencies.getSignalServiceMessageReceiver(),
|
||||
ApplicationDependencies.getSignalWebSocket());
|
||||
|
||||
Pair<Recipient, ServiceResponse<ProfileAndCredential>> response = retrieveProfile(context, recipient, requestType, profileService, allowUnidentifiedAccess).blockingGet();
|
||||
Pair<Recipient, ServiceResponse<ProfileAndCredential>> response = retrieveProfile(context, recipient, requestType, allowUnidentifiedAccess).blockingGet();
|
||||
return new ProfileService.ProfileResponseProcessor(response.second()).getResultOrThrow();
|
||||
}
|
||||
|
||||
public static Single<Pair<Recipient, ServiceResponse<ProfileAndCredential>>> retrieveProfile(@NonNull Context context,
|
||||
@NonNull Recipient recipient,
|
||||
@NonNull SignalServiceProfile.RequestType requestType,
|
||||
@NonNull ProfileService profileService)
|
||||
@NonNull SignalServiceProfile.RequestType requestType)
|
||||
{
|
||||
return retrieveProfile(context, recipient, requestType, profileService, true);
|
||||
return retrieveProfile(context, recipient, requestType, true);
|
||||
}
|
||||
|
||||
private static Single<Pair<Recipient, ServiceResponse<ProfileAndCredential>>> retrieveProfile(@NonNull Context context,
|
||||
@NonNull Recipient recipient,
|
||||
@NonNull SignalServiceProfile.RequestType requestType,
|
||||
@NonNull ProfileService profileService,
|
||||
boolean allowUnidentifiedAccess)
|
||||
{
|
||||
ProfileService profileService = ApplicationDependencies.getProfileService();
|
||||
Optional<UnidentifiedAccess> unidentifiedAccess = allowUnidentifiedAccess ? getUnidentifiedAccess(context, recipient) : Optional.empty();
|
||||
Optional<ProfileKey> profileKey = ProfileKeyUtil.profileKeyOptional(recipient.getProfileKey());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user