mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +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(
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
profile = decryptProfileAndDownloadAvatar(recipientId, profileKey, encryptedProfile);
|
||||||
|
}
|
||||||
account.getProfileStore().storeProfile(recipientId, profile);
|
account.getProfileStore().storeProfile(recipientId, profile);
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,38 @@ 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);
|
||||||
|
return new Profile(new Date().getTime(),
|
||||||
|
nameParts.first(),
|
||||||
|
nameParts.second(),
|
||||||
|
about,
|
||||||
|
aboutEmoji,
|
||||||
|
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>();
|
final var capabilities = new HashSet<Profile.Capability>();
|
||||||
if (encryptedProfile.getCapabilities().isGv1Migration()) {
|
if (encryptedProfile.getCapabilities().isGv1Migration()) {
|
||||||
capabilities.add(Profile.Capability.gv1Migration);
|
capabilities.add(Profile.Capability.gv1Migration);
|
||||||
|
@ -42,20 +63,7 @@ public class ProfileUtils {
|
||||||
if (encryptedProfile.getCapabilities().isStorage()) {
|
if (encryptedProfile.getCapabilities().isStorage()) {
|
||||||
capabilities.add(Profile.Capability.storage);
|
capabilities.add(Profile.Capability.storage);
|
||||||
}
|
}
|
||||||
return new Profile(new Date().getTime(),
|
return capabilities;
|
||||||
nameParts.first(),
|
|
||||||
nameParts.second(),
|
|
||||||
about,
|
|
||||||
aboutEmoji,
|
|
||||||
encryptedProfile.isUnrestrictedUnidentifiedAccess()
|
|
||||||
? Profile.UnidentifiedAccessMode.UNRESTRICTED
|
|
||||||
: unidentifiedAccess != null
|
|
||||||
? Profile.UnidentifiedAccessMode.ENABLED
|
|
||||||
: Profile.UnidentifiedAccessMode.DISABLED,
|
|
||||||
capabilities);
|
|
||||||
} catch (InvalidCiphertextException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String decryptName(
|
private static String decryptName(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue