Skip to content

Commit

Permalink
Clear unidentified access mode when profile key changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal authored and greyson-signal committed Feb 14, 2020
1 parent 455974c commit 23e55ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,25 +799,30 @@ public void setUuidSupported(@NonNull RecipientId id, boolean supported) {
/**
* Updates the profile key.
* <p>
* If it changes, it clears out the profile key credential.
* If it changes, it clears out the profile key credential and resets the unidentified access mode.
* @return true iff changed.
*/
public void setProfileKey(@NonNull RecipientId id, @Nullable ProfileKey profileKey) {
public boolean setProfileKey(@NonNull RecipientId id, @NonNull ProfileKey profileKey) {
String selection = ID + " = ?";
String[] args = new String[]{id.serialize()};
ContentValues valuesToCompare = new ContentValues(1);
ContentValues valuesToSet = new ContentValues(2);
String encodedProfileKey = profileKey == null ? null : Base64.encodeBytes(profileKey.serialize());
ContentValues valuesToSet = new ContentValues(3);
String encodedProfileKey = Base64.encodeBytes(profileKey.serialize());

valuesToCompare.put(PROFILE_KEY, encodedProfileKey);

valuesToSet.put(PROFILE_KEY, encodedProfileKey);
valuesToSet.putNull(PROFILE_KEY_CREDENTIAL);
valuesToSet.put(UNIDENTIFIED_ACCESS_MODE, UnidentifiedAccessMode.UNKNOWN.getMode());

SqlUtil.UpdateQuery updateQuery = SqlUtil.buildTrueUpdateQuery(selection, args, valuesToCompare);

if (update(updateQuery, valuesToSet)) {
markDirty(id, DirtyState.UPDATE);
Recipient.live(id).refresh();
return true;
} else {
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,13 +1180,14 @@ private void handleProfileKey(@NonNull SignalServiceContent content,
{
RecipientDatabase database = DatabaseFactory.getRecipientDatabase(context);
Recipient recipient = Recipient.externalPush(context, content.getSender());
ProfileKey currentProfileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
ProfileKey messageProfileKey = ProfileKeyUtil.profileKeyOrNull(messageProfileKeyBytes);

if (messageProfileKey != null && !messageProfileKey.equals(currentProfileKey)) {
database.setProfileKey(recipient.getId(), messageProfileKey);
database.setUnidentifiedAccessMode(recipient.getId(), RecipientDatabase.UnidentifiedAccessMode.UNKNOWN);
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient));
if (messageProfileKey != null) {
if (database.setProfileKey(recipient.getId(), messageProfileKey)) {
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient));
}
} else {
Log.w(TAG, "Ignored invalid profile key seen in message");
}
}

Expand Down

0 comments on commit 23e55ac

Please sign in to comment.