|
|
@ -71,6 +71,7 @@ public enum MessageReceiver {
|
|
|
|
(plaintext, sender) = try decryptWithSessionProtocol(ciphertext: ciphertext, using: userX25519KeyPair)
|
|
|
|
(plaintext, sender) = try decryptWithSessionProtocol(ciphertext: ciphertext, using: userX25519KeyPair)
|
|
|
|
case .closedGroupCiphertext:
|
|
|
|
case .closedGroupCiphertext:
|
|
|
|
guard let hexEncodedGroupPublicKey = envelope.source, SNMessagingKitConfiguration.shared.storage.isClosedGroup(hexEncodedGroupPublicKey) else { throw Error.invalidGroupPublicKey }
|
|
|
|
guard let hexEncodedGroupPublicKey = envelope.source, SNMessagingKitConfiguration.shared.storage.isClosedGroup(hexEncodedGroupPublicKey) else { throw Error.invalidGroupPublicKey }
|
|
|
|
|
|
|
|
do {
|
|
|
|
var keyPairs = Storage.shared.getClosedGroupEncryptionKeyPairs(for: hexEncodedGroupPublicKey)
|
|
|
|
var keyPairs = Storage.shared.getClosedGroupEncryptionKeyPairs(for: hexEncodedGroupPublicKey)
|
|
|
|
guard !keyPairs.isEmpty else { throw Error.noGroupKeyPair }
|
|
|
|
guard !keyPairs.isEmpty else { throw Error.noGroupKeyPair }
|
|
|
|
// Loop through all known group key pairs in reverse order (i.e. try the latest key pair first (which'll more than
|
|
|
|
// Loop through all known group key pairs in reverse order (i.e. try the latest key pair first (which'll more than
|
|
|
@ -89,6 +90,12 @@ public enum MessageReceiver {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try decrypt()
|
|
|
|
try decrypt()
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
// Fall back on the V1 method
|
|
|
|
|
|
|
|
guard let privateKey = SNMessagingKitConfiguration.shared.storage.getClosedGroupPrivateKey(for: hexEncodedGroupPublicKey) else { throw Error.noGroupKeyPair }
|
|
|
|
|
|
|
|
let keyPair = try ECKeyPair(publicKeyData: Data(hex: hexEncodedGroupPublicKey.removing05PrefixIfNeeded()), privateKeyData: Data(hex: privateKey))
|
|
|
|
|
|
|
|
(plaintext, sender) = try decryptWithSessionProtocol(ciphertext: ciphertext, using: keyPair)
|
|
|
|
|
|
|
|
}
|
|
|
|
groupPublicKey = envelope.source
|
|
|
|
groupPublicKey = envelope.source
|
|
|
|
default: throw Error.unknownEnvelopeType
|
|
|
|
default: throw Error.unknownEnvelopeType
|
|
|
|
}
|
|
|
|
}
|
|
|
|