diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/AccountConsistencyWorkerJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/AccountConsistencyWorkerJob.kt index 2e68d7b3e9..59dc62346f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/AccountConsistencyWorkerJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/AccountConsistencyWorkerJob.kt @@ -56,19 +56,34 @@ class AccountConsistencyWorkerJob private constructor(parameters: Parameters) : return } - val profile: SignalServiceProfile = ProfileUtil.retrieveProfileSync(context, Recipient.self(), SignalServiceProfile.RequestType.PROFILE, false).profile - val encodedPublicKey = Base64.encodeWithPadding(SignalStore.account().aciIdentityKey.publicKey.serialize()) + val aciProfile: SignalServiceProfile = ProfileUtil.retrieveProfileSync(context, Recipient.self(), SignalServiceProfile.RequestType.PROFILE, false).profile + val encodedAciPublicKey = Base64.encodeWithPadding(SignalStore.account().aciIdentityKey.publicKey.serialize()) - if (profile.identityKey != encodedPublicKey) { - Log.w(TAG, "Identity key on profile differed from the one we have locally! Marking ourselves unregistered.") + if (aciProfile.identityKey != encodedAciPublicKey) { + Log.w(TAG, "ACI identity key on profile differed from the one we have locally! Marking ourselves unregistered.") SignalStore.account().setRegistered(false) SignalStore.registrationValues().clearRegistrationComplete() SignalStore.registrationValues().clearHasUploadedProfile() - } else { - Log.i(TAG, "Everything matched.") + + SignalStore.misc().lastConsistencyCheckTime = System.currentTimeMillis() + return } + val pniProfile: SignalServiceProfile = ProfileUtil.retrieveProfileSync(SignalStore.account().pni!!, SignalServiceProfile.RequestType.PROFILE).profile + val encodedPniPublicKey = Base64.encodeWithPadding(SignalStore.account().pniIdentityKey.publicKey.serialize()) + + if (pniProfile.identityKey != encodedPniPublicKey) { + Log.w(TAG, "PNI identity key on profile differed from the one we have locally!") + + SignalStore.account().setRegistered(false) + SignalStore.registrationValues().clearRegistrationComplete() + SignalStore.registrationValues().clearHasUploadedProfile() + return + } + + Log.i(TAG, "Everything matched.") + SignalStore.misc().lastConsistencyCheckTime = System.currentTimeMillis() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ProfileUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/ProfileUtil.java index 869b3fd6b1..b5024b7177 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ProfileUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ProfileUtil.java @@ -43,6 +43,7 @@ import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair; import org.whispersystems.signalservice.api.profiles.AvatarUploadParams; import org.whispersystems.signalservice.api.profiles.ProfileAndCredential; import org.whispersystems.signalservice.api.profiles.SignalServiceProfile; +import org.whispersystems.signalservice.api.push.ServiceId; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.services.ProfileService; import org.whispersystems.signalservice.api.util.StreamDetails; @@ -108,6 +109,22 @@ public final class ProfileUtil { return new ProfileService.ProfileResponseProcessor(response.second()).getResultOrThrow(); } + @WorkerThread + public static @NonNull ProfileAndCredential retrieveProfileSync(@NonNull ServiceId.PNI pni, + @NonNull SignalServiceProfile.RequestType requestType) + throws IOException + { + ProfileService profileService = ApplicationDependencies.getProfileService(); + + ServiceResponse response = Single + .fromCallable(() -> new SignalServiceAddress(pni)) + .flatMap(address -> profileService.getProfile(address, Optional.empty(), Optional.empty(), requestType, Locale.getDefault())) + .onErrorReturn(t -> ServiceResponse.forUnknownError(t)) + .blockingGet(); + + return new ProfileService.ProfileResponseProcessor(response).getResultOrThrow(); + } + public static Single>> retrieveProfile(@NonNull Context context, @NonNull Recipient recipient, @NonNull SignalServiceProfile.RequestType requestType)