ensure blocking keychange message has identityKey before proceeding

This is increasingly irrelevant due to recent safety number changes, but
legacy clients with old messages can still run into this.

FIXES: https://github.com/WhisperSystems/Signal-iOS/issues/2346

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 8b724c5d7e
commit 3f4dcecf15

@ -287,7 +287,14 @@ NS_ASSUME_NONNULL_BEGIN
if (!isMissing) { if (!isMissing) {
continue; continue;
} }
[missingUnseenSafetyNumberChanges addObject:safetyNumberChange.newIdentityKey];
NSData *_Nullable newIdentityKey = safetyNumberChange.newIdentityKey;
if (newIdentityKey == nil) {
OWSFail(@"Safety number change was missing it's new identity key.");
continue;
}
[missingUnseenSafetyNumberChanges addObject:newIdentityKey];
} }
// Count the de-duplicated "blocking" safety number changes and all // Count the de-duplicated "blocking" safety number changes and all

@ -1,9 +1,5 @@
// //
// TSInvalidIdentityKeyErrorMessage.h // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Signal
//
// Created by Frederic Jacobs on 15/02/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
// //
#import "TSErrorMessage.h" #import "TSErrorMessage.h"
@ -15,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface TSInvalidIdentityKeyErrorMessage : TSErrorMessage @interface TSInvalidIdentityKeyErrorMessage : TSErrorMessage
- (void)acceptNewIdentityKey; - (void)acceptNewIdentityKey;
- (NSData *)newIdentityKey; - (nullable NSData *)newIdentityKey;
- (NSString *)theirSignalId; - (NSString *)theirSignalId;
@end @end

@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
NSAssert(NO, @"Method needs to be implemented in subclasses of TSInvalidIdentityKeyErrorMessage."); NSAssert(NO, @"Method needs to be implemented in subclasses of TSInvalidIdentityKeyErrorMessage.");
} }
- (NSString *)newIdentityKey - (nullable NSData *)newIdentityKey
{ {
NSAssert(NO, @"Method needs to be implemented in subclasses of TSInvalidIdentityKeyErrorMessage."); NSAssert(NO, @"Method needs to be implemented in subclasses of TSInvalidIdentityKeyErrorMessage.");
return nil; return nil;

@ -74,9 +74,9 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
NSData *newKey = [self newIdentityKey]; NSData *_Nullable newKey = [self newIdentityKey];
if (!newKey) { if (!newKey) {
DDLogError(@"Couldn't extract identity key to accept"); OWSFail(@"Couldn't extract identity key to accept");
return; return;
} }
@ -101,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN
}); });
} }
- (NSData *)newIdentityKey - (nullable NSData *)newIdentityKey
{ {
if (!self.envelope) { if (!self.envelope) {
DDLogError(@"Error message had no envelope data to extract key from"); DDLogError(@"Error message had no envelope data to extract key from");

@ -50,12 +50,18 @@ NSString *TSInvalidRecipientKey = @"TSInvalidRecipientKey";
OWSFail(@"accepting new identity key is deprecated."); OWSFail(@"accepting new identity key is deprecated.");
// Saving a new identity mutates the session store so it must happen on the sessionStoreQueue // Saving a new identity mutates the session store so it must happen on the sessionStoreQueue
NSData *_Nullable newIdentityKey = self.newIdentityKey;
if (!newIdentityKey) {
OWSFail(@"newIdentityKey is unexpectedly nil. Bad Prekey bundle?: %@", self.preKeyBundle);
return;
}
dispatch_async([OWSDispatch sessionStoreQueue], ^{ dispatch_async([OWSDispatch sessionStoreQueue], ^{
[[OWSIdentityManager sharedManager] saveRemoteIdentity:self.newIdentityKey recipientId:self.recipientId]; [[OWSIdentityManager sharedManager] saveRemoteIdentity:newIdentityKey recipientId:self.recipientId];
}); });
} }
- (NSData *)newIdentityKey - (nullable NSData *)newIdentityKey
{ {
return [self.preKeyBundle.identityKey removeKeyType]; return [self.preKeyBundle.identityKey removeKeyType];
} }

Loading…
Cancel
Save