From 02877a01646fd5f4e6d61de69d623e68e91e1a32 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 8 Nov 2019 14:59:36 +1100 Subject: [PATCH] Re-enable sync message validation --- SignalServiceKit/src/Messages/OWSMessageManager.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 1686ea842..709b74bd7 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -901,12 +901,14 @@ NS_ASSUME_NONNULL_BEGIN return; } - NSString *localNumber = self.tsAccountManager.localNumber; -// if (![localNumber isEqualToString:envelope.source]) { -// // Sync messages should only come from linked devices. -// OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorSyncMessageFromUnknownSource], envelope); -// return; -// } + NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey; + NSSet *linkedDeviceHexEncodedPublicKeys = [LKDatabaseUtilities getLinkedDeviceHexEncodedPublicKeysFor:userHexEncodedPublicKey in:transaction]; + if (![linkedDeviceHexEncodedPublicKeys contains:^BOOL(NSString *hexEncodedPublicKey) { + return [hexEncodedPublicKey isEqual:envelope.source]; + }]) { + OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorSyncMessageFromUnknownSource], envelope); + return; + } if (syncMessage.sent) { OWSIncomingSentMessageTranscript *transcript =