Debug SSKs further

This commit is contained in:
nielsandriesse 2020-10-01 13:46:13 +10:00
parent 4325756395
commit b1d9cb0cf9
2 changed files with 9 additions and 13 deletions

View file

@ -411,7 +411,9 @@ public final class ClosedGroupsProtocol : NSObject {
// Respond to the request
print("[Loki] Responding to sender key request from: \(senderPublicKey).")
SessionManagementProtocol.sendSessionRequestIfNeeded(to: senderPublicKey, using: transaction) // This internally takes care of multi device
let userRatchet = SharedSenderKeysImplementation.shared.generateRatchet(for: groupPublicKey, senderPublicKey: userPublicKey, using: transaction)
guard let userRatchet = Storage.getClosedGroupRatchet(for: groupPublicKey, senderPublicKey: userPublicKey) else {
return print("[Loki] Missing own ratchet.")
}
let userSenderKey = ClosedGroupSenderKey(chainKey: Data(hex: userRatchet.chainKey), keyIndex: userRatchet.keyIndex, publicKey: Data(hex: userPublicKey))
let thread = TSContactThread.getOrCreateThread(withContactId: senderPublicKey, transaction: transaction)
thread.save(with: transaction)
@ -424,20 +426,9 @@ public final class ClosedGroupsProtocol : NSObject {
private static func handleSenderKeyMessage(_ closedGroupUpdate: SSKProtoDataMessageClosedGroupUpdate, from senderPublicKey: String, using transaction: YapDatabaseReadWriteTransaction) {
// Prepare
let groupPublicKey = closedGroupUpdate.groupPublicKey.toHexString()
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
guard let thread = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction) else {
return print("[Loki] Ignoring closed group sender key for nonexistent group.")
}
let group = thread.groupModel
guard let senderKey = closedGroupUpdate.senderKeys.first else {
return print("[Loki] Ignoring invalid closed group sender key.")
}
// Check that the requesting user is a member of the group
var membersAndLinkedDevices: Set<String> = Set(group.groupMemberIds)
for member in group.groupMemberIds {
let deviceLinks = OWSPrimaryStorage.shared().getDeviceLinks(for: member, in: transaction)
membersAndLinkedDevices.formUnion(deviceLinks.flatMap { [ $0.master.publicKey, $0.slave.publicKey ] })
}
guard senderKey.publicKey.toHexString() == senderPublicKey else {
return print("[Loki] Ignoring invalid closed group sender key.")
}

View file

@ -177,7 +177,12 @@ public final class SharedSenderKeysImplementation : NSObject {
throw RatchetingError.messageKeyMissing(targetKeyIndex: keyIndex, groupPublicKey: groupPublicKey, senderPublicKey: senderPublicKey)
}
let aes = try AES(key: Data(hex: messageKey).bytes, blockMode: gcm, padding: .noPadding)
return Data(try aes.decrypt(ciphertext.bytes))
do {
return Data(try aes.decrypt(ciphertext.bytes))
} catch {
ClosedGroupsProtocol.requestSenderKey(for: groupPublicKey, senderPublicKey: senderPublicKey, using: transaction)
throw error
}
}
@objc public func isClosedGroup(_ publicKey: String) -> Bool {