Revise group v2 proto parsing robustness.
This commit is contained in:
parent
20c72ce077
commit
4a04265e15
@ -107,18 +107,14 @@ public class GroupsV2Changes {
|
||||
groupMembershipBuilder.remove(address)
|
||||
groupMembershipBuilder.addNonPendingMember(address, role: role)
|
||||
|
||||
do {
|
||||
guard let profileKeyCiphertextData = member.profileKey else {
|
||||
throw OWSAssertionError("Missing profileKeyCiphertext.")
|
||||
}
|
||||
let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData))
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
|
||||
profileKeys[uuid] = profileKey
|
||||
} catch {
|
||||
owsFailDebug("Error parsing profile key: \(error)")
|
||||
guard let profileKeyCiphertextData = member.profileKey else {
|
||||
throw OWSAssertionError("Missing profileKeyCiphertext.")
|
||||
}
|
||||
let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData))
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
|
||||
profileKeys[uuid] = profileKey
|
||||
}
|
||||
|
||||
for action in changeActionsProto.deleteMembers {
|
||||
@ -168,14 +164,10 @@ public class GroupsV2Changes {
|
||||
throw OWSAssertionError("Invalid membership.")
|
||||
}
|
||||
|
||||
do {
|
||||
let profileKeyCiphertext = try presentation.getProfileKeyCiphertext()
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
profileKeys[uuid] = profileKey
|
||||
} catch {
|
||||
owsFailDebug("Error parsing profile key: \(error)")
|
||||
}
|
||||
let profileKeyCiphertext = try presentation.getProfileKeyCiphertext()
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
profileKeys[uuid] = profileKey
|
||||
}
|
||||
|
||||
for action in changeActionsProto.addPendingMembers {
|
||||
@ -194,13 +186,19 @@ public class GroupsV2Changes {
|
||||
guard let role = TSGroupMemberRole.role(for: protoRole) else {
|
||||
throw OWSAssertionError("Invalid role: \(protoRole.rawValue)")
|
||||
}
|
||||
let uuid = try groupV2Params.uuid(forUserId: userId)
|
||||
let address = SignalServiceAddress(uuid: uuid)
|
||||
guard let addedByUserID = pendingMember.addedByUserID else {
|
||||
throw OWSAssertionError("Group pending member missing addedByUserID.")
|
||||
}
|
||||
let addedByUuid = try groupV2Params.uuid(forUserId: addedByUserID)
|
||||
|
||||
let uuid: UUID
|
||||
let addedByUuid: UUID
|
||||
do {
|
||||
uuid = try groupV2Params.uuid(forUserId: userId)
|
||||
addedByUuid = try groupV2Params.uuid(forUserId: addedByUserID)
|
||||
} catch {
|
||||
owsFailDebug("Error parsing uuid: \(error)")
|
||||
continue
|
||||
}
|
||||
let address = SignalServiceAddress(uuid: uuid)
|
||||
guard !oldGroupMembership.allUsers.contains(address) else {
|
||||
throw OWSAssertionError("Invalid membership.")
|
||||
}
|
||||
@ -242,14 +240,10 @@ public class GroupsV2Changes {
|
||||
groupMembershipBuilder.remove(address)
|
||||
groupMembershipBuilder.addNonPendingMember(address, role: role)
|
||||
|
||||
do {
|
||||
let profileKeyCiphertext = try presentation.getProfileKeyCiphertext()
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
profileKeys[uuid] = profileKey
|
||||
} catch {
|
||||
owsFailDebug("Error parsing profile key: \(error)")
|
||||
}
|
||||
let profileKeyCiphertext = try presentation.getProfileKeyCiphertext()
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
profileKeys[uuid] = profileKey
|
||||
}
|
||||
|
||||
if let action = changeActionsProto.modifyTitle {
|
||||
|
||||
@ -242,18 +242,13 @@ public class GroupsV2Protos {
|
||||
role: role)
|
||||
members.append(member)
|
||||
|
||||
do {
|
||||
let uuid = try groupV2Params.uuid(forUserId: userID)
|
||||
guard let profileKeyCiphertextData = memberProto.profileKey else {
|
||||
throw OWSAssertionError("Group member missing profileKeyCiphertextData.")
|
||||
}
|
||||
let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData))
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
profileKeys[uuid] = profileKey
|
||||
} catch {
|
||||
owsFailDebug("Error parsing profile key: \(error)")
|
||||
guard let profileKeyCiphertextData = memberProto.profileKey else {
|
||||
throw OWSAssertionError("Group member missing profileKeyCiphertextData.")
|
||||
}
|
||||
let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData))
|
||||
let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext,
|
||||
uuid: uuid)
|
||||
profileKeys[uuid] = profileKey
|
||||
}
|
||||
|
||||
var pendingMembers = [GroupV2SnapshotImpl.PendingMember]()
|
||||
@ -271,13 +266,19 @@ public class GroupsV2Protos {
|
||||
throw OWSAssertionError("Group pending member missing addedByUserID.")
|
||||
}
|
||||
let timestamp = pendingMemberProto.timestamp
|
||||
|
||||
let uuid = try groupV2Params.uuid(forUserId: userId)
|
||||
let addedByUuid = try groupV2Params.uuid(forUserId: addedByUserId)
|
||||
|
||||
guard memberProto.hasRole, let role = memberProto.role else {
|
||||
throw OWSAssertionError("Group member missing role.")
|
||||
}
|
||||
|
||||
let uuid: UUID
|
||||
let addedByUuid: UUID
|
||||
do {
|
||||
uuid = try groupV2Params.uuid(forUserId: userId)
|
||||
addedByUuid = try groupV2Params.uuid(forUserId: addedByUserId)
|
||||
} catch {
|
||||
owsFailDebug("Error parsing uuid: \(error)")
|
||||
continue
|
||||
}
|
||||
let pendingMember = GroupV2SnapshotImpl.PendingMember(userID: userId,
|
||||
uuid: uuid,
|
||||
timestamp: timestamp,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user