2017-06-22 18:12:24 +02:00
|
|
|
//
|
2018-02-07 18:44:09 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-06-22 18:12:24 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "OWSOutgoingNullMessage.h"
|
|
|
|
#import "Cryptography.h"
|
2017-09-22 16:30:35 +02:00
|
|
|
#import "NSDate+OWS.h"
|
2017-08-01 19:53:51 +02:00
|
|
|
#import "OWSSignalServiceProtos.pb.h"
|
|
|
|
#import "OWSVerificationStateSyncMessage.h"
|
2017-09-22 16:30:35 +02:00
|
|
|
#import "TSContactThread.h"
|
2017-06-22 18:12:24 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@interface OWSOutgoingNullMessage ()
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) OWSVerificationStateSyncMessage *verificationStateSyncMessage;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2018-02-07 18:44:09 +01:00
|
|
|
#pragma mark -
|
|
|
|
|
2017-06-22 18:12:24 +02:00
|
|
|
@implementation OWSOutgoingNullMessage
|
|
|
|
|
|
|
|
- (instancetype)initWithContactThread:(TSContactThread *)contactThread
|
|
|
|
verificationStateSyncMessage:(OWSVerificationStateSyncMessage *)verificationStateSyncMessage
|
|
|
|
{
|
2018-02-07 18:44:09 +01:00
|
|
|
self = [super initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
inThread:contactThread
|
|
|
|
messageBody:nil
|
|
|
|
attachmentIds:[NSMutableArray new]
|
|
|
|
expiresInSeconds:0
|
|
|
|
expireStartedAt:0
|
|
|
|
isVoiceMessage:NO
|
2018-04-19 17:25:11 +02:00
|
|
|
groupMetaMessage:TSGroupMessageUnspecified
|
2018-02-07 18:44:09 +01:00
|
|
|
quotedMessage:nil];
|
2017-06-22 18:12:24 +02:00
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
_verificationStateSyncMessage = verificationStateSyncMessage;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - override TSOutgoingMessage
|
|
|
|
|
2017-08-01 23:01:07 +02:00
|
|
|
- (NSData *)buildPlainTextData:(SignalRecipient *)recipient
|
2017-06-22 18:12:24 +02:00
|
|
|
{
|
|
|
|
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
|
|
|
OWSSignalServiceProtosNullMessageBuilder *nullMessageBuilder = [OWSSignalServiceProtosNullMessageBuilder new];
|
|
|
|
|
2017-06-22 20:32:06 +02:00
|
|
|
NSUInteger contentLength = self.verificationStateSyncMessage.unpaddedVerifiedLength;
|
|
|
|
|
|
|
|
OWSAssert(self.verificationStateSyncMessage.paddingBytesLength > 0);
|
2017-06-22 21:13:34 +02:00
|
|
|
|
|
|
|
// We add the same amount of padding in the VerificationStateSync message and it's coresponding NullMessage so that
|
|
|
|
// the sync message is indistinguishable from an outgoing Sent transcript corresponding to the NullMessage. We pad
|
|
|
|
// the NullMessage so as to obscure it's content. The sync message (like all sync messages) will be *additionally*
|
|
|
|
// padded by the superclass while being sent. The end result is we send a NullMessage of a non-distinct size, and a
|
|
|
|
// verification sync which is ~1-512 bytes larger then that.
|
2017-06-22 20:32:06 +02:00
|
|
|
contentLength += self.verificationStateSyncMessage.paddingBytesLength;
|
|
|
|
|
2018-04-12 00:06:29 +02:00
|
|
|
OWSAssert(contentLength > 0);
|
|
|
|
|
2017-06-22 18:12:24 +02:00
|
|
|
nullMessageBuilder.padding = [Cryptography generateRandomBytes:contentLength];
|
|
|
|
|
|
|
|
contentBuilder.nullMessage = [nullMessageBuilder build];
|
2017-08-01 23:01:07 +02:00
|
|
|
|
2017-06-22 18:12:24 +02:00
|
|
|
return [contentBuilder build].data;
|
|
|
|
}
|
|
|
|
|
2017-06-22 19:05:28 +02:00
|
|
|
- (BOOL)shouldSyncTranscript
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:53:16 +01:00
|
|
|
- (BOOL)shouldBeSaved
|
2017-06-22 18:12:24 +02:00
|
|
|
{
|
2017-11-15 23:53:16 +01:00
|
|
|
return NO;
|
2017-06-22 18:12:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|