Merge pull request #464 from hjubb/fix_npe_and_fail_contact_parse

fix: return early if no profile name (prefs likely invalid state) and ignore contacts whose publicKey fails to parse
This commit is contained in:
Niels Andriesse 2021-02-26 10:13:56 +11:00 committed by GitHub
commit adfbcb5be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -34,7 +34,7 @@ object MultiDeviceProtocol {
}.map { recipient ->
ConfigurationMessage.Contact(recipient.address.serialize(), recipient.name!!, recipient.profileAvatar, recipient.profileKey)
}
val configurationMessage = ConfigurationMessage.getCurrent(contacts)
val configurationMessage = ConfigurationMessage.getCurrent(contacts) ?: return
val serializedMessage = configurationMessage.toProto()!!.toByteArray()
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
val address = SignalServiceAddress(userPublicKey)
@ -58,7 +58,7 @@ object MultiDeviceProtocol {
}.map { recipient ->
ConfigurationMessage.Contact(recipient.address.serialize(), recipient.name!!, recipient.profileAvatar, recipient.profileKey)
}
val configurationMessage = ConfigurationMessage.getCurrent(contacts)
val configurationMessage = ConfigurationMessage.getCurrent(contacts) ?: return
val serializedMessage = configurationMessage.toProto()!!.toByteArray()
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
val address = SignalServiceAddress(userPublicKey)

View File

@ -67,7 +67,11 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
fun toProto(): SignalServiceProtos.ConfigurationMessage.Contact? {
val result = SignalServiceProtos.ConfigurationMessage.Contact.newBuilder()
result.name = this.name
result.publicKey = ByteString.copyFrom(Hex.fromStringCondensed(publicKey))
try {
result.publicKey = ByteString.copyFrom(Hex.fromStringCondensed(publicKey))
} catch (e: Exception) {
return null
}
if (!this.profilePicture.isNullOrEmpty()) {
result.profilePicture = this.profilePicture
}
@ -83,13 +87,13 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
companion object {
fun getCurrent(contacts: List<Contact>): ConfigurationMessage {
fun getCurrent(contacts: List<Contact>): ConfigurationMessage? {
val closedGroups = mutableListOf<ClosedGroup>()
val openGroups = mutableListOf<String>()
val sharedConfig = MessagingConfiguration.shared
val storage = sharedConfig.storage
val context = sharedConfig.context
val displayName = TextSecurePreferences.getProfileName(context)!!
val displayName = TextSecurePreferences.getProfileName(context) ?: return null
val profilePicture = TextSecurePreferences.getProfilePictureURL(context)
val profileKey = ProfileKeyUtil.getProfileKey(context)
val groups = storage.getAllGroups()