fix a crash where the configuration message contacts info may contain invalid profile key

pull/507/head
ryanzhao 4 years ago
parent e049d05891
commit 50465c04bf

@ -189,8 +189,10 @@ extension MessageReceiver {
let storage = SNMessagingKitConfiguration.shared.storage let storage = SNMessagingKitConfiguration.shared.storage
let transaction = transaction as! YapDatabaseReadWriteTransaction let transaction = transaction as! YapDatabaseReadWriteTransaction
// Profile // Profile
var userProfileKy: OWSAES256Key? = nil
if let profileKey = message.profileKey { userProfileKy = OWSAES256Key(data: profileKey) }
updateProfileIfNeeded(publicKey: userPublicKey, name: message.displayName, profilePictureURL: message.profilePictureURL, updateProfileIfNeeded(publicKey: userPublicKey, name: message.displayName, profilePictureURL: message.profilePictureURL,
profileKey: given(message.profileKey) { OWSAES256Key(data: $0)! }, sentTimestamp: message.sentTimestamp!, transaction: transaction) profileKey: userProfileKy, sentTimestamp: message.sentTimestamp!, transaction: transaction)
// Initial configuration sync // Initial configuration sync
if !UserDefaults.standard[.hasSyncedInitialConfiguration] { if !UserDefaults.standard[.hasSyncedInitialConfiguration] {
UserDefaults.standard[.hasSyncedInitialConfiguration] = true UserDefaults.standard[.hasSyncedInitialConfiguration] = true
@ -199,7 +201,7 @@ extension MessageReceiver {
for contactInfo in message.contacts { for contactInfo in message.contacts {
let sessionID = contactInfo.publicKey! let sessionID = contactInfo.publicKey!
let contact = Contact(sessionID: sessionID) let contact = Contact(sessionID: sessionID)
contact.profileEncryptionKey = given(contactInfo.profileKey) { OWSAES256Key(data: $0)! } if let profileKey = contactInfo.profileKey { contact.profileEncryptionKey = OWSAES256Key(data: profileKey) }
contact.profilePictureURL = contactInfo.profilePictureURL contact.profilePictureURL = contactInfo.profilePictureURL
contact.name = contactInfo.displayName contact.name = contactInfo.displayName
Storage.shared.setContact(contact, using: transaction) Storage.shared.setContact(contact, using: transaction)

Loading…
Cancel
Save