From e5856b2ac5b0b0c1bb98741c311f2922340449b9 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 25 Jul 2018 15:19:40 -0600 Subject: [PATCH] CR: Add back deprecated constructor to debug list --- .../ViewControllers/DebugUI/DebugUIMessages.m | 8 ++++- ...SInvalidIdentityKeyReceivingErrorMessage.h | 5 +++ ...SInvalidIdentityKeyReceivingErrorMessage.m | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 6d9e0c7be..d2609948c 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -3553,7 +3553,13 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac withTransaction:transaction]]; [result addObject:[TSErrorMessage corruptedMessageWithEnvelope:[self createEnvelopeForThread:thread] withTransaction:transaction]]; - + + + TSInvalidIdentityKeyReceivingErrorMessage *_Nullable blockingSNChangeMessage = + [TSInvalidIdentityKeyReceivingErrorMessage untrustedKeyWithEnvelope:[self createEnvelopeForThread:thread] + withTransaction:transaction]; + OWSAssert(blockingSNChangeMessage); + [result addObject:blockingSNChangeMessage]; [result addObject:[[TSErrorMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread failedMessageType:TSErrorMessageNonBlockingIdentityChange diff --git a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.h b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.h index fd919d10c..d4dc75140 100644 --- a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.h +++ b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.h @@ -6,10 +6,15 @@ NS_ASSUME_NONNULL_BEGIN +@class SSKEnvelope; + // DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may // exist, so we should keep this class around to honor their old behavior. @interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage ++ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope + withTransaction:(YapDatabaseReadWriteTransaction *)transaction; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m index 5747c5d5c..659924e41 100644 --- a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m +++ b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m @@ -33,6 +33,39 @@ NS_ASSUME_NONNULL_BEGIN @synthesize envelopeData = _envelopeData; ++ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope + withTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + TSContactThread *contactThread = + [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction]; + TSInvalidIdentityKeyReceivingErrorMessage *errorMessage = + [[self alloc] initForUnknownIdentityKeyWithTimestamp:envelope.timestamp + inThread:contactThread + incomingEnvelope:envelope]; + return errorMessage; +} + +- (nullable instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp + inThread:(TSThread *)thread + incomingEnvelope:(SSKEnvelope *)envelope +{ + self = [self initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageWrongTrustedIdentityKey]; + if (!self) { + return self; + } + + NSError *error; + _envelopeData = [envelope serializedDataAndReturnError:&error]; + if (!_envelopeData || error != nil) { + OWSFail(@"%@ failure: envelope data failed with error: %@", self.logTag, error); + return nil; + } + + _authorId = envelope.source; + + return self; +} + - (nullable SSKEnvelope *)envelope { if (!_envelope) {