Merge branch 'charlesmchen/protoWrappers'

This commit is contained in:
Matthew Chen 2018-08-02 14:25:53 -04:00
commit 808443f2a9
23 changed files with 4845 additions and 270 deletions

2
Pods

@ -1 +1 @@
Subproject commit 653107b632ab7b3e8449bfaad591ac950eae41ff Subproject commit b8c8d320dba1c279b5c0ea03313232239e4e0ba5

1060
Scripts/ProtoWrappers.py Executable file

File diff suppressed because it is too large Load diff

View file

@ -38,7 +38,7 @@ public class MessageFetcherJob: NSObject {
Logger.info("\(self.logTag) fetching messages via REST.") Logger.info("\(self.logTag) fetching messages via REST.")
let promise = self.fetchUndeliveredMessages().then { (envelopes: [SSKEnvelope], more: Bool) -> Promise<Void> in let promise = self.fetchUndeliveredMessages().then { (envelopes: [SSKProtoEnvelope], more: Bool) -> Promise<Void> in
for envelope in envelopes { for envelope in envelopes {
Logger.info("\(self.logTag) received envelope.") Logger.info("\(self.logTag) received envelope.")
do { do {
@ -85,7 +85,7 @@ public class MessageFetcherJob: NSObject {
timer = nil timer = nil
} }
private func parseMessagesResponse(responseObject: Any?) -> (envelopes: [SSKEnvelope], more: Bool)? { private func parseMessagesResponse(responseObject: Any?) -> (envelopes: [SSKProtoEnvelope], more: Bool)? {
guard let responseObject = responseObject else { guard let responseObject = responseObject else {
Logger.error("\(self.logTag) response object was surpringly nil") Logger.error("\(self.logTag) response object was surpringly nil")
return nil return nil
@ -110,7 +110,7 @@ public class MessageFetcherJob: NSObject {
} }
}() }()
let envelopes: [SSKEnvelope] = messageDicts.compactMap { buildEnvelope(messageDict: $0) } let envelopes: [SSKProtoEnvelope] = messageDicts.compactMap { buildEnvelope(messageDict: $0) }
return ( return (
envelopes: envelopes, envelopes: envelopes,
@ -118,30 +118,43 @@ public class MessageFetcherJob: NSObject {
) )
} }
private func buildEnvelope(messageDict: [String: Any]) -> SSKEnvelope? { private func buildEnvelope(messageDict: [String: Any]) -> SSKProtoEnvelope? {
do { do {
let params = ParamParser(dictionary: messageDict) let params = ParamParser(dictionary: messageDict)
let builder = SSKProtoEnvelope.SSKProtoEnvelopeBuilder()
let typeInt: Int32 = try params.required(key: "type") let typeInt: Int32 = try params.required(key: "type")
guard let type: SSKEnvelope.SSKEnvelopeType = SSKEnvelope.SSKEnvelopeType(rawValue: typeInt) else { guard let type: SSKProtoEnvelope.SSKProtoEnvelopeType = SSKProtoEnvelope.SSKProtoEnvelopeType(rawValue: typeInt) else {
Logger.error("\(self.logTag) `typeInt` was invalid: \(typeInt)") Logger.error("\(self.logTag) `typeInt` was invalid: \(typeInt)")
throw ParamParser.ParseError.invalidFormat("type") throw ParamParser.ParseError.invalidFormat("type")
} }
builder.setType(type)
let timestamp: UInt64 = try params.required(key: "timestamp") if let timestamp: UInt64 = try params.required(key: "timestamp") {
let source: String = try params.required(key: "source") builder.setTimestamp(timestamp)
let sourceDevice: UInt32 = try params.required(key: "sourceDevice") }
let legacyMessage: Data? = try params.optionalBase64EncodedData(key: "message") if let source: String = try params.required(key: "source") {
let content: Data? = try params.optionalBase64EncodedData(key: "content") builder.setSource(source)
}
if let sourceDevice: UInt32 = try params.required(key: "sourceDevice") {
builder.setSourceDevice(sourceDevice)
}
if let legacyMessage = try params.optionalBase64EncodedData(key: "message") {
builder.setLegacyMessage(legacyMessage)
}
if let content = try params.optionalBase64EncodedData(key: "content") {
builder.setContent(content)
}
return SSKEnvelope(timestamp: UInt64(timestamp), source: source, sourceDevice: sourceDevice, type: type, content: content, legacyMessage: legacyMessage) return try builder.build()
} catch { } catch {
owsFail("\(self.logTag) in \(#function) error building envelope: \(error)") owsFail("\(self.logTag) in \(#function) error building envelope: \(error)")
return nil return nil
} }
} }
private func fetchUndeliveredMessages() -> Promise<(envelopes: [SSKEnvelope], more: Bool)> { private func fetchUndeliveredMessages() -> Promise<(envelopes: [SSKProtoEnvelope], more: Bool)> {
return Promise { fulfill, reject in return Promise { fulfill, reject in
let request = OWSRequestFactory.getMessagesRequest() let request = OWSRequestFactory.getMessagesRequest()
self.networkManager.makeRequest( self.networkManager.makeRequest(
@ -165,8 +178,9 @@ public class MessageFetcherJob: NSObject {
} }
} }
private func acknowledgeDelivery(envelope: SSKEnvelope) { private func acknowledgeDelivery(envelope: SSKProtoEnvelope) {
let request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: envelope.source, timestamp: envelope.timestamp) let source = envelope.source
let request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: source, timestamp: envelope.timestamp)
self.networkManager.makeRequest(request, self.networkManager.makeRequest(request,
success: { (_: URLSessionDataTask?, _: Any?) -> Void in success: { (_: URLSessionDataTask?, _: Any?) -> Void in
Logger.debug("\(self.logTag) acknowledged delivery for message at timestamp: \(envelope.timestamp)") Logger.debug("\(self.logTag) acknowledged delivery for message at timestamp: \(envelope.timestamp)")

View file

@ -3372,7 +3372,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
completion:nil]; completion:nil];
} }
+ (SSKEnvelope *)createEnvelopeForThread:(TSThread *)thread + (SSKProtoEnvelope *)createEnvelopeForThread:(TSThread *)thread
{ {
OWSAssert(thread); OWSAssert(thread);
@ -3390,13 +3390,17 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
} }
}(); }();
SSKEnvelope *envelope = [[SSKEnvelope alloc] initWithTimestamp:timestamp SSKProtoEnvelopeBuilder *envelopeBuilder = [SSKProtoEnvelopeBuilder new];
source:source envelopeBuilder.type = SSKProtoEnvelopeTypeCiphertext;
sourceDevice:1 envelopeBuilder.source = source;
type:SSKEnvelopeTypeCiphertext envelopeBuilder.sourceDevice = 1;
content:nil envelopeBuilder.timestamp = timestamp;
legacyMessage:nil]; NSError *error;
SSKProtoEnvelope *_Nullable envelope = [envelopeBuilder buildAndReturnError:&error];
if (error || !envelope) {
OWSFail(@"%@ Could not construct envelope: %@.", self.logTag, error);
return nil;
}
return envelope; return envelope;
} }
@ -3886,19 +3890,27 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
uint64_t timestamp = [NSDate ows_millisecondTimeStamp]; uint64_t timestamp = [NSDate ows_millisecondTimeStamp];
NSString *source = recipientId; NSString *source = recipientId;
uint32_t sourceDevice = 1; uint32_t sourceDevice = 1;
SSKEnvelopeType envelopeType = SSKEnvelopeTypeCiphertext; SSKProtoEnvelopeType envelopeType = SSKProtoEnvelopeTypeCiphertext;
NSData *content = plaintextData; NSData *content = plaintextData;
SSKEnvelope *envelope = [[SSKEnvelope alloc] initWithTimestamp:timestamp SSKProtoEnvelopeBuilder *envelopeBuilder = [SSKProtoEnvelopeBuilder new];
source:source envelopeBuilder.type = envelopeType;
sourceDevice:sourceDevice envelopeBuilder.source = source;
type:envelopeType envelopeBuilder.sourceDevice = sourceDevice;
content:content envelopeBuilder.timestamp = timestamp;
legacyMessage:nil]; envelopeBuilder.content = content;
NSError *error; NSError *error;
SSKProtoEnvelope *_Nullable envelope = [envelopeBuilder buildAndReturnError:&error];
if (error || !envelope) {
OWSFail(@"%@ Could not construct envelope: %@.", self.logTag, error);
return;
}
NSData *_Nullable envelopeData = [envelope serializedDataAndReturnError:&error]; NSData *_Nullable envelopeData = [envelope serializedDataAndReturnError:&error];
OWSAssert(!error && envelopeData); if (error || !envelopeData) {
OWSFail(@"%@ Could not serialize envelope: %@.", self.logTag, error);
return;
}
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[OWSBatchMessageProcessor sharedInstance] enqueueEnvelopeData:envelopeData [[OWSBatchMessageProcessor sharedInstance] enqueueEnvelopeData:envelopeData

View file

@ -7,7 +7,7 @@ import XCTest
import SignalServiceKit import SignalServiceKit
import SwiftProtobuf import SwiftProtobuf
class SSKEnvelopeTest: XCTestCase { class SSKProtoEnvelopeTest: XCTestCase {
override func setUp() { override func setUp() {
super.setUp() super.setUp()
@ -21,12 +21,12 @@ class SSKEnvelopeTest: XCTestCase {
func testParse_EmptyData() { func testParse_EmptyData() {
let data = Data() let data = Data()
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) XCTAssertThrowsError(try SSKProtoEnvelope(serializedData: data))
} }
func testParse_UnparseableData() { func testParse_UnparseableData() {
let data = "asdf".data(using: .utf8)! let data = "asdf".data(using: .utf8)!
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { error in XCTAssertThrowsError(try SSKProtoEnvelope(serializedData: data)) { error in
XCTAssert(error is SwiftProtobuf.BinaryDecodingError) XCTAssert(error is SwiftProtobuf.BinaryDecodingError)
} }
} }
@ -42,7 +42,7 @@ class SSKEnvelopeTest: XCTestCase {
let encodedData = "CAESDCsxNTU1MTIzMTIzNCjKm4WazSw4AQ==" let encodedData = "CAESDCsxNTU1MTIzMTIzNCjKm4WazSw4AQ=="
let data = Data(base64Encoded: encodedData)! let data = Data(base64Encoded: encodedData)!
XCTAssertNoThrow(try SSKEnvelope(serializedData: data)) XCTAssertNoThrow(try SSKProtoEnvelope(serializedData: data))
} }
func testParse_invalidData() { func testParse_invalidData() {
@ -56,9 +56,9 @@ class SSKEnvelopeTest: XCTestCase {
let encodedData = "EgwrMTU1NTEyMzEyMzQojdmOms0sOAE=" let encodedData = "EgwrMTU1NTEyMzEyMzQojdmOms0sOAE="
let data = Data(base64Encoded: encodedData)! let data = Data(base64Encoded: encodedData)!
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { (error) -> Void in XCTAssertThrowsError(try SSKProtoEnvelope(serializedData: data)) { (error) -> Void in
switch error { switch error {
case SSKEnvelope.EnvelopeError.invalidProtobuf: case SSKProtoEnvelope.EnvelopeError.invalidProtobuf:
break break
default: default:
XCTFail("unexpected error: \(error)") XCTFail("unexpected error: \(error)")

View file

@ -2,12 +2,16 @@
PROTOC=protoc \ PROTOC=protoc \
--proto_path='./' --proto_path='./'
WRAPPER_SCRIPT=../../Scripts/ProtoWrappers.py \
--proto-dir='./' --verbose
all: signal_service_protos provisioning_protos fingerprint_protos websocket_protos signal_ios_protos all: signal_service_protos provisioning_protos fingerprint_protos websocket_protos signal_ios_protos
signal_service_protos: SignalService.proto signal_service_protos: SignalService.proto
$(PROTOC) --swift_out=../src/Protos/Generated \ $(PROTOC) --swift_out=../src/Protos/Generated \
SignalService.proto SignalService.proto
$(WRAPPER_SCRIPT) --dst-dir=../src/Protos/Generated \
--wrapper-prefix=SSKProto --proto-prefix=SignalServiceProtos --proto-file=SignalService.proto
provisioning_protos: Provisioning.proto provisioning_protos: Provisioning.proto
$(PROTOC) --swift_out=../src/Protos/Generated \ $(PROTOC) --swift_out=../src/Protos/Generated \

View file

@ -23,10 +23,14 @@ message Envelope {
RECEIPT = 5; RECEIPT = 5;
} }
// @required
optional Type type = 1; optional Type type = 1;
// @required
optional string source = 2; optional string source = 2;
// @required
optional uint32 sourceDevice = 7; optional uint32 sourceDevice = 7;
optional string relay = 3; optional string relay = 3;
// @required
optional uint64 timestamp = 5; optional uint64 timestamp = 5;
optional bytes legacyMessage = 6; // Contains an encrypted DataMessage optional bytes legacyMessage = 6; // Contains an encrypted DataMessage
optional bytes content = 8; // Contains an encrypted Content optional bytes content = 8; // Contains an encrypted Content
@ -42,6 +46,7 @@ message Content {
message CallMessage { message CallMessage {
message Offer { message Offer {
// @required
optional uint64 id = 1; optional uint64 id = 1;
// Signal-iOS renamed the description field to avoid // Signal-iOS renamed the description field to avoid
// conflicts with [NSObject description]. // conflicts with [NSObject description].
@ -49,6 +54,7 @@ message CallMessage {
} }
message Answer { message Answer {
// @required
optional uint64 id = 1; optional uint64 id = 1;
// Signal-iOS renamed the description field to avoid // Signal-iOS renamed the description field to avoid
// conflicts with [NSObject description]. // conflicts with [NSObject description].
@ -56,6 +62,7 @@ message CallMessage {
} }
message IceUpdate { message IceUpdate {
// @required
optional uint64 id = 1; optional uint64 id = 1;
optional string sdpMid = 2; optional string sdpMid = 2;
optional uint32 sdpMLineIndex = 3; optional uint32 sdpMLineIndex = 3;
@ -63,10 +70,12 @@ message CallMessage {
} }
message Busy { message Busy {
// @required
optional uint64 id = 1; optional uint64 id = 1;
} }
message Hangup { message Hangup {
// @required
optional uint64 id = 1; optional uint64 id = 1;
} }
@ -100,7 +109,9 @@ message DataMessage {
optional uint32 flags = 4; optional uint32 flags = 4;
} }
// @required
optional uint64 id = 1; optional uint64 id = 1;
// @required
optional string author = 2; optional string author = 2;
optional string text = 3; optional string text = 3;
repeated QuotedAttachment attachments = 4; repeated QuotedAttachment attachments = 4;
@ -124,6 +135,7 @@ message DataMessage {
CUSTOM = 4; CUSTOM = 4;
} }
// @required
optional string value = 1; optional string value = 1;
optional Type type = 2; optional Type type = 2;
optional string label = 3; optional string label = 3;
@ -137,6 +149,7 @@ message DataMessage {
CUSTOM = 4; CUSTOM = 4;
} }
// @required
optional string value = 1; optional string value = 1;
optional Type type = 2; optional Type type = 2;
optional string label = 3; optional string label = 3;
@ -194,6 +207,7 @@ message ReceiptMessage {
READ = 1; READ = 1;
} }
// @required
optional Type type = 1; optional Type type = 1;
repeated uint64 timestamp = 2; repeated uint64 timestamp = 2;
} }
@ -205,6 +219,7 @@ message Verified {
UNVERIFIED = 2; UNVERIFIED = 2;
} }
// @required
optional string destination = 1; optional string destination = 1;
optional bytes identityKey = 2; optional bytes identityKey = 2;
optional State state = 3; optional State state = 3;
@ -220,6 +235,7 @@ message SyncMessage {
} }
message Contacts { message Contacts {
// @required
optional AttachmentPointer blob = 1; optional AttachmentPointer blob = 1;
// Signal-iOS renamed this property. // Signal-iOS renamed this property.
optional bool isComplete = 2 [default = false]; optional bool isComplete = 2 [default = false];
@ -242,11 +258,14 @@ message SyncMessage {
CONFIGURATION = 4; CONFIGURATION = 4;
} }
// @required
optional Type type = 1; optional Type type = 1;
} }
message Read { message Read {
// @required
optional string sender = 1; optional string sender = 1;
// @required
optional uint64 timestamp = 2; optional uint64 timestamp = 2;
} }
@ -270,6 +289,7 @@ message AttachmentPointer {
VOICE_MESSAGE = 1; VOICE_MESSAGE = 1;
} }
// @required
optional fixed64 id = 1; optional fixed64 id = 1;
optional string contentType = 2; optional string contentType = 2;
optional bytes key = 3; optional bytes key = 3;
@ -290,7 +310,9 @@ message GroupContext {
QUIT = 3; QUIT = 3;
REQUEST_INFO = 4; REQUEST_INFO = 4;
} }
// @required
optional bytes id = 1; optional bytes id = 1;
// @required
optional Type type = 2; optional Type type = 2;
optional string name = 3; optional string name = 3;
repeated string members = 4; repeated string members = 4;
@ -303,6 +325,7 @@ message ContactDetails {
optional uint32 length = 2; optional uint32 length = 2;
} }
// @required
optional string number = 1; optional string number = 1;
optional string name = 2; optional string name = 2;
optional Avatar avatar = 3; optional Avatar avatar = 3;
@ -319,6 +342,7 @@ message GroupDetails {
optional uint32 length = 2; optional uint32 length = 2;
} }
// @required
optional bytes id = 1; optional bytes id = 1;
optional string name = 2; optional string name = 2;
repeated string members = 3; repeated string members = 3;

View file

@ -7,7 +7,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
typedef NS_ENUM(int32_t, TSErrorMessageType) { typedef NS_ENUM(int32_t, TSErrorMessageType) {
TSErrorMessageNoSession, TSErrorMessageNoSession,
@ -55,18 +55,18 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
inThread:(nullable TSThread *)thread inThread:(nullable TSThread *)thread
failedMessageType:(TSErrorMessageType)errorMessageType; failedMessageType:(TSErrorMessageType)errorMessageType;
+ (instancetype)corruptedMessageWithEnvelope:(SSKEnvelope *)envelope + (instancetype)corruptedMessageWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)corruptedMessageInUnknownThread; + (instancetype)corruptedMessageInUnknownThread;
+ (instancetype)invalidVersionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidVersionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)invalidKeyExceptionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidKeyExceptionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)missingSessionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)missingSessionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId; + (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId;

View file

@ -84,7 +84,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
return [self initWithTimestamp:timestamp inThread:thread failedMessageType:errorMessageType recipientId:nil]; return [self initWithTimestamp:timestamp inThread:thread failedMessageType:errorMessageType recipientId:nil];
} }
- (instancetype)initWithEnvelope:(SSKEnvelope *)envelope - (instancetype)initWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
failedMessageType:(TSErrorMessageType)errorMessageType failedMessageType:(TSErrorMessageType)errorMessageType
{ {
@ -146,7 +146,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
} }
} }
+ (instancetype)corruptedMessageWithEnvelope:(SSKEnvelope *)envelope + (instancetype)corruptedMessageWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return [[self alloc] initWithEnvelope:envelope return [[self alloc] initWithEnvelope:envelope
@ -159,7 +159,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
return [[self alloc] initWithFailedMessageType:TSErrorMessageInvalidMessage]; return [[self alloc] initWithFailedMessageType:TSErrorMessageInvalidMessage];
} }
+ (instancetype)invalidVersionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidVersionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return [[self alloc] initWithEnvelope:envelope return [[self alloc] initWithEnvelope:envelope
@ -167,7 +167,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
failedMessageType:TSErrorMessageInvalidVersion]; failedMessageType:TSErrorMessageInvalidVersion];
} }
+ (instancetype)invalidKeyExceptionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidKeyExceptionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return [[self alloc] initWithEnvelope:envelope return [[self alloc] initWithEnvelope:envelope
@ -175,7 +175,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
failedMessageType:TSErrorMessageInvalidKeyException]; failedMessageType:TSErrorMessageInvalidKeyException];
} }
+ (instancetype)missingSessionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)missingSessionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return return

View file

@ -6,13 +6,13 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
// DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may // 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. // exist, so we should keep this class around to honor their old behavior.
@interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage @interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope + (nullable instancetype)untrustedKeyWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
@end @end

View file

@ -28,13 +28,13 @@ NS_ASSUME_NONNULL_BEGIN
@implementation TSInvalidIdentityKeyReceivingErrorMessage { @implementation TSInvalidIdentityKeyReceivingErrorMessage {
// Not using a property declaration in order to exclude from DB serialization // Not using a property declaration in order to exclude from DB serialization
SSKEnvelope *_Nullable _envelope; SSKProtoEnvelope *_Nullable _envelope;
} }
@synthesize envelopeData = _envelopeData; @synthesize envelopeData = _envelopeData;
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope + (nullable instancetype)untrustedKeyWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
TSContactThread *contactThread = TSContactThread *contactThread =
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction]; [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
@ -46,8 +46,8 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (nullable instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp - (nullable instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread inThread:(TSThread *)thread
incomingEnvelope:(SSKEnvelope *)envelope incomingEnvelope:(SSKProtoEnvelope *)envelope
{ {
self = [self initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageWrongTrustedIdentityKey]; self = [self initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageWrongTrustedIdentityKey];
if (!self) { if (!self) {
@ -66,11 +66,11 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
- (nullable SSKEnvelope *)envelope - (nullable SSKProtoEnvelope *)envelope
{ {
if (!_envelope) { if (!_envelope) {
NSError *error; NSError *error;
SSKEnvelope *_Nullable envelope = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error]; SSKProtoEnvelope *_Nullable envelope = [SSKProtoEnvelope parseData:self.envelopeData error:&error];
if (error || envelope == nil) { if (error || envelope == nil) {
OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, error); OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, error);
} else { } else {
@ -118,7 +118,7 @@ NS_ASSUME_NONNULL_BEGIN
return nil; return nil;
} }
if (self.envelope.type != SSKEnvelopeTypePrekeyBundle) { if (self.envelope.type != SSKProtoEnvelopeTypePrekeyBundle) {
DDLogError(@"Refusing to attempt key extraction from an envelope which isn't a prekey bundle"); DDLogError(@"Refusing to attempt key extraction from an envelope which isn't a prekey bundle");
return nil; return nil;
} }

View file

@ -5,7 +5,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class OWSStorage; @class OWSStorage;
@class SSKEnvelope; @class SSKProtoEnvelope;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
// This class is used to write incoming (decrypted, unprocessed) // This class is used to write incoming (decrypted, unprocessed)

View file

@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithUniqueId:(NSString *_Nullable)uniqueId NS_UNAVAILABLE; - (instancetype)initWithUniqueId:(NSString *_Nullable)uniqueId NS_UNAVAILABLE;
@property (nonatomic, readonly, nullable) SSKEnvelope *envelope; @property (nonatomic, readonly, nullable) SSKProtoEnvelope *envelope;
@end @end
@ -74,13 +74,13 @@ NS_ASSUME_NONNULL_BEGIN
return [super initWithCoder:coder]; return [super initWithCoder:coder];
} }
- (nullable SSKEnvelope *)envelope - (nullable SSKProtoEnvelope *)envelope
{ {
NSError *error; NSError *error;
SSKEnvelope *_Nullable result = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error]; SSKProtoEnvelope *_Nullable result = [SSKProtoEnvelope parseData:self.envelopeData error:&error];
if (error) { if (error) {
OWSProdLogAndFail(@"%@ paring SSKEnvelope failed with error: %@", self.logTag, error); OWSProdLogAndFail(@"%@ paring SSKProtoEnvelope failed with error: %@", self.logTag, error);
return nil; return nil;
} }
@ -396,7 +396,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
}; };
@try { @try {
SSKEnvelope *_Nullable envelope = job.envelope; SSKProtoEnvelope *_Nullable envelope = job.envelope;
if (!envelope) { if (!envelope) {
reportFailure(transaction); reportFailure(transaction);
} else { } else {

View file

@ -6,7 +6,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
typedef void (^DecryptSuccessBlock)(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction); typedef void (^DecryptSuccessBlock)(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction);
@ -22,7 +22,7 @@ typedef void (^DecryptFailureBlock)(void);
// //
// Exactly one of successBlock & failureBlock will be called, // Exactly one of successBlock & failureBlock will be called,
// once. // once.
- (void)decryptEnvelope:(SSKEnvelope *)envelope - (void)decryptEnvelope:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
failureBlock:(DecryptFailureBlock)failureBlock; failureBlock:(DecryptFailureBlock)failureBlock;

View file

@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Blocking #pragma mark - Blocking
- (BOOL)isEnvelopeBlocked:(SSKEnvelope *)envelope - (BOOL)isEnvelopeBlocked:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -90,7 +90,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Decryption #pragma mark - Decryption
- (void)decryptEnvelope:(SSKEnvelope *)envelope - (void)decryptEnvelope:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlockParameter successBlock:(DecryptSuccessBlock)successBlockParameter
failureBlock:(DecryptFailureBlock)failureBlockParameter failureBlock:(DecryptFailureBlock)failureBlockParameter
{ {
@ -129,7 +129,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
switch (envelope.type) { switch (envelope.type) {
case SSKEnvelopeTypeCiphertext: { case SSKProtoEnvelopeTypeCiphertext: {
[self decryptSecureMessage:envelope [self decryptSecureMessage:envelope
successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) { successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) {
DDLogDebug(@"%@ decrypted secure message.", self.logTag); DDLogDebug(@"%@ decrypted secure message.", self.logTag);
@ -146,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
// Return to avoid double-acknowledging. // Return to avoid double-acknowledging.
return; return;
} }
case SSKEnvelopeTypePrekeyBundle: { case SSKProtoEnvelopeTypePrekeyBundle: {
[self decryptPreKeyBundle:envelope [self decryptPreKeyBundle:envelope
successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) { successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) {
DDLogDebug(@"%@ decrypted pre-key whisper message", self.logTag); DDLogDebug(@"%@ decrypted pre-key whisper message", self.logTag);
@ -165,9 +165,9 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
// These message types don't have a payload to decrypt. // These message types don't have a payload to decrypt.
case SSKEnvelopeTypeReceipt: case SSKProtoEnvelopeTypeReceipt:
case SSKEnvelopeTypeKeyExchange: case SSKProtoEnvelopeTypeKeyExchange:
case SSKEnvelopeTypeUnknown: { case SSKProtoEnvelopeTypeUnknown: {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
successBlock(nil, transaction); successBlock(nil, transaction);
}]; }];
@ -193,7 +193,7 @@ NS_ASSUME_NONNULL_BEGIN
failureBlock(); failureBlock();
} }
- (void)decryptSecureMessage:(SSKEnvelope *)envelope - (void)decryptSecureMessage:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
failureBlock:(void (^)(NSError *_Nullable error))failureBlock failureBlock:(void (^)(NSError *_Nullable error))failureBlock
{ {
@ -210,7 +210,7 @@ NS_ASSUME_NONNULL_BEGIN
failureBlock:failureBlock]; failureBlock:failureBlock];
} }
- (void)decryptPreKeyBundle:(SSKEnvelope *)envelope - (void)decryptPreKeyBundle:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
failureBlock:(void (^)(NSError *_Nullable error))failureBlock failureBlock:(void (^)(NSError *_Nullable error))failureBlock
{ {
@ -230,7 +230,7 @@ NS_ASSUME_NONNULL_BEGIN
failureBlock:failureBlock]; failureBlock:failureBlock];
} }
- (void)decryptEnvelope:(SSKEnvelope *)envelope - (void)decryptEnvelope:(SSKProtoEnvelope *)envelope
cipherTypeName:(NSString *)cipherTypeName cipherTypeName:(NSString *)cipherTypeName
cipherMessageBlock:(id<CipherMessage> (^_Nonnull)(NSData *))cipherMessageBlock cipherMessageBlock:(id<CipherMessage> (^_Nonnull)(NSData *))cipherMessageBlock
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
@ -279,7 +279,7 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
- (void)processException:(NSException *)exception envelope:(SSKEnvelope *)envelope - (void)processException:(NSException *)exception envelope:(SSKProtoEnvelope *)envelope
{ {
DDLogError(@"%@ Got exception: %@ of type: %@ with reason: %@", DDLogError(@"%@ Got exception: %@ of type: %@ with reason: %@",
self.logTag, self.logTag,
@ -326,7 +326,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)notifyUserForErrorMessage:(TSErrorMessage *)errorMessage - (void)notifyUserForErrorMessage:(TSErrorMessage *)errorMessage
envelope:(SSKEnvelope *)envelope envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction]; TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];

View file

@ -6,14 +6,14 @@ NS_ASSUME_NONNULL_BEGIN
@class OWSSignalServiceProtosContent; @class OWSSignalServiceProtosContent;
@class OWSSignalServiceProtosDataMessage; @class OWSSignalServiceProtosDataMessage;
@class SSKEnvelope; @class SSKProtoEnvelope;
NSString *envelopeAddress(SSKEnvelope *envelope); NSString *envelopeAddress(SSKProtoEnvelope *envelope);
@interface OWSMessageHandler : NSObject @interface OWSMessageHandler : NSObject
- (NSString *)descriptionForEnvelopeType:(SSKEnvelope *)envelope; - (NSString *)descriptionForEnvelopeType:(SSKProtoEnvelope *)envelope;
- (NSString *)descriptionForEnvelope:(SSKEnvelope *)envelope; - (NSString *)descriptionForEnvelope:(SSKProtoEnvelope *)envelope;
- (NSString *)descriptionForContent:(OWSSignalServiceProtosContent *)content; - (NSString *)descriptionForContent:(OWSSignalServiceProtosContent *)content;
- (NSString *)descriptionForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage; - (NSString *)descriptionForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage;

View file

@ -9,31 +9,31 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
// used in log formatting // used in log formatting
NSString *envelopeAddress(SSKEnvelope *envelope) NSString *envelopeAddress(SSKProtoEnvelope *envelope)
{ {
return [NSString stringWithFormat:@"%@.%d", envelope.source, (unsigned int)envelope.sourceDevice]; return [NSString stringWithFormat:@"%@.%d", envelope.source, (unsigned int)envelope.sourceDevice];
} }
@implementation OWSMessageHandler @implementation OWSMessageHandler
- (NSString *)descriptionForEnvelopeType:(SSKEnvelope *)envelope - (NSString *)descriptionForEnvelopeType:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope != nil); OWSAssert(envelope != nil);
switch (envelope.type) { switch (envelope.type) {
case SSKEnvelopeTypeReceipt: case SSKProtoEnvelopeTypeReceipt:
return @"DeliveryReceipt"; return @"DeliveryReceipt";
case SSKEnvelopeTypeUnknown: case SSKProtoEnvelopeTypeUnknown:
// Shouldn't happen // Shouldn't happen
OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeUnknown]); OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeUnknown]);
return @"Unknown"; return @"Unknown";
case SSKEnvelopeTypeCiphertext: case SSKProtoEnvelopeTypeCiphertext:
return @"SignalEncryptedMessage"; return @"SignalEncryptedMessage";
case SSKEnvelopeTypeKeyExchange: case SSKProtoEnvelopeTypeKeyExchange:
// Unsupported // Unsupported
OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeKeyExchange]); OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeKeyExchange]);
return @"KeyExchange"; return @"KeyExchange";
case SSKEnvelopeTypePrekeyBundle: case SSKProtoEnvelopeTypePrekeyBundle:
return @"PreKeyEncryptedMessage"; return @"PreKeyEncryptedMessage";
default: default:
// Shouldn't happen // Shouldn't happen
@ -42,7 +42,7 @@ NSString *envelopeAddress(SSKEnvelope *envelope)
} }
} }
- (NSString *)descriptionForEnvelope:(SSKEnvelope *)envelope - (NSString *)descriptionForEnvelope:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope != nil); OWSAssert(envelope != nil);

View file

@ -6,7 +6,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
@class TSThread; @class TSThread;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)sharedManager; + (instancetype)sharedManager;
// processEnvelope: can be called from any thread. // processEnvelope: can be called from any thread.
- (void)processEnvelope:(SSKEnvelope *)envelope - (void)processEnvelope:(SSKProtoEnvelope *)envelope
plaintextData:(NSData *_Nullable)plaintextData plaintextData:(NSData *_Nullable)plaintextData
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;

View file

@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Blocking #pragma mark - Blocking
- (BOOL)isEnvelopeBlocked:(SSKEnvelope *)envelope - (BOOL)isEnvelopeBlocked:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -167,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - message handling #pragma mark - message handling
- (void)processEnvelope:(SSKEnvelope *)envelope - (void)processEnvelope:(SSKProtoEnvelope *)envelope
plaintextData:(NSData *_Nullable)plaintextData plaintextData:(NSData *_Nullable)plaintextData
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -189,8 +189,8 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(![self isEnvelopeBlocked:envelope]); OWSAssert(![self isEnvelopeBlocked:envelope]);
switch (envelope.type) { switch (envelope.type) {
case SSKEnvelopeTypeCiphertext: case SSKProtoEnvelopeTypeCiphertext:
case SSKEnvelopeTypePrekeyBundle: case SSKProtoEnvelopeTypePrekeyBundle:
if (plaintextData) { if (plaintextData) {
[self handleEnvelope:envelope plaintextData:plaintextData transaction:transaction]; [self handleEnvelope:envelope plaintextData:plaintextData transaction:transaction];
} else { } else {
@ -198,15 +198,15 @@ NS_ASSUME_NONNULL_BEGIN
@"%@ missing decrypted data for envelope: %@", self.logTag, [self descriptionForEnvelope:envelope]); @"%@ missing decrypted data for envelope: %@", self.logTag, [self descriptionForEnvelope:envelope]);
} }
break; break;
case SSKEnvelopeTypeReceipt: case SSKProtoEnvelopeTypeReceipt:
OWSAssert(!plaintextData); OWSAssert(!plaintextData);
[self handleDeliveryReceipt:envelope transaction:transaction]; [self handleDeliveryReceipt:envelope transaction:transaction];
break; break;
// Other messages are just dismissed for now. // Other messages are just dismissed for now.
case SSKEnvelopeTypeKeyExchange: case SSKProtoEnvelopeTypeKeyExchange:
DDLogWarn(@"Received Key Exchange Message, not supported"); DDLogWarn(@"Received Key Exchange Message, not supported");
break; break;
case SSKEnvelopeTypeUnknown: case SSKProtoEnvelopeTypeUnknown:
DDLogWarn(@"Received an unknown message type"); DDLogWarn(@"Received an unknown message type");
break; break;
default: default:
@ -215,8 +215,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleDeliveryReceipt:(SSKEnvelope *)envelope - (void)handleDeliveryReceipt:(SSKProtoEnvelope *)envelope transaction:(YapDatabaseReadWriteTransaction *)transaction
transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(envelope); OWSAssert(envelope);
OWSAssert(transaction); OWSAssert(transaction);
@ -272,7 +271,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleEnvelope:(SSKEnvelope *)envelope - (void)handleEnvelope:(SSKProtoEnvelope *)envelope
plaintextData:(NSData *)plaintextData plaintextData:(NSData *)plaintextData
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -326,7 +325,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -395,7 +394,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)sendGroupInfoRequest:(NSData *)groupId - (void)sendGroupInfoRequest:(NSData *)groupId
envelope:(SSKEnvelope *)envelope envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(groupId.length > 0); OWSAssert(groupId.length > 0);
@ -429,7 +428,7 @@ NS_ASSUME_NONNULL_BEGIN
return [TextSecureKitEnv sharedEnv].profileManager; return [TextSecureKitEnv sharedEnv].profileManager;
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withReceiptMessage:(OWSSignalServiceProtosReceiptMessage *)receiptMessage withReceiptMessage:(OWSSignalServiceProtosReceiptMessage *)receiptMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -464,7 +463,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withCallMessage:(OWSSignalServiceProtosCallMessage *)callMessage withCallMessage:(OWSSignalServiceProtosCallMessage *)callMessage
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -499,7 +498,7 @@ NS_ASSUME_NONNULL_BEGIN
}); });
} }
- (void)handleReceivedGroupAvatarUpdateWithEnvelope:(SSKEnvelope *)envelope - (void)handleReceivedGroupAvatarUpdateWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -537,7 +536,7 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
- (void)handleReceivedMediaWithEnvelope:(SSKEnvelope *)envelope - (void)handleReceivedMediaWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -585,7 +584,7 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -720,7 +719,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleEndSessionMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleEndSessionMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -737,7 +736,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.primaryStorage deleteAllSessionsForContact:envelope.source protocolContext:transaction]; [self.primaryStorage deleteAllSessionsForContact:envelope.source protocolContext:transaction];
} }
- (void)handleExpirationTimerUpdateMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleExpirationTimerUpdateMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -780,7 +779,7 @@ NS_ASSUME_NONNULL_BEGIN
[message saveWithTransaction:transaction]; [message saveWithTransaction:transaction];
} }
- (void)handleProfileKeyMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleProfileKeyMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -805,7 +804,7 @@ NS_ASSUME_NONNULL_BEGIN
[profileManager setProfileKeyData:profileKey forRecipientId:recipientId]; [profileManager setProfileKeyData:profileKey forRecipientId:recipientId];
} }
- (void)handleReceivedTextMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleReceivedTextMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -845,7 +844,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleGroupInfoRequest:(SSKEnvelope *)envelope - (void)handleGroupInfoRequest:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -901,7 +900,7 @@ NS_ASSUME_NONNULL_BEGIN
[self sendGroupUpdateForThread:gThread message:message]; [self sendGroupUpdateForThread:gThread message:message];
} }
- (TSIncomingMessage *_Nullable)handleReceivedEnvelope:(SSKEnvelope *)envelope - (TSIncomingMessage *_Nullable)handleReceivedEnvelope:(SSKProtoEnvelope *)envelope
withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
attachmentIds:(NSArray<NSString *> *)attachmentIds attachmentIds:(NSArray<NSString *> *)attachmentIds
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
@ -1083,7 +1082,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage - (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage
thread:(TSThread *)thread thread:(TSThread *)thread
envelope:(SSKEnvelope *)envelope envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(thread); OWSAssert(thread);
@ -1203,7 +1202,7 @@ NS_ASSUME_NONNULL_BEGIN
* Group or Contact thread for message, creating a new contact thread if necessary, * Group or Contact thread for message, creating a new contact thread if necessary,
* but never creating a new group thread. * but never creating a new group thread.
*/ */
- (nullable TSThread *)threadForEnvelope:(SSKEnvelope *)envelope - (nullable TSThread *)threadForEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {

View file

@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSDate *createdAt; @property (nonatomic, readonly) NSDate *createdAt;
@property (nonatomic, readonly) NSData *envelopeData; @property (nonatomic, readonly) NSData *envelopeData;
@property (nonatomic, readonly, nullable) SSKEnvelope *envelopeProto; @property (nonatomic, readonly, nullable) SSKProtoEnvelope *envelopeProto;
- (instancetype)initWithEnvelopeData:(NSData *)envelopeData NS_DESIGNATED_INITIALIZER; - (instancetype)initWithEnvelopeData:(NSData *)envelopeData NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
@ -68,10 +68,10 @@ NS_ASSUME_NONNULL_BEGIN
return [super initWithCoder:coder]; return [super initWithCoder:coder];
} }
- (nullable SSKEnvelope *)envelopeProto - (nullable SSKProtoEnvelope *)envelopeProto
{ {
NSError *error; NSError *error;
SSKEnvelope *_Nullable envelope = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error]; SSKProtoEnvelope *_Nullable envelope = [SSKProtoEnvelope parseData:self.envelopeData error:&error];
if (error || envelope == nil) { if (error || envelope == nil) {
OWSFail(@"%@ failed to parase envelope with error: %@", self.logTag, error); OWSFail(@"%@ failed to parase envelope with error: %@", self.logTag, error);
return nil; return nil;
@ -327,7 +327,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
AssertOnDispatchQueue(self.serialQueue); AssertOnDispatchQueue(self.serialQueue);
OWSAssert(job); OWSAssert(job);
SSKEnvelope *_Nullable envelope = nil; SSKProtoEnvelope *_Nullable envelope = nil;
@try { @try {
envelope = job.envelopeProto; envelope = job.envelopeProto;
} @catch (NSException *exception) { } @catch (NSException *exception) {

File diff suppressed because it is too large Load diff

View file

@ -32,6 +32,7 @@ struct SignalServiceProtos_Envelope {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var type: SignalServiceProtos_Envelope.TypeEnum { var type: SignalServiceProtos_Envelope.TypeEnum {
get {return _type ?? .unknown} get {return _type ?? .unknown}
set {_type = newValue} set {_type = newValue}
@ -41,6 +42,7 @@ struct SignalServiceProtos_Envelope {
/// Clears the value of `type`. Subsequent reads from it will return its default value. /// Clears the value of `type`. Subsequent reads from it will return its default value.
mutating func clearType() {self._type = nil} mutating func clearType() {self._type = nil}
/// @required
var source: String { var source: String {
get {return _source ?? String()} get {return _source ?? String()}
set {_source = newValue} set {_source = newValue}
@ -50,6 +52,7 @@ struct SignalServiceProtos_Envelope {
/// Clears the value of `source`. Subsequent reads from it will return its default value. /// Clears the value of `source`. Subsequent reads from it will return its default value.
mutating func clearSource() {self._source = nil} mutating func clearSource() {self._source = nil}
/// @required
var sourceDevice: UInt32 { var sourceDevice: UInt32 {
get {return _sourceDevice ?? 0} get {return _sourceDevice ?? 0}
set {_sourceDevice = newValue} set {_sourceDevice = newValue}
@ -68,6 +71,7 @@ struct SignalServiceProtos_Envelope {
/// Clears the value of `relay`. Subsequent reads from it will return its default value. /// Clears the value of `relay`. Subsequent reads from it will return its default value.
mutating func clearRelay() {self._relay = nil} mutating func clearRelay() {self._relay = nil}
/// @required
var timestamp: UInt64 { var timestamp: UInt64 {
get {return _timestamp ?? 0} get {return _timestamp ?? 0}
set {_timestamp = newValue} set {_timestamp = newValue}
@ -266,6 +270,7 @@ struct SignalServiceProtos_CallMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: UInt64 { var id: UInt64 {
get {return _id ?? 0} get {return _id ?? 0}
set {_id = newValue} set {_id = newValue}
@ -299,6 +304,7 @@ struct SignalServiceProtos_CallMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: UInt64 { var id: UInt64 {
get {return _id ?? 0} get {return _id ?? 0}
set {_id = newValue} set {_id = newValue}
@ -332,6 +338,7 @@ struct SignalServiceProtos_CallMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: UInt64 { var id: UInt64 {
get {return _id ?? 0} get {return _id ?? 0}
set {_id = newValue} set {_id = newValue}
@ -383,6 +390,7 @@ struct SignalServiceProtos_CallMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: UInt64 { var id: UInt64 {
get {return _id ?? 0} get {return _id ?? 0}
set {_id = newValue} set {_id = newValue}
@ -404,6 +412,7 @@ struct SignalServiceProtos_CallMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: UInt64 { var id: UInt64 {
get {return _id ?? 0} get {return _id ?? 0}
set {_id = newValue} set {_id = newValue}
@ -539,6 +548,7 @@ struct SignalServiceProtos_DataMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: UInt64 { var id: UInt64 {
get {return _id ?? 0} get {return _id ?? 0}
set {_id = newValue} set {_id = newValue}
@ -548,6 +558,7 @@ struct SignalServiceProtos_DataMessage {
/// Clears the value of `id`. Subsequent reads from it will return its default value. /// Clears the value of `id`. Subsequent reads from it will return its default value.
mutating func clearID() {self._id = nil} mutating func clearID() {self._id = nil}
/// @required
var author: String { var author: String {
get {return _author ?? String()} get {return _author ?? String()}
set {_author = newValue} set {_author = newValue}
@ -773,6 +784,7 @@ struct SignalServiceProtos_DataMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var value: String { var value: String {
get {return _value ?? String()} get {return _value ?? String()}
set {_value = newValue} set {_value = newValue}
@ -846,6 +858,7 @@ struct SignalServiceProtos_DataMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var value: String { var value: String {
get {return _value ?? String()} get {return _value ?? String()}
set {_value = newValue} set {_value = newValue}
@ -1110,6 +1123,7 @@ struct SignalServiceProtos_ReceiptMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var type: SignalServiceProtos_ReceiptMessage.TypeEnum { var type: SignalServiceProtos_ReceiptMessage.TypeEnum {
get {return _type ?? .delivery} get {return _type ?? .delivery}
set {_type = newValue} set {_type = newValue}
@ -1159,6 +1173,7 @@ struct SignalServiceProtos_Verified {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var destination: String { var destination: String {
get {return _destination ?? String()} get {return _destination ?? String()}
set {_destination = newValue} set {_destination = newValue}
@ -1371,6 +1386,7 @@ struct SignalServiceProtos_SyncMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var blob: SignalServiceProtos_AttachmentPointer { var blob: SignalServiceProtos_AttachmentPointer {
get {return _storage._blob ?? SignalServiceProtos_AttachmentPointer()} get {return _storage._blob ?? SignalServiceProtos_AttachmentPointer()}
set {_uniqueStorage()._blob = newValue} set {_uniqueStorage()._blob = newValue}
@ -1435,6 +1451,7 @@ struct SignalServiceProtos_SyncMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var type: SignalServiceProtos_SyncMessage.Request.TypeEnum { var type: SignalServiceProtos_SyncMessage.Request.TypeEnum {
get {return _type ?? .unknown} get {return _type ?? .unknown}
set {_type = newValue} set {_type = newValue}
@ -1491,6 +1508,7 @@ struct SignalServiceProtos_SyncMessage {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var sender: String { var sender: String {
get {return _sender ?? String()} get {return _sender ?? String()}
set {_sender = newValue} set {_sender = newValue}
@ -1500,6 +1518,7 @@ struct SignalServiceProtos_SyncMessage {
/// Clears the value of `sender`. Subsequent reads from it will return its default value. /// Clears the value of `sender`. Subsequent reads from it will return its default value.
mutating func clearSender() {self._sender = nil} mutating func clearSender() {self._sender = nil}
/// @required
var timestamp: UInt64 { var timestamp: UInt64 {
get {return _timestamp ?? 0} get {return _timestamp ?? 0}
set {_timestamp = newValue} set {_timestamp = newValue}
@ -1548,6 +1567,7 @@ struct SignalServiceProtos_AttachmentPointer {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: UInt64 { var id: UInt64 {
get {return _id ?? 0} get {return _id ?? 0}
set {_id = newValue} set {_id = newValue}
@ -1682,6 +1702,7 @@ struct SignalServiceProtos_GroupContext {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: Data { var id: Data {
get {return _storage._id ?? SwiftProtobuf.Internal.emptyData} get {return _storage._id ?? SwiftProtobuf.Internal.emptyData}
set {_uniqueStorage()._id = newValue} set {_uniqueStorage()._id = newValue}
@ -1691,6 +1712,7 @@ struct SignalServiceProtos_GroupContext {
/// Clears the value of `id`. Subsequent reads from it will return its default value. /// Clears the value of `id`. Subsequent reads from it will return its default value.
mutating func clearID() {_storage._id = nil} mutating func clearID() {_storage._id = nil}
/// @required
var type: SignalServiceProtos_GroupContext.TypeEnum { var type: SignalServiceProtos_GroupContext.TypeEnum {
get {return _storage._type ?? .unknown} get {return _storage._type ?? .unknown}
set {_uniqueStorage()._type = newValue} set {_uniqueStorage()._type = newValue}
@ -1770,6 +1792,7 @@ struct SignalServiceProtos_ContactDetails {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var number: String { var number: String {
get {return _storage._number ?? String()} get {return _storage._number ?? String()}
set {_uniqueStorage()._number = newValue} set {_uniqueStorage()._number = newValue}
@ -1885,6 +1908,7 @@ struct SignalServiceProtos_GroupDetails {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages. // methods supported on all messages.
/// @required
var id: Data { var id: Data {
get {return _storage._id ?? SwiftProtobuf.Internal.emptyData} get {return _storage._id ?? SwiftProtobuf.Internal.emptyData}
set {_uniqueStorage()._id = newValue} set {_uniqueStorage()._id = newValue}

View file

@ -1,149 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@objc
public class SSKEnvelope: NSObject {
public enum EnvelopeError: Error {
case invalidProtobuf(description: String)
}
@objc
public enum SSKEnvelopeType: Int32 {
case unknown = 0
case ciphertext = 1
case keyExchange = 2
case prekeyBundle = 3
case receipt = 5
}
@objc
public let timestamp: UInt64
@objc
public let source: String
@objc
public let sourceDevice: UInt32
@objc
public let type: SSKEnvelopeType
@objc
public let relay: String?
@objc
public let content: Data?
@objc
public let legacyMessage: Data?
@objc
public init(timestamp: UInt64, source: String, sourceDevice: UInt32, type: SSKEnvelopeType, content: Data?, legacyMessage: Data?) {
self.source = source
self.type = type
self.timestamp = timestamp
self.sourceDevice = sourceDevice
self.relay = nil
self.content = content
self.legacyMessage = legacyMessage
}
@objc
public init(serializedData: Data) throws {
let proto: SignalServiceProtos_Envelope = try SignalServiceProtos_Envelope(serializedData: serializedData)
guard proto.hasSource else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: source")
}
self.source = proto.source
guard proto.hasType else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: type")
}
self.type = {
switch proto.type {
case .unknown:
return .unknown
case .ciphertext:
return .ciphertext
case .keyExchange:
return .keyExchange
case .prekeyBundle:
return .prekeyBundle
case .receipt:
return .receipt
}
}()
guard proto.hasTimestamp else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: timestamp")
}
self.timestamp = proto.timestamp
guard proto.hasSourceDevice else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: sourceDevice")
}
self.sourceDevice = proto.sourceDevice
if proto.hasContent {
self.content = proto.content
} else {
self.content = nil
}
if proto.hasLegacyMessage {
self.legacyMessage = proto.legacyMessage
} else {
self.legacyMessage = nil
}
if proto.relay.count > 0 {
self.relay = proto.relay
} else {
relay = nil
}
}
@objc
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
}
private var asProtobuf: SignalServiceProtos_Envelope {
let proto = SignalServiceProtos_Envelope.with { (builder) in
builder.source = self.source
builder.type = {
switch self.type {
case .unknown:
return .unknown
case .ciphertext:
return .ciphertext
case .keyExchange:
return .keyExchange
case .prekeyBundle:
return .prekeyBundle
case .receipt:
return .receipt
}
}()
builder.timestamp = self.timestamp
builder.sourceDevice = self.sourceDevice
if let relay = self.relay {
builder.relay = relay
}
if let content = self.content {
builder.content = content
}
}
return proto
}
}