Merge branch 'mlin/PR/SmallSenderKeyFixes' into release/5.19.0

This commit is contained in:
Michelle Linington 2021-08-27 16:10:59 -07:00
commit f617d5d589
6 changed files with 35 additions and 18 deletions

View File

@ -126,7 +126,7 @@ NS_DESIGNATED_INITIALIZER NS_SWIFT_NAME(init(grdbId:uniqueId:receivedAtTimestamp
wasIdentityVerified:(BOOL)wasIdentityVerified;
+ (instancetype)failedDecryptionForEnvelope:(SSKProtoEnvelope *)envelope
groupId:(nullable NSData *)groupId
untrustedGroupId:(nullable NSData *)untrustedGroupId
withTransaction:(SDSAnyWriteTransaction *)transaction;
+ (instancetype)failedDecryptionForSender:(nullable SignalServiceAddress *)sender

View File

@ -314,7 +314,7 @@ NSUInteger TSErrorMessageSchemaVersion = 2;
}
+ (instancetype)failedDecryptionForEnvelope:(SSKProtoEnvelope *)envelope
groupId:(nullable NSData *)groupId
untrustedGroupId:(nullable NSData *)untrustedGroupId
withTransaction:(SDSAnyWriteTransaction *)transaction
{
SignalServiceAddress *sender = [[SignalServiceAddress alloc] initWithUuidString:envelope.sourceUuid];
@ -323,9 +323,16 @@ NSUInteger TSErrorMessageSchemaVersion = 2;
return nil;
}
TSThread *thread;
if (groupId.length > 0) {
thread = [TSGroupThread fetchWithGroupId:groupId transaction:transaction];
TSThread *_Nullable thread = nil;
if (untrustedGroupId.length > 0) {
[TSGroupThread ensureGroupIdMappingForGroupId:untrustedGroupId transaction:writeTx];
TSGroupThread *_Nullable groupThread = [TSGroupThread fetchWithGroupId:untrustedGroupId
transaction:transaction];
// If we aren't sure that the sender is a member of the reported groupId, we should fall back
// to inserting the placeholder in the contact thread.
if ([groupThread.groupMembership isFullMember:sender]) {
thread = groupThread;
}
OWSAssertDebug(thread);
}
if (!thread) {

View File

@ -285,7 +285,7 @@ public class OWSMessageDecrypter: OWSMessageHandler {
private func processError(
_ error: Error,
envelope: SSKProtoEnvelope,
groupId: Data?,
untrustedGroupId: Data?,
cipherType: CiphertextMessage.MessageType,
contentHint: SealedSenderContentHint,
transaction: SDSAnyWriteTransaction
@ -346,13 +346,13 @@ public class OWSMessageDecrypter: OWSMessageHandler {
// If default, insert an error message right away
errorMessage = TSErrorMessage.failedDecryption(
for: envelope,
groupId: groupId,
untrustedGroupId: untrustedGroupId,
with: transaction)
case .resendable:
// If resendable, insert a placeholder
errorMessage = OWSRecoverableDecryptionPlaceholder(
failedEnvelope: envelope,
groupId: groupId,
untrustedGroupId: untrustedGroupId,
transaction: transaction)
case .implicit:
errorMessage = nil
@ -587,7 +587,7 @@ public class OWSMessageDecrypter: OWSMessageHandler {
let wrappedError = processError(
error,
envelope: envelope,
groupId: nil,
untrustedGroupId: nil,
cipherType: cipherType,
contentHint: .default,
transaction: transaction
@ -691,7 +691,7 @@ public class OWSMessageDecrypter: OWSMessageHandler {
return .failure(handleUnidentifiedSenderDecryptionError(
error: outerError.underlyingError,
envelope: envelope.buildIdentifiedCopy(using: outerError),
groupId: outerError.groupId,
untrustedGroupId: outerError.groupId,
cipherType: outerError.cipherType,
contentHint: SealedSenderContentHint(outerError.contentHint),
transaction: transaction)
@ -700,7 +700,7 @@ public class OWSMessageDecrypter: OWSMessageHandler {
return .failure(handleUnidentifiedSenderDecryptionError(
error: error,
envelope: envelope,
groupId: nil,
untrustedGroupId: nil,
cipherType: .plaintext,
contentHint: .default,
transaction: transaction)
@ -760,7 +760,7 @@ public class OWSMessageDecrypter: OWSMessageHandler {
func handleUnidentifiedSenderDecryptionError(
error: Error,
envelope: SSKProtoEnvelope,
groupId: Data?,
untrustedGroupId: Data?,
cipherType: CiphertextMessage.MessageType,
contentHint: SealedSenderContentHint,
transaction: SDSAnyWriteTransaction
@ -771,7 +771,7 @@ public class OWSMessageDecrypter: OWSMessageHandler {
} else if isSignalClientError(error) {
return processError(error,
envelope: envelope,
groupId: groupId,
untrustedGroupId: untrustedGroupId,
cipherType: cipherType,
contentHint: contentHint,
transaction: transaction)

View File

@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initErrorMessageWithBuilder:(TSErrorMessageBuilder *)errorMessageBuilder NS_UNAVAILABLE;
- (nullable instancetype)initWithFailedEnvelope:(SSKProtoEnvelope *)envelope
groupId:(nullable NSData *)groupId
untrustedGroupId:(nullable NSData *)untrustedGroupId
transaction:(SDSAnyWriteTransaction *)writeTx NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

View File

@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSRecoverableDecryptionPlaceholder
- (nullable instancetype)initWithFailedEnvelope:(SSKProtoEnvelope *)envelope
groupId:(nullable NSData *)groupId
untrustedGroupId:(nullable NSData *)untrustedGroupId
transaction:(SDSAnyWriteTransaction *)writeTx
{
SignalServiceAddress *sender = [[SignalServiceAddress alloc] initWithUuidString:envelope.sourceUuid];
@ -21,8 +21,14 @@ NS_ASSUME_NONNULL_BEGIN
}
TSThread *thread;
if (groupId.length > 0) {
thread = [TSGroupThread fetchWithGroupId:groupId transaction:writeTx];
if (untrustedGroupId.length > 0) {
[TSGroupThread ensureGroupIdMappingForGroupId:untrustedGroupId transaction:writeTx];
TSGroupThread *_Nullable groupThread = [TSGroupThread fetchWithGroupId:untrustedGroupId transaction:writeTx];
// If we aren't sure that the sender is a member of the reported groupId, we should fall back
// to inserting the placeholder in the contact thread.
if ([groupThread.groupMembership isFullMember:sender]) {
thread = groupThread;
}
OWSAssertDebug(thread);
}
if (!thread) {

View File

@ -103,7 +103,11 @@ public class SenderKeyStore: NSObject {
let distributionId = distributionIdForSendingToThreadId(thread.uniqueId, writeTx: writeTx)
guard let keyMetadata = getKeyMetadata(for: distributionId, readTx: writeTx) else { return }
if !keyMetadata.isValid {
let currentKeyRecipients = Set(keyMetadata.keyRecipients.keys)
let currentGroupMembership = thread.groupMembership.fullMembers
let didSomeoneLeaveTheGroup = currentKeyRecipients.subtracting(currentGroupMembership).count > 0
if !keyMetadata.isValid || didSomeoneLeaveTheGroup {
setMetadata(nil, for: distributionId, writeTx: writeTx)
}
}