Store available profile data even if we don't have the profile key

This commit is contained in:
AsamK 2021-05-11 18:37:18 +02:00
parent 7364f0f7cf
commit 19c004e987
3 changed files with 49 additions and 35 deletions

View file

@ -556,14 +556,6 @@ public class Manager implements Closeable {
Profile getRecipientProfile( Profile getRecipientProfile(
RecipientId recipientId, boolean force RecipientId recipientId, boolean force
) { ) {
var profileKey = account.getProfileStore().getProfileKey(recipientId);
if (profileKey == null) {
if (force) {
// retrieve profile to get identity key
retrieveEncryptedProfile(recipientId);
}
return null;
}
var profile = account.getProfileStore().getProfile(recipientId); var profile = account.getProfileStore().getProfile(recipientId);
var now = new Date().getTime(); var now = new Date().getTime();
@ -590,7 +582,18 @@ public class Manager implements Closeable {
return null; return null;
} }
profile = decryptProfileAndDownloadAvatar(recipientId, profileKey, encryptedProfile); var profileKey = account.getProfileStore().getProfileKey(recipientId);
if (profileKey == null) {
profile = new Profile(new Date().getTime(),
null,
null,
null,
null,
ProfileUtils.getUnidentifiedAccessMode(encryptedProfile, null),
ProfileUtils.getCapabilities(encryptedProfile));
} else {
profile = decryptProfileAndDownloadAvatar(recipientId, profileKey, encryptedProfile);
}
account.getProfileStore().storeProfile(recipientId, profile); account.getProfileStore().storeProfile(recipientId, profile);
return profile; return profile;

View file

@ -233,6 +233,9 @@ public class RecipientStore implements ContactsStore, ProfileStore {
final var newRecipient = Recipient.newBuilder(recipient) final var newRecipient = Recipient.newBuilder(recipient)
.withProfileKey(profileKey) .withProfileKey(profileKey)
.withProfileKeyCredential(null) .withProfileKeyCredential(null)
.withProfile(recipient.getProfile() == null
? null
: Profile.newBuilder(recipient.getProfile()).withLastUpdateTimestamp(0).build())
.build(); .build();
storeRecipientLocked(recipientId, newRecipient); storeRecipientLocked(recipientId, newRecipient);
} }

View file

@ -21,43 +21,51 @@ public class ProfileUtils {
var name = decryptName(encryptedProfile.getName(), profileCipher); var name = decryptName(encryptedProfile.getName(), profileCipher);
var about = decryptName(encryptedProfile.getAbout(), profileCipher); var about = decryptName(encryptedProfile.getAbout(), profileCipher);
var aboutEmoji = decryptName(encryptedProfile.getAboutEmoji(), profileCipher); var aboutEmoji = decryptName(encryptedProfile.getAboutEmoji(), profileCipher);
String unidentifiedAccess;
try {
unidentifiedAccess = encryptedProfile.getUnidentifiedAccess() == null
|| !profileCipher.verifyUnidentifiedAccess(Base64.getDecoder()
.decode(encryptedProfile.getUnidentifiedAccess()))
? null
: encryptedProfile.getUnidentifiedAccess();
} catch (IllegalArgumentException e) {
unidentifiedAccess = null;
}
final var nameParts = splitName(name); final var nameParts = splitName(name);
final var capabilities = new HashSet<Profile.Capability>();
if (encryptedProfile.getCapabilities().isGv1Migration()) {
capabilities.add(Profile.Capability.gv1Migration);
}
if (encryptedProfile.getCapabilities().isGv2()) {
capabilities.add(Profile.Capability.gv2);
}
if (encryptedProfile.getCapabilities().isStorage()) {
capabilities.add(Profile.Capability.storage);
}
return new Profile(new Date().getTime(), return new Profile(new Date().getTime(),
nameParts.first(), nameParts.first(),
nameParts.second(), nameParts.second(),
about, about,
aboutEmoji, aboutEmoji,
encryptedProfile.isUnrestrictedUnidentifiedAccess() getUnidentifiedAccessMode(encryptedProfile, profileCipher),
? Profile.UnidentifiedAccessMode.UNRESTRICTED getCapabilities(encryptedProfile));
: unidentifiedAccess != null
? Profile.UnidentifiedAccessMode.ENABLED
: Profile.UnidentifiedAccessMode.DISABLED,
capabilities);
} catch (InvalidCiphertextException e) { } catch (InvalidCiphertextException e) {
return null; return null;
} }
} }
public static Profile.UnidentifiedAccessMode getUnidentifiedAccessMode(
final SignalServiceProfile encryptedProfile, final ProfileCipher profileCipher
) {
if (encryptedProfile.isUnrestrictedUnidentifiedAccess()) {
return Profile.UnidentifiedAccessMode.UNRESTRICTED;
}
if (encryptedProfile.getUnidentifiedAccess() != null && profileCipher != null) {
final var unidentifiedAccessVerifier = Base64.getDecoder().decode(encryptedProfile.getUnidentifiedAccess());
if (profileCipher.verifyUnidentifiedAccess(unidentifiedAccessVerifier)) {
return Profile.UnidentifiedAccessMode.ENABLED;
}
}
return Profile.UnidentifiedAccessMode.DISABLED;
}
public static HashSet<Profile.Capability> getCapabilities(final SignalServiceProfile encryptedProfile) {
final var capabilities = new HashSet<Profile.Capability>();
if (encryptedProfile.getCapabilities().isGv1Migration()) {
capabilities.add(Profile.Capability.gv1Migration);
}
if (encryptedProfile.getCapabilities().isGv2()) {
capabilities.add(Profile.Capability.gv2);
}
if (encryptedProfile.getCapabilities().isStorage()) {
capabilities.add(Profile.Capability.storage);
}
return capabilities;
}
private static String decryptName( private static String decryptName(
final String encryptedName, final ProfileCipher profileCipher final String encryptedName, final ProfileCipher profileCipher
) throws InvalidCiphertextException { ) throws InvalidCiphertextException {