2017-06-09 04:23:18 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
2016-08-23 22:38:05 +02:00
|
|
|
|
|
|
|
#import "OWSOutgoingSyncMessage.h"
|
2016-08-26 01:01:35 +02:00
|
|
|
#import "OWSSignalServiceProtos.pb.h"
|
2017-06-22 19:05:28 +02:00
|
|
|
#import "Cryptography.h"
|
2016-08-23 22:38:05 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation OWSOutgoingSyncMessage
|
|
|
|
|
2016-09-01 21:42:51 +02:00
|
|
|
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
{
|
|
|
|
// override superclass with no-op.
|
|
|
|
//
|
|
|
|
// There's no need to save this message, since it's not displayed to the user.
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:38:05 +02:00
|
|
|
- (BOOL)shouldSyncTranscript
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2017-06-22 19:05:28 +02:00
|
|
|
// This method should not be overridden, since we want to add random padding to *every* sync message
|
2016-08-26 01:01:35 +02:00
|
|
|
- (OWSSignalServiceProtosSyncMessage *)buildSyncMessage
|
|
|
|
{
|
2017-06-22 19:05:28 +02:00
|
|
|
OWSSignalServiceProtosSyncMessageBuilder *builder = [self syncMessageBuilder];
|
|
|
|
|
|
|
|
// Add a random 1-512 bytes to obscure sync message type
|
|
|
|
size_t paddingBytesLength = arc4random_uniform(512) + 1;
|
|
|
|
builder.padding = [Cryptography generateRandomBytes:paddingBytesLength];
|
|
|
|
|
|
|
|
return [builder build];
|
|
|
|
}
|
2016-08-26 01:01:35 +02:00
|
|
|
|
2017-06-22 19:05:28 +02:00
|
|
|
- (OWSSignalServiceProtosSyncMessageBuilder *)syncMessageBuilder
|
|
|
|
{
|
|
|
|
OWSFail(@"Abstract method should be overridden in subclass.");
|
|
|
|
return [OWSSignalServiceProtosSyncMessageBuilder new];
|
2016-08-26 01:01:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSData *)buildPlainTextData
|
|
|
|
{
|
|
|
|
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
2017-06-22 19:56:38 +02:00
|
|
|
[contentBuilder setSyncMessage:[self buildSyncMessage]];
|
2016-08-26 01:01:35 +02:00
|
|
|
|
|
|
|
return [[contentBuilder build] data];
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:38:05 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|