restrict self device id in message building, not in recipient data model

pull/1/head
Michael Kirk 7 years ago
parent 6749eccaac
commit 7eaaab7be4

@ -71,23 +71,8 @@ NS_ASSUME_NONNULL_BEGIN
if (!self) {
return self;
}
OWSAssertDebug(self.tsAccountManager.localNumber.length > 0);
if ([self.tsAccountManager.localNumber isEqualToString:textSecureIdentifier]) {
// Default to no devices.
//
// This instance represents our own account and is used for sending
// sync message to linked devices. We shouldn't have any linked devices
// yet when we create the "self" SignalRecipient, and we don't need to
// send sync messages to the primary - we ARE the primary.
_devices = [NSOrderedSet new];
} else {
// Default to sending to just primary device.
//
// OWSMessageSender will correct this if it is wrong the next time
// we send a message to this recipient.
_devices = [NSOrderedSet orderedSetWithObject:@(OWSDevicePrimaryDeviceId)];
}
_devices = [NSOrderedSet orderedSetWithObject:@(OWSDevicePrimaryDeviceId)];
return self;
}
@ -103,11 +88,6 @@ NS_ASSUME_NONNULL_BEGIN
_devices = [NSOrderedSet new];
}
if ([self.uniqueId isEqual:self.tsAccountManager.localNumber] &&
[self.devices containsObject:@(OWSDevicePrimaryDeviceId)]) {
OWSFailDebug(@"self as recipient device");
}
return self;
}
@ -129,12 +109,6 @@ NS_ASSUME_NONNULL_BEGIN
{
OWSAssertDebug(devices.count > 0);
if ([self.uniqueId isEqual:self.tsAccountManager.localNumber] &&
[devices containsObject:@(OWSDevicePrimaryDeviceId)]) {
OWSFailDebug(@"adding self as recipient device");
return;
}
NSMutableOrderedSet *updatedDevices = [self.devices mutableCopy];
[updatedDevices unionSet:devices];
self.devices = [updatedDevices copy];

@ -819,8 +819,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}];
}
- (nullable NSArray<NSDictionary *> *)deviceMessagesForMessageSendSafe:(OWSMessageSend *)messageSend
error:(NSError **)errorHandle
- (nullable NSArray<NSDictionary *> *)deviceMessagesForMessageSend:(OWSMessageSend *)messageSend
error:(NSError **)errorHandle
{
OWSAssertDebug(messageSend);
OWSAssertDebug(errorHandle);
@ -830,7 +830,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSArray<NSDictionary *> *deviceMessages;
@try {
deviceMessages = [self throws_deviceMessagesForMessageSendUnsafe:messageSend];
deviceMessages = [self throws_deviceMessagesForMessageSend:messageSend];
} @catch (NSException *exception) {
if ([exception.name isEqualToString:UntrustedIdentityKeyException]) {
// This *can* happen under normal usage, but it should happen relatively rarely.
@ -964,7 +964,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSError *deviceMessagesError;
NSArray<NSDictionary *> *_Nullable deviceMessages =
[self deviceMessagesForMessageSendSafe:messageSend error:&deviceMessagesError];
[self deviceMessagesForMessageSend:messageSend error:&deviceMessagesError];
if (deviceMessagesError || !deviceMessages) {
OWSAssertDebug(deviceMessagesError);
return messageSend.failure(deviceMessagesError);
@ -1398,7 +1398,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[self sendMessageToRecipient:messageSend];
}
- (NSArray<NSDictionary *> *)throws_deviceMessagesForMessageSendUnsafe:(OWSMessageSend *)messageSend
- (NSArray<NSDictionary *> *)throws_deviceMessagesForMessageSend:(OWSMessageSend *)messageSend
{
OWSAssertDebug(messageSend.message);
OWSAssertDebug(messageSend.recipient);
@ -1423,11 +1423,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSMutableArray<NSNumber *> *deviceIds = [recipient.devices mutableCopy];
OWSAssertDebug(deviceIds);
if (messageSend.isUDSend && messageSend.isLocalNumber) {
OWSLogVerbose(@"Adding device message for UD send to local device.");
OWSAssertDebug(![deviceIds containsObject:@(OWSDevicePrimaryDeviceId)]);
[deviceIds addObject:@(OWSDevicePrimaryDeviceId)];
if (messageSend.isLocalNumber) {
[deviceIds removeObject:@(OWSDevicePrimaryDeviceId)];
}
for (NSNumber *deviceId in deviceIds) {

@ -2,10 +2,10 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "SignalRecipient.h"
#import "MockSSKEnvironment.h"
#import "OWSPrimaryStorage.h"
#import "SSKBaseTestObjC.h"
#import "SignalRecipient.h"
#import "TSAccountManager.h"
#import "TestAppContext.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
@ -49,4 +49,16 @@
}];
}
- (void)testRecipientWithExistingRecord
{
// Sanity Check
XCTAssertNotNil(self.localNumber);
NSString *recipientId = @"+15551231234";
[self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[SignalRecipient markRecipientAsRegisteredAndGet:recipientId transaction:transaction];
XCTAssertTrue([SignalRecipient isRegisteredRecipient:recipientId transaction:transaction]);
}];
}
@end

Loading…
Cancel
Save