Prevent invalid profile keys from being processed for storage service

This commit is contained in:
AsamK 2025-10-24 09:52:43 +02:00
parent 06fd350e9c
commit 7b08225c57
2 changed files with 16 additions and 1 deletions

View File

@ -172,6 +172,10 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
e164 = firstNonEmpty(remote.e164, local.e164);
}
final var remoteProfileKey = remote.profileKey.size() == 0
|| KeyUtils.profileKeyOrNull(remote.profileKey.toByteArray()) == null
? ByteString.EMPTY
: remote.profileKey;
final var mergedBuilder = remote.newBuilder()
.aci(local.aci.isEmpty() ? remote.aci : local.aci)
.e164(e164)
@ -181,7 +185,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
.systemGivenName(account.isPrimaryDevice() ? local.systemGivenName : remote.systemGivenName)
.systemFamilyName(account.isPrimaryDevice() ? local.systemFamilyName : remote.systemFamilyName)
.systemNickname(remote.systemNickname)
.profileKey(firstNonEmpty(remote.profileKey, local.profileKey))
.profileKey(firstNonEmpty(remoteProfileKey, local.profileKey))
.username(firstNonEmpty(remote.username, local.username))
.identityState(identityState)
.identityKey(identityKey)

View File

@ -96,6 +96,17 @@ public class KeyUtils {
}
}
public static ProfileKey profileKeyOrNull(byte[] profileKey) {
if (profileKey == null) {
return null;
}
try {
return new ProfileKey(profileKey);
} catch (InvalidInputException e) {
return null;
}
}
public static String createPassword() {
return getSecret(18);
}