mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Store available profile data even if we don't have the profile key
This commit is contained in:
parent
7364f0f7cf
commit
19c004e987
3 changed files with 49 additions and 35 deletions
|
@ -556,14 +556,6 @@ public class Manager implements Closeable {
|
|||
Profile getRecipientProfile(
|
||||
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 now = new Date().getTime();
|
||||
|
@ -590,7 +582,18 @@ public class Manager implements Closeable {
|
|||
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);
|
||||
|
||||
return profile;
|
||||
|
|
|
@ -233,6 +233,9 @@ public class RecipientStore implements ContactsStore, ProfileStore {
|
|||
final var newRecipient = Recipient.newBuilder(recipient)
|
||||
.withProfileKey(profileKey)
|
||||
.withProfileKeyCredential(null)
|
||||
.withProfile(recipient.getProfile() == null
|
||||
? null
|
||||
: Profile.newBuilder(recipient.getProfile()).withLastUpdateTimestamp(0).build())
|
||||
.build();
|
||||
storeRecipientLocked(recipientId, newRecipient);
|
||||
}
|
||||
|
|
|
@ -21,43 +21,51 @@ public class ProfileUtils {
|
|||
var name = decryptName(encryptedProfile.getName(), profileCipher);
|
||||
var about = decryptName(encryptedProfile.getAbout(), 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 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(),
|
||||
nameParts.first(),
|
||||
nameParts.second(),
|
||||
about,
|
||||
aboutEmoji,
|
||||
encryptedProfile.isUnrestrictedUnidentifiedAccess()
|
||||
? Profile.UnidentifiedAccessMode.UNRESTRICTED
|
||||
: unidentifiedAccess != null
|
||||
? Profile.UnidentifiedAccessMode.ENABLED
|
||||
: Profile.UnidentifiedAccessMode.DISABLED,
|
||||
capabilities);
|
||||
getUnidentifiedAccessMode(encryptedProfile, profileCipher),
|
||||
getCapabilities(encryptedProfile));
|
||||
} catch (InvalidCiphertextException e) {
|
||||
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(
|
||||
final String encryptedName, final ProfileCipher profileCipher
|
||||
) throws InvalidCiphertextException {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue