Merge branch 'mkirk/validated-protos'
This commit is contained in:
commit
0081a877ef
@ -60,6 +60,7 @@ PODS:
|
||||
- Reachability
|
||||
- SAMKeychain
|
||||
- SocketRocket
|
||||
- SwiftProtobuf
|
||||
- YapDatabase/SQLCipher
|
||||
- SocketRocket (0.5.1)
|
||||
- SQLCipher (3.4.2):
|
||||
@ -68,6 +69,7 @@ PODS:
|
||||
- SQLCipher/standard (3.4.2):
|
||||
- SQLCipher/common
|
||||
- SSZipArchive (2.1.2)
|
||||
- SwiftProtobuf (1.0.3)
|
||||
- YapDatabase/SQLCipher (3.0.2):
|
||||
- YapDatabase/SQLCipher/Core (= 3.0.2)
|
||||
- YapDatabase/SQLCipher/Extensions (= 3.0.2)
|
||||
@ -161,6 +163,7 @@ SPEC REPOS:
|
||||
- Reachability
|
||||
- SAMKeychain
|
||||
- SSZipArchive
|
||||
- SwiftProtobuf
|
||||
- YYImage
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
@ -223,10 +226,11 @@ SPEC CHECKSUMS:
|
||||
PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd
|
||||
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
|
||||
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
|
||||
SignalServiceKit: eaaf6404e61fc05c71f91246327e2d487e0e1833
|
||||
SignalServiceKit: a16410721705f896905c65ad718424fa20728e7d
|
||||
SocketRocket: dbb1554b8fc288ef8ef370d6285aeca7361be31e
|
||||
SQLCipher: f9fcf29b2e59ced7defc2a2bdd0ebe79b40d4990
|
||||
SSZipArchive: d4009d2ce5520a421f231fd97028cc0e2667eed8
|
||||
SwiftProtobuf: 5ccc0e4054e37c75800e5744acb2aa80bb72b39c
|
||||
YapDatabase: 299a32de9d350d37a9ac5b0532609d87d5d2a5de
|
||||
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
|
||||
|
||||
|
||||
2
Pods
2
Pods
@ -1 +1 @@
|
||||
Subproject commit 4ede6c138ce6b5fd7279c9dcbbcece4018b03d57
|
||||
Subproject commit 7c62088f5a59230b1d3435c12ab4273b97c594e9
|
||||
@ -431,6 +431,7 @@
|
||||
4C13C9F620E57BA30089A98B /* ColorPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C13C9F520E57BA30089A98B /* ColorPickerViewController.swift */; };
|
||||
4C20B2B720CA0034001BAC90 /* ThreadViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4542DF51208B82E9007B4E76 /* ThreadViewModel.swift */; };
|
||||
4C20B2B920CA10DE001BAC90 /* ConversationSearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */; };
|
||||
4C3EF802210918740007EBF7 /* SSKEnvelopeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C3EF801210918740007EBF7 /* SSKEnvelopeTest.swift */; };
|
||||
4C4AEC4520EC343B0020E72B /* DismissableTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */; };
|
||||
4C4BC6C32102D697004040C9 /* ContactDiscoveryOperationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */; };
|
||||
4C6F527C20FFE8400097DEEE /* SignalUBSan.supp in Resources */ = {isa = PBXBuildFile; fileRef = 4C6F527B20FFE8400097DEEE /* SignalUBSan.supp */; };
|
||||
@ -1110,6 +1111,7 @@
|
||||
4C11AA4F20FD59C700351FBD /* MessageStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageStatusView.swift; sourceTree = "<group>"; };
|
||||
4C13C9F520E57BA30089A98B /* ColorPickerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerViewController.swift; sourceTree = "<group>"; };
|
||||
4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationSearchViewController.swift; sourceTree = "<group>"; };
|
||||
4C3EF801210918740007EBF7 /* SSKEnvelopeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSKEnvelopeTest.swift; sourceTree = "<group>"; };
|
||||
4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissableTextField.swift; sourceTree = "<group>"; };
|
||||
4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ContactDiscoveryOperationTest.swift; path = contact/ContactDiscoveryOperationTest.swift; sourceTree = "<group>"; };
|
||||
4C6F527B20FFE8400097DEEE /* SignalUBSan.supp */ = {isa = PBXFileReference; lastKnownFileType = text; path = SignalUBSan.supp; sourceTree = "<group>"; };
|
||||
@ -2109,6 +2111,14 @@
|
||||
path = Speakerbox;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4C3EF8002109184A0007EBF7 /* SSKTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4C3EF801210918740007EBF7 /* SSKEnvelopeTest.swift */,
|
||||
);
|
||||
path = SSKTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
76EB03C118170B33006006FC /* src */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -2284,6 +2294,7 @@
|
||||
B660F66C1C29867F00687D6E /* test */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4C3EF8002109184A0007EBF7 /* SSKTests */,
|
||||
34C6B0A41FA0E46F00D35993 /* Assets */,
|
||||
B660F6731C29867F00687D6E /* call */,
|
||||
B660F6751C29867F00687D6E /* contact */,
|
||||
@ -2998,6 +3009,7 @@
|
||||
"${BUILT_PRODUCTS_DIR}/SSZipArchive/SSZipArchive.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/SignalServiceKit/SignalServiceKit.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/SocketRocket/SocketRocket.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/YYImage/YYImage.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/YapDatabase/YapDatabase.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/libPhoneNumber-iOS/libPhoneNumber_iOS.framework",
|
||||
@ -3021,6 +3033,7 @@
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SSZipArchive.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SignalServiceKit.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SocketRocket.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftProtobuf.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YYImage.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YapDatabase.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libPhoneNumber_iOS.framework",
|
||||
@ -3070,6 +3083,7 @@
|
||||
"${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/SignalServiceKit/SignalServiceKit.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/SocketRocket/SocketRocket.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/YYImage/YYImage.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/YapDatabase/YapDatabase.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/libPhoneNumber-iOS/libPhoneNumber_iOS.framework",
|
||||
@ -3091,6 +3105,7 @@
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SignalServiceKit.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SocketRocket.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftProtobuf.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YYImage.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YapDatabase.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libPhoneNumber_iOS.framework",
|
||||
@ -3450,6 +3465,7 @@
|
||||
B660F6DA1C29868000687D6E /* ExceptionsTest.m in Sources */,
|
||||
B660F6DB1C29868000687D6E /* FunctionalUtilTest.m in Sources */,
|
||||
45E7A6A81E71CA7E00D44FB5 /* DisplayableTextFilterTest.swift in Sources */,
|
||||
4C3EF802210918740007EBF7 /* SSKEnvelopeTest.swift in Sources */,
|
||||
452D1AF12081059C00A67F7F /* StringAdditionsTest.swift in Sources */,
|
||||
4C4BC6C32102D697004040C9 /* ContactDiscoveryOperationTest.swift in Sources */,
|
||||
B660F6BB1C29868000687D6E /* OWSContactsManagerTest.m in Sources */,
|
||||
|
||||
@ -38,10 +38,15 @@ public class MessageFetcherJob: NSObject {
|
||||
|
||||
Logger.info("\(self.logTag) fetching messages via REST.")
|
||||
|
||||
let promise = self.fetchUndeliveredMessages().then { (envelopes: [OWSSignalServiceProtosEnvelope], more: Bool) -> Promise<Void> in
|
||||
let promise = self.fetchUndeliveredMessages().then { (envelopes: [SSKEnvelope], more: Bool) -> Promise<Void> in
|
||||
for envelope in envelopes {
|
||||
Logger.info("\(self.logTag) received envelope.")
|
||||
self.messageReceiver.handleReceivedEnvelope(envelope)
|
||||
do {
|
||||
let envelopeData = try envelope.serializedData()
|
||||
self.messageReceiver.handleReceivedEnvelopeData(envelopeData)
|
||||
} catch {
|
||||
owsFail("\(self.logTag) in \(#function) failed to serialize envelope")
|
||||
}
|
||||
self.acknowledgeDelivery(envelope: envelope)
|
||||
}
|
||||
|
||||
@ -80,7 +85,7 @@ public class MessageFetcherJob: NSObject {
|
||||
timer = nil
|
||||
}
|
||||
|
||||
private func parseMessagesResponse(responseObject: Any?) -> (envelopes: [OWSSignalServiceProtosEnvelope], more: Bool)? {
|
||||
private func parseMessagesResponse(responseObject: Any?) -> (envelopes: [SSKEnvelope], more: Bool)? {
|
||||
guard let responseObject = responseObject else {
|
||||
Logger.error("\(self.logTag) response object was surpringly nil")
|
||||
return nil
|
||||
@ -113,56 +118,57 @@ public class MessageFetcherJob: NSObject {
|
||||
)
|
||||
}
|
||||
|
||||
private func buildEnvelope(messageDict: [String: Any]) -> OWSSignalServiceProtosEnvelope? {
|
||||
let builder = OWSSignalServiceProtosEnvelopeBuilder()
|
||||
private func buildEnvelope(messageDict: [String: Any]) -> SSKEnvelope? {
|
||||
|
||||
guard let typeInt = messageDict["type"] as? Int32 else {
|
||||
Logger.error("\(self.logTag) message body didn't have type")
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let type = OWSSignalServiceProtosEnvelopeType(rawValue: typeInt) else {
|
||||
guard let type: SSKEnvelope.SSKEnvelopeType = SSKEnvelope.SSKEnvelopeType(rawValue: typeInt) else {
|
||||
Logger.error("\(self.logTag) message body type was invalid")
|
||||
return nil
|
||||
}
|
||||
builder.setType(type)
|
||||
|
||||
guard let timestamp = messageDict["timestamp"] as? UInt64 else {
|
||||
Logger.error("\(self.logTag) message body didn't have timestamp")
|
||||
return nil
|
||||
}
|
||||
builder.setTimestamp(timestamp)
|
||||
|
||||
guard let source = messageDict["source"] as? String else {
|
||||
Logger.error("\(self.logTag) message body didn't have source")
|
||||
return nil
|
||||
}
|
||||
builder.setSource(source)
|
||||
|
||||
guard let sourceDevice = messageDict["sourceDevice"] as? UInt32 else {
|
||||
Logger.error("\(self.logTag) message body didn't have sourceDevice")
|
||||
return nil
|
||||
}
|
||||
builder.setSourceDevice(sourceDevice)
|
||||
|
||||
if let encodedLegacyMessage = messageDict["message"] as? String {
|
||||
Logger.debug("\(self.logTag) message body had legacyMessage")
|
||||
if let legacyMessage = Data(base64Encoded: encodedLegacyMessage) {
|
||||
builder.setLegacyMessage(legacyMessage)
|
||||
let legacyMessage: Data? = {
|
||||
if let encodedLegacyMessage = messageDict["message"] as? String {
|
||||
Logger.debug("\(self.logTag) message body had legacyMessage")
|
||||
if let legacyMessage = Data(base64Encoded: encodedLegacyMessage) {
|
||||
return legacyMessage
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
|
||||
if let encodedContent = messageDict["content"] as? String {
|
||||
Logger.debug("\(self.logTag) message body had content")
|
||||
if let content = Data(base64Encoded: encodedContent) {
|
||||
builder.setContent(content)
|
||||
let content: Data? = {
|
||||
if let encodedContent = messageDict["content"] as? String {
|
||||
Logger.debug("\(self.logTag) message body had content")
|
||||
if let content = Data(base64Encoded: encodedContent) {
|
||||
return content
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
|
||||
return builder.build()
|
||||
return SSKEnvelope(timestamp: timestamp, source: source, sourceDevice: sourceDevice, type: type, content: content, legacyMessage: legacyMessage)
|
||||
}
|
||||
|
||||
private func fetchUndeliveredMessages() -> Promise<(envelopes: [OWSSignalServiceProtosEnvelope], more: Bool)> {
|
||||
private func fetchUndeliveredMessages() -> Promise<(envelopes: [SSKEnvelope], more: Bool)> {
|
||||
return Promise { fulfill, reject in
|
||||
let request = OWSRequestFactory.getMessagesRequest()
|
||||
self.networkManager.makeRequest(
|
||||
@ -186,7 +192,7 @@ public class MessageFetcherJob: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
private func acknowledgeDelivery(envelope: OWSSignalServiceProtosEnvelope) {
|
||||
private func acknowledgeDelivery(envelope: SSKEnvelope) {
|
||||
let request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: envelope.source, timestamp: envelope.timestamp)
|
||||
self.networkManager.makeRequest(request,
|
||||
success: { (_: URLSessionDataTask?, _: Any?) -> Void in
|
||||
|
||||
@ -3372,23 +3372,32 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
+ (OWSSignalServiceProtosEnvelope *)createEnvelopeForThread:(TSThread *)thread
|
||||
+ (SSKEnvelope *)createEnvelopeForThread:(TSThread *)thread
|
||||
{
|
||||
OWSAssert(thread);
|
||||
|
||||
OWSSignalServiceProtosEnvelopeBuilder *builder = [OWSSignalServiceProtosEnvelopeBuilder new];
|
||||
uint64_t timestamp = [NSDate ows_millisecondTimeStamp];
|
||||
NSString *source = ^{
|
||||
if ([thread isKindOfClass:[TSGroupThread class]]) {
|
||||
TSGroupThread *gThread = (TSGroupThread *)thread;
|
||||
return gThread.groupModel.groupMemberIds[0];
|
||||
} else if ([thread isKindOfClass:[TSContactThread class]]) {
|
||||
TSContactThread *contactThread = (TSContactThread *)thread;
|
||||
return contactThread.contactIdentifier;
|
||||
} else {
|
||||
OWSFail(@"%@ failure: unknown thread type", self.logTag);
|
||||
return @"unknown-source-id";
|
||||
}
|
||||
}();
|
||||
|
||||
[builder setTimestamp:[NSDate ows_millisecondTimeStamp]];
|
||||
SSKEnvelope *envelope = [[SSKEnvelope alloc] initWithTimestamp:timestamp
|
||||
source:source
|
||||
sourceDevice:1
|
||||
type:SSKEnvelopeTypeCiphertext
|
||||
content:nil
|
||||
legacyMessage:nil];
|
||||
|
||||
if ([thread isKindOfClass:[TSGroupThread class]]) {
|
||||
TSGroupThread *gThread = (TSGroupThread *)thread;
|
||||
[builder setSource:gThread.groupModel.groupMemberIds[0]];
|
||||
} else if ([thread isKindOfClass:[TSContactThread class]]) {
|
||||
TSContactThread *contactThread = (TSContactThread *)thread;
|
||||
[builder setSource:contactThread.contactIdentifier];
|
||||
}
|
||||
|
||||
return [builder build];
|
||||
return envelope;
|
||||
}
|
||||
|
||||
+ (NSArray<TSInteraction *> *)unsavedSystemMessagesInThread:(TSThread *)thread
|
||||
@ -3542,12 +3551,15 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
||||
withTransaction:transaction]];
|
||||
[result addObject:[TSErrorMessage invalidVersionWithEnvelope:[self createEnvelopeForThread:thread]
|
||||
withTransaction:transaction]];
|
||||
[result addObject:[TSInvalidIdentityKeyReceivingErrorMessage
|
||||
untrustedKeyWithEnvelope:[self createEnvelopeForThread:thread]
|
||||
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
|
||||
@ -3871,15 +3883,22 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
||||
recipientId = @"+12345678901";
|
||||
}
|
||||
|
||||
OWSSignalServiceProtosEnvelopeBuilder *envelopeBuilder = [OWSSignalServiceProtosEnvelopeBuilder new];
|
||||
[envelopeBuilder setType:OWSSignalServiceProtosEnvelopeTypeCiphertext];
|
||||
[envelopeBuilder setSource:recipientId];
|
||||
[envelopeBuilder setSourceDevice:1];
|
||||
[envelopeBuilder setTimestamp:[NSDate ows_millisecondTimeStamp]];
|
||||
[envelopeBuilder setContent:plaintextData];
|
||||
uint64_t timestamp = [NSDate ows_millisecondTimeStamp];
|
||||
NSString *source = recipientId;
|
||||
uint32_t sourceDevice = 1;
|
||||
SSKEnvelopeType envelopeType = SSKEnvelopeTypeCiphertext;
|
||||
NSData *content = plaintextData;
|
||||
|
||||
NSData *envelopeData = [envelopeBuilder build].data;
|
||||
OWSAssert(envelopeData);
|
||||
SSKEnvelope *envelope = [[SSKEnvelope alloc] initWithTimestamp:timestamp
|
||||
source:source
|
||||
sourceDevice:sourceDevice
|
||||
type:envelopeType
|
||||
content:content
|
||||
legacyMessage:nil];
|
||||
|
||||
NSError *error;
|
||||
NSData *_Nullable envelopeData = [envelope serializedDataAndReturnError:&error];
|
||||
OWSAssert(!error && envelopeData);
|
||||
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[[OWSBatchMessageProcessor sharedInstance] enqueueEnvelopeData:envelopeData
|
||||
|
||||
68
Signal/test/SSKTests/SSKEnvelopeTest.swift
Normal file
68
Signal/test/SSKTests/SSKEnvelopeTest.swift
Normal file
@ -0,0 +1,68 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
import SignalServiceKit
|
||||
import SwiftProtobuf
|
||||
|
||||
class SSKEnvelopeTest: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testParse_EmptyData() {
|
||||
let data = Data()
|
||||
XCTAssertThrowsError(try SSKEnvelope(serializedData: data))
|
||||
}
|
||||
|
||||
func testParse_UnparseableData() {
|
||||
let data = "asdf".data(using: .utf8)!
|
||||
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { error in
|
||||
XCTAssert(error is SwiftProtobuf.BinaryDecodingError)
|
||||
}
|
||||
}
|
||||
|
||||
func testParse_ValidData() {
|
||||
// `encodedData` was derived thus:
|
||||
// let builder = OWSSignalServiceProtosEnvelopeBuilder()
|
||||
// builder.setTimestamp(NSDate.ows_millisecondTimeStamp())
|
||||
// builder.setSource("+15551231234")
|
||||
// builder.setSourceDevice(1)
|
||||
// builder.setType(OWSSignalServiceProtosEnvelopeType.ciphertext)
|
||||
// let encodedData = builder.build().data()!.base64EncodedString()
|
||||
let encodedData = "CAESDCsxNTU1MTIzMTIzNCjKm4WazSw4AQ=="
|
||||
let data = Data(base64Encoded: encodedData)!
|
||||
|
||||
XCTAssertNoThrow(try SSKEnvelope(serializedData: data))
|
||||
}
|
||||
|
||||
func testParse_invalidData() {
|
||||
// `encodedData` was derived thus:
|
||||
// let builder = OWSSignalServiceProtosEnvelopeBuilder()
|
||||
// builder.setTimestamp(NSDate.ows_millisecondTimeStamp())
|
||||
// builder.setSource("+15551231234")
|
||||
// builder.setSourceDevice(1)
|
||||
// // MISSING TYPE!
|
||||
// let encodedData = builder.build().data()!.base64EncodedString()
|
||||
let encodedData = "EgwrMTU1NTEyMzEyMzQojdmOms0sOAE="
|
||||
let data = Data(base64Encoded: encodedData)!
|
||||
|
||||
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { (error) -> Void in
|
||||
switch error {
|
||||
case SSKEnvelope.EnvelopeError.invalidProtobuf:
|
||||
break
|
||||
default:
|
||||
XCTFail("unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,11 +49,12 @@ An Objective-C library for communicating with the Signal messaging service.
|
||||
s.dependency 'GRKOpenSSLFramework'
|
||||
s.dependency 'SAMKeychain'
|
||||
s.dependency 'Reachability'
|
||||
s.dependency 'SwiftProtobuf'
|
||||
|
||||
# Avoid PromiseKit 5/6 for now.
|
||||
# From the maintainer:
|
||||
# > PromiseKit 5 has been released, but is not yet fully documented,
|
||||
# > so we advise sticking with version 4 for the time being.
|
||||
# Avoid PromiseKit 5/6 for now.
|
||||
# From the maintainer:
|
||||
# > PromiseKit 5 has been released, but is not yet fully documented,
|
||||
# > so we advise sticking with version 4 for the time being.
|
||||
s.dependency 'PromiseKit', "~> 4.0"
|
||||
|
||||
end
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package textsecure;
|
||||
// iOS - since we use a modern proto-compiler, we must specify
|
||||
// the legacy proto format.
|
||||
syntax = "proto2";
|
||||
|
||||
// iOS - package name determines class prefix
|
||||
package FingerprintProtos;
|
||||
|
||||
option java_package = "org.whispersystems.libsignal.fingerprint";
|
||||
option java_outer_classname = "FingerprintProtos";
|
||||
|
||||
import "objectivec-descriptor.proto";
|
||||
option (google.protobuf.objectivec_file_options).class_prefix = "OWSFingerprintProtos";
|
||||
|
||||
message LogicalFingerprint {
|
||||
optional bytes identityData = 1;
|
||||
// optional bytes identifier = 2;
|
||||
@ -1,25 +1,26 @@
|
||||
# See README.md in this dir for prerequisite setup.
|
||||
|
||||
PROTOC=protoc \
|
||||
--plugin=/usr/local/bin/protoc-gen-objc \
|
||||
--proto_path="${HOME}/src/signal/protobuf-objc/src/compiler/" \
|
||||
--proto_path="${HOME}/src/signal/protobuf-objc/src/compiler/google/protobuf/" \
|
||||
--proto_path='./'
|
||||
|
||||
all: signal_service_proto provisioning_protos fingerprint_protos websocket_protos
|
||||
all: signal_service_protos provisioning_protos fingerprint_protos websocket_protos signal_ios_protos
|
||||
|
||||
signal_service_proto: OWSSignalServiceProtos.proto
|
||||
$(PROTOC) --objc_out=../src/Messages/ \
|
||||
OWSSignalServiceProtos.proto
|
||||
signal_service_protos: SignalService.proto
|
||||
$(PROTOC) --swift_out=../src/Protos/Generated \
|
||||
SignalService.proto
|
||||
|
||||
provisioning_protos: OWSProvisioningProtos.proto
|
||||
$(PROTOC) --objc_out=../src/Devices/ \
|
||||
OWSProvisioningProtos.proto
|
||||
provisioning_protos: Provisioning.proto
|
||||
$(PROTOC) --swift_out=../src/Protos/Generated \
|
||||
Provisioning.proto
|
||||
|
||||
fingerprint_protos: OWSFingerprintProtos.proto
|
||||
$(PROTOC) --objc_out=../src/Security/ \
|
||||
OWSFingerprintProtos.proto
|
||||
fingerprint_protos: Fingerprint.proto
|
||||
$(PROTOC) --swift_out=../src/Protos/Generated \
|
||||
Fingerprint.proto
|
||||
|
||||
websocket_protos: WebSocketResources.proto
|
||||
$(PROTOC) --objc_out=../src/Network/WebSockets/ \
|
||||
$(PROTOC) --swift_out=../src/Protos/Generated \
|
||||
WebSocketResources.proto
|
||||
|
||||
signal_ios_protos: SignalIOS.proto
|
||||
$(PROTOC) --swift_out=../src/Protos/Generated \
|
||||
SignalIOS.proto
|
||||
|
||||
@ -4,14 +4,15 @@
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package signalservice;
|
||||
// iOS - since we use a modern proto-compiler, we must specify
|
||||
// the legacy proto format.
|
||||
syntax = "proto2";
|
||||
|
||||
package ProvisioningProto;
|
||||
|
||||
option java_package = "org.whispersystems.signalservice.internal.push";
|
||||
option java_outer_classname = "ProvisioningProtos";
|
||||
|
||||
import "objectivec-descriptor.proto";
|
||||
option (google.protobuf.objectivec_file_options).class_prefix = "OWSProvisioningProtos";
|
||||
|
||||
message ProvisionEnvelope {
|
||||
optional bytes publicKey = 1;
|
||||
optional bytes body = 2; // Encrypted ProvisionMessage
|
||||
@ -1,38 +1,22 @@
|
||||
# SignalServiceKit Protobufs
|
||||
|
||||
These protobuf definitions are copied from Signal-Android, but modified
|
||||
to include a conventional ObjC classnames.
|
||||
|
||||
e.g.
|
||||
|
||||
import "objectivec-descriptor.proto";
|
||||
option (google.protobuf.objectivec_file_options).class_prefix = "OWSFingerprintProtos";
|
||||
to match some iOS conventions.
|
||||
|
||||
## Prequisites
|
||||
|
||||
Install protobuf 2.6, the objc plugin doesn't currently work with
|
||||
protobuf 3.0
|
||||
Install Apple's `swift-protobuf` (*not* the similarly named `protobuf-swift`)
|
||||
|
||||
brew install protobuf@2.6
|
||||
# Beware if you are depending on protobuf 3.0 elsewhere
|
||||
brew link --force protobuf@2.6
|
||||
brew install swift-protobuf
|
||||
|
||||
Install the objc plugin to $SignalServiceKitRoot/..
|
||||
This should install an up to date protobuf package as a dependency. Note that
|
||||
since we use the legacy proto2 format, we need to specify this in our .proto
|
||||
files.
|
||||
|
||||
e.g. I have SignalServiceKit installed to ~/src/WhisperSystems/SignalServiceKit
|
||||
|
||||
So I run
|
||||
|
||||
cd ~/src/WhisperSystems
|
||||
git clone https://github.com/alexeyxo/protobuf-objc
|
||||
|
||||
Follow the install instructions at https://github.com/alexeyxo/protobuf-objc
|
||||
syntax = "proto2";
|
||||
|
||||
## Building Protobuf
|
||||
|
||||
After changes are made to any proto, generate the ObjC classes by
|
||||
running:
|
||||
|
||||
cd ~/src/WhisperSystems/SignalServiceKit/protobuf
|
||||
make
|
||||
|
||||
|
||||
@ -4,11 +4,12 @@
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package signalios;
|
||||
// iOS - since we use a modern proto-compiler, we must specify
|
||||
// the legacy proto format.
|
||||
syntax = "proto2";
|
||||
|
||||
// Signal-iOS
|
||||
import "objectivec-descriptor.proto";
|
||||
option (google.protobuf.objectivec_file_options).class_prefix = "OWSSignaliOSProtos";
|
||||
// iOS - package name determines class prefix
|
||||
package IOSProtos;
|
||||
|
||||
message BackupSnapshot
|
||||
{
|
||||
@ -26,4 +27,4 @@ message BackupSnapshot
|
||||
}
|
||||
|
||||
repeated BackupEntity entity = 1;
|
||||
}
|
||||
}
|
||||
@ -4,15 +4,16 @@
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package signalservice;
|
||||
// iOS - since we use a modern proto-compiler, we must specify
|
||||
// the legacy proto format.
|
||||
syntax = "proto2";
|
||||
|
||||
// iOS - package name determines class prefix
|
||||
package SignalServiceProtos;
|
||||
|
||||
option java_package = "org.whispersystems.signalservice.internal.push";
|
||||
option java_outer_classname = "SignalServiceProtos";
|
||||
|
||||
// Signal-iOS
|
||||
import "objectivec-descriptor.proto";
|
||||
option (google.protobuf.objectivec_file_options).class_prefix = "OWSSignalServiceProtos";
|
||||
|
||||
message Envelope {
|
||||
enum Type {
|
||||
UNKNOWN = 0;
|
||||
@ -4,15 +4,16 @@
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package signalservice;
|
||||
// iOS - since we use a modern proto-compiler, we must specify
|
||||
// the legacy proto format.
|
||||
syntax = "proto2";
|
||||
|
||||
// iOS - package name determines class prefix
|
||||
package WebSocketProtos;
|
||||
|
||||
option java_package = "org.whispersystems.signalservice.internal.websocket";
|
||||
option java_outer_classname = "WebSocketProtos";
|
||||
|
||||
// Signal-iOS
|
||||
import "objectivec-descriptor.proto";
|
||||
option (google.protobuf.objectivec_file_options).class_prefix = "WebSocketResources";
|
||||
|
||||
message WebSocketRequestMessage
|
||||
{
|
||||
optional string verb = 1;
|
||||
@ -42,4 +43,4 @@ message WebSocketMessage
|
||||
optional Type type = 1;
|
||||
optional WebSocketRequestMessage request = 2;
|
||||
optional WebSocketResponseMessage response = 3;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,11 +3,12 @@
|
||||
//
|
||||
|
||||
#import "OWSReadTracking.h"
|
||||
#import "OWSSignalServiceProtos.pb.h"
|
||||
#import "TSMessage.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SSKEnvelope;
|
||||
|
||||
typedef NS_ENUM(int32_t, TSErrorMessageType) {
|
||||
TSErrorMessageNoSession,
|
||||
// DEPRECATED: We no longer create TSErrorMessageWrongTrustedIdentityKey, but
|
||||
@ -54,18 +55,18 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
|
||||
inThread:(nullable TSThread *)thread
|
||||
failedMessageType:(TSErrorMessageType)errorMessageType;
|
||||
|
||||
+ (instancetype)corruptedMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)corruptedMessageWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
+ (instancetype)corruptedMessageInUnknownThread;
|
||||
|
||||
+ (instancetype)invalidVersionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)invalidVersionWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
+ (instancetype)invalidKeyExceptionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)invalidKeyExceptionWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
+ (instancetype)missingSessionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)missingSessionWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
+ (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId;
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#import "TSContactThread.h"
|
||||
#import "TSErrorMessage_privateConstructor.h"
|
||||
#import "TextSecureKitEnv.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
#import <YapDatabase/YapDatabaseConnection.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@ -83,7 +84,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
|
||||
return [self initWithTimestamp:timestamp inThread:thread failedMessageType:errorMessageType recipientId:nil];
|
||||
}
|
||||
|
||||
- (instancetype)initWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (instancetype)initWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
failedMessageType:(TSErrorMessageType)errorMessageType
|
||||
{
|
||||
@ -145,7 +146,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
|
||||
}
|
||||
}
|
||||
|
||||
+ (instancetype)corruptedMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)corruptedMessageWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
return [[self alloc] initWithEnvelope:envelope
|
||||
@ -158,7 +159,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
|
||||
return [[self alloc] initWithFailedMessageType:TSErrorMessageInvalidMessage];
|
||||
}
|
||||
|
||||
+ (instancetype)invalidVersionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)invalidVersionWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
return [[self alloc] initWithEnvelope:envelope
|
||||
@ -166,7 +167,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
|
||||
failedMessageType:TSErrorMessageInvalidVersion];
|
||||
}
|
||||
|
||||
+ (instancetype)invalidKeyExceptionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)invalidKeyExceptionWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
return [[self alloc] initWithEnvelope:envelope
|
||||
@ -174,7 +175,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
|
||||
failedMessageType:TSErrorMessageInvalidKeyException];
|
||||
}
|
||||
|
||||
+ (instancetype)missingSessionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (instancetype)missingSessionWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
return
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
//
|
||||
// TSErrorMessage_privateConstructor.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 31/12/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSErrorMessage.h"
|
||||
@ -14,7 +10,7 @@
|
||||
inThread:(TSThread *)thread
|
||||
failedMessageType:(TSErrorMessageType)errorMessageType NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@property NSData *envelopeData;
|
||||
@property (atomic, nullable) NSData *envelopeData;
|
||||
|
||||
@property NSDictionary *pendingOutgoingMessage;
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSSignalServiceProtosDataMessage;
|
||||
@class OWSSignalServiceProtosEnvelope;
|
||||
@class TSAttachment;
|
||||
@class TSAttachmentStream;
|
||||
@class TSQuotedMessage;
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
//
|
||||
// TSInvalidIdentityKeyErrorMessage.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 31/12/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSInvalidIdentityKeyErrorMessage.h"
|
||||
|
||||
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
|
||||
|
||||
+ (instancetype)untrustedKeyWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#import "TSErrorMessage_privateConstructor.h"
|
||||
#import <AxolotlKit/NSData+keyVersionByte.h>
|
||||
#import <AxolotlKit/PreKeyWhisperMessage.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@ -27,46 +28,53 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation TSInvalidIdentityKeyReceivingErrorMessage {
|
||||
// Not using a property declaration in order to exclude from DB serialization
|
||||
OWSSignalServiceProtosEnvelope *_envelope;
|
||||
SSKEnvelope *_Nullable _envelope;
|
||||
}
|
||||
|
||||
@synthesize envelopeData = _envelopeData;
|
||||
|
||||
+ (instancetype)untrustedKeyWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
TSContactThread *contactThread =
|
||||
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
|
||||
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
|
||||
TSInvalidIdentityKeyReceivingErrorMessage *errorMessage =
|
||||
[[self alloc] initForUnknownIdentityKeyWithTimestamp:envelope.timestamp
|
||||
inThread:contactThread
|
||||
incomingEnvelope:envelope];
|
||||
[[self alloc] initForUnknownIdentityKeyWithTimestamp:envelope.timestamp
|
||||
inThread:contactThread
|
||||
incomingEnvelope:envelope];
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
- (instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp
|
||||
- (nullable instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSThread *)thread
|
||||
incomingEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
incomingEnvelope:(SSKEnvelope *)envelope
|
||||
{
|
||||
self = [self initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageWrongTrustedIdentityKey];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_envelopeData = envelope.data;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
- (OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (nullable SSKEnvelope *)envelope
|
||||
{
|
||||
if (!_envelope) {
|
||||
@try {
|
||||
_envelope = [OWSSignalServiceProtosEnvelope parseFromData:self.envelopeData];
|
||||
} @catch (NSException *exception) {
|
||||
OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, exception.debugDescription);
|
||||
// TODO: Add analytics.
|
||||
NSError *error;
|
||||
SSKEnvelope *_Nullable envelope = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error];
|
||||
if (error || envelope == nil) {
|
||||
OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, error);
|
||||
} else {
|
||||
_envelope = envelope;
|
||||
}
|
||||
}
|
||||
return _envelope;
|
||||
@ -94,7 +102,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
[self.thread receivedMessagesForInvalidKey:newKey];
|
||||
|
||||
for (TSInvalidIdentityKeyReceivingErrorMessage *errorMessage in messagesToDecrypt) {
|
||||
[[OWSMessageReceiver sharedInstance] handleReceivedEnvelope:errorMessage.envelope];
|
||||
[[OWSMessageReceiver sharedInstance] handleReceivedEnvelopeData:errorMessage.envelopeData];
|
||||
|
||||
// Here we remove the existing error message because handleReceivedEnvelope will either
|
||||
// 1.) succeed and create a new successful message in the thread or...
|
||||
@ -110,13 +118,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (self.envelope.type != OWSSignalServiceProtosEnvelopeTypePrekeyBundle) {
|
||||
if (self.envelope.type != SSKEnvelopeTypePrekeyBundle) {
|
||||
DDLogError(@"Refusing to attempt key extraction from an envelope which isn't a prekey bundle");
|
||||
return nil;
|
||||
}
|
||||
|
||||
// DEPRECATED - Remove after all clients have been upgraded.
|
||||
NSData *pkwmData = self.envelope.hasContent ? self.envelope.content : self.envelope.legacyMessage;
|
||||
NSData *pkwmData = self.envelope.content;
|
||||
if (!pkwmData) {
|
||||
DDLogError(@"Ignoring acceptNewIdentityKey for empty message");
|
||||
return nil;
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSSignalServiceProtosEnvelope;
|
||||
@class OWSStorage;
|
||||
@class SSKEnvelope;
|
||||
@class YapDatabaseReadWriteTransaction;
|
||||
|
||||
// This class is used to write incoming (decrypted, unprocessed)
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#import "TSYapDatabaseObject.h"
|
||||
#import "TextSecureKitEnv.h"
|
||||
#import "Threading.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
#import <YapDatabase/YapDatabaseAutoView.h>
|
||||
#import <YapDatabase/YapDatabaseConnection.h>
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
@ -28,8 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark - Persisted data model
|
||||
|
||||
@class OWSSignalServiceProtosEnvelope;
|
||||
|
||||
@interface OWSMessageContentJob : TSYapDatabaseObject
|
||||
|
||||
@property (nonatomic, readonly) NSDate *createdAt;
|
||||
@ -40,7 +39,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
plaintextData:(NSData *_Nullable)plaintextData NS_DESIGNATED_INITIALIZER;
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithUniqueId:(NSString *_Nullable)uniqueId NS_UNAVAILABLE;
|
||||
- (OWSSignalServiceProtosEnvelope *)envelopeProto;
|
||||
|
||||
@property (nonatomic, readonly, nullable) SSKEnvelope *envelope;
|
||||
|
||||
@end
|
||||
|
||||
@ -74,9 +74,17 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return [super initWithCoder:coder];
|
||||
}
|
||||
|
||||
- (OWSSignalServiceProtosEnvelope *)envelopeProto
|
||||
- (nullable SSKEnvelope *)envelope
|
||||
{
|
||||
return [OWSSignalServiceProtosEnvelope parseFromData:self.envelopeData];
|
||||
NSError *error;
|
||||
SSKEnvelope *_Nullable result = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error];
|
||||
|
||||
if (error) {
|
||||
OWSProdLogAndFail(@"%@ paring SSKEnvelope failed with error: %@", self.logTag, error);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -378,16 +386,27 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
||||
NSMutableArray<OWSMessageContentJob *> *processedJobs = [NSMutableArray new];
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (OWSMessageContentJob *job in jobs) {
|
||||
@try {
|
||||
[self.messagesManager processEnvelope:job.envelopeProto
|
||||
plaintextData:job.plaintextData
|
||||
transaction:transaction];
|
||||
} @catch (NSException *exception) {
|
||||
OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription);
|
||||
|
||||
void (^reportFailure)(YapDatabaseReadWriteTransaction *transaction) = ^(
|
||||
YapDatabaseReadWriteTransaction *transaction) {
|
||||
// TODO: Add analytics.
|
||||
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
|
||||
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
|
||||
transaction:transaction];
|
||||
};
|
||||
|
||||
@try {
|
||||
SSKEnvelope *_Nullable envelope = job.envelope;
|
||||
if (!envelope) {
|
||||
reportFailure(transaction);
|
||||
} else {
|
||||
[self.messagesManager processEnvelope:envelope
|
||||
plaintextData:job.plaintextData
|
||||
transaction:transaction];
|
||||
}
|
||||
} @catch (NSException *exception) {
|
||||
OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription);
|
||||
reportFailure(transaction);
|
||||
}
|
||||
[processedJobs addObject:job];
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSSignalServiceProtosEnvelope;
|
||||
@class SSKEnvelope;
|
||||
@class YapDatabaseReadWriteTransaction;
|
||||
|
||||
typedef void (^DecryptSuccessBlock)(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction);
|
||||
@ -22,7 +22,7 @@ typedef void (^DecryptFailureBlock)(void);
|
||||
//
|
||||
// Exactly one of successBlock & failureBlock will be called,
|
||||
// once.
|
||||
- (void)decryptEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)decryptEnvelope:(SSKEnvelope *)envelope
|
||||
successBlock:(DecryptSuccessBlock)successBlock
|
||||
failureBlock:(DecryptFailureBlock)failureBlock;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#import "TextSecureKitEnv.h"
|
||||
#import <AxolotlKit/AxolotlExceptions.h>
|
||||
#import <AxolotlKit/SessionCipher.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@ -80,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark - Blocking
|
||||
|
||||
- (BOOL)isEnvelopeBlocked:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (BOOL)isEnvelopeBlocked:(SSKEnvelope *)envelope
|
||||
{
|
||||
OWSAssert(envelope);
|
||||
|
||||
@ -89,7 +90,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark - Decryption
|
||||
|
||||
- (void)decryptEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)decryptEnvelope:(SSKEnvelope *)envelope
|
||||
successBlock:(DecryptSuccessBlock)successBlockParameter
|
||||
failureBlock:(DecryptFailureBlock)failureBlockParameter
|
||||
{
|
||||
@ -128,7 +129,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
|
||||
switch (envelope.type) {
|
||||
case OWSSignalServiceProtosEnvelopeTypeCiphertext: {
|
||||
case SSKEnvelopeTypeCiphertext: {
|
||||
[self decryptSecureMessage:envelope
|
||||
successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) {
|
||||
DDLogDebug(@"%@ decrypted secure message.", self.logTag);
|
||||
@ -145,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
// Return to avoid double-acknowledging.
|
||||
return;
|
||||
}
|
||||
case OWSSignalServiceProtosEnvelopeTypePrekeyBundle: {
|
||||
case SSKEnvelopeTypePrekeyBundle: {
|
||||
[self decryptPreKeyBundle:envelope
|
||||
successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) {
|
||||
DDLogDebug(@"%@ decrypted pre-key whisper message", self.logTag);
|
||||
@ -164,9 +165,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return;
|
||||
}
|
||||
// These message types don't have a payload to decrypt.
|
||||
case OWSSignalServiceProtosEnvelopeTypeReceipt:
|
||||
case OWSSignalServiceProtosEnvelopeTypeKeyExchange:
|
||||
case OWSSignalServiceProtosEnvelopeTypeUnknown: {
|
||||
case SSKEnvelopeTypeReceipt:
|
||||
case SSKEnvelopeTypeKeyExchange:
|
||||
case SSKEnvelopeTypeUnknown: {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
successBlock(nil, transaction);
|
||||
}];
|
||||
@ -192,7 +193,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
failureBlock();
|
||||
}
|
||||
|
||||
- (void)decryptSecureMessage:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)decryptSecureMessage:(SSKEnvelope *)envelope
|
||||
successBlock:(DecryptSuccessBlock)successBlock
|
||||
failureBlock:(void (^)(NSError *_Nullable error))failureBlock
|
||||
{
|
||||
@ -209,7 +210,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
failureBlock:failureBlock];
|
||||
}
|
||||
|
||||
- (void)decryptPreKeyBundle:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)decryptPreKeyBundle:(SSKEnvelope *)envelope
|
||||
successBlock:(DecryptSuccessBlock)successBlock
|
||||
failureBlock:(void (^)(NSError *_Nullable error))failureBlock
|
||||
{
|
||||
@ -229,7 +230,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
failureBlock:failureBlock];
|
||||
}
|
||||
|
||||
- (void)decryptEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)decryptEnvelope:(SSKEnvelope *)envelope
|
||||
cipherTypeName:(NSString *)cipherTypeName
|
||||
cipherMessageBlock:(id<CipherMessage> (^_Nonnull)(NSData *))cipherMessageBlock
|
||||
successBlock:(DecryptSuccessBlock)successBlock
|
||||
@ -245,8 +246,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
NSString *recipientId = envelope.source;
|
||||
int deviceId = envelope.sourceDevice;
|
||||
|
||||
// DEPRECATED - Remove after all clients have been upgraded.
|
||||
NSData *encryptedData = envelope.hasContent ? envelope.content : envelope.legacyMessage;
|
||||
// DEPRECATED - Remove `legacyMessage` after all clients have been upgraded.
|
||||
NSData *encryptedData = envelope.content ?: envelope.legacyMessage;
|
||||
if (!encryptedData) {
|
||||
OWSProdFail([OWSAnalyticsEvents messageManagerErrorMessageEnvelopeHasNoContent]);
|
||||
failureBlock(nil);
|
||||
@ -278,7 +279,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)processException:(NSException *)exception envelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)processException:(NSException *)exception envelope:(SSKEnvelope *)envelope
|
||||
{
|
||||
DDLogError(@"%@ Got exception: %@ of type: %@ with reason: %@",
|
||||
self.logTag,
|
||||
@ -325,7 +326,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
|
||||
- (void)notifyUserForErrorMessage:(TSErrorMessage *)errorMessage
|
||||
envelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
envelope:(SSKEnvelope *)envelope
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSSignalServiceProtosContent;
|
||||
@class OWSSignalServiceProtosDataMessage;
|
||||
@class OWSSignalServiceProtosEnvelope;
|
||||
@class SSKEnvelope;
|
||||
|
||||
NSString *envelopeAddress(OWSSignalServiceProtosEnvelope *envelope);
|
||||
NSString *envelopeAddress(SSKEnvelope *envelope);
|
||||
|
||||
@interface OWSMessageHandler : NSObject
|
||||
|
||||
- (NSString *)descriptionForEnvelopeType:(OWSSignalServiceProtosEnvelope *)envelope;
|
||||
- (NSString *)descriptionForEnvelope:(OWSSignalServiceProtosEnvelope *)envelope;
|
||||
- (NSString *)descriptionForEnvelopeType:(SSKEnvelope *)envelope;
|
||||
- (NSString *)descriptionForEnvelope:(SSKEnvelope *)envelope;
|
||||
- (NSString *)descriptionForContent:(OWSSignalServiceProtosContent *)content;
|
||||
- (NSString *)descriptionForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage;
|
||||
|
||||
|
||||
@ -4,35 +4,36 @@
|
||||
|
||||
#import "OWSMessageHandler.h"
|
||||
#import "OWSSignalServiceProtos.pb.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// used in log formatting
|
||||
NSString *envelopeAddress(OWSSignalServiceProtosEnvelope *envelope)
|
||||
NSString *envelopeAddress(SSKEnvelope *envelope)
|
||||
{
|
||||
return [NSString stringWithFormat:@"%@.%d", envelope.source, (unsigned int)envelope.sourceDevice];
|
||||
}
|
||||
|
||||
@implementation OWSMessageHandler
|
||||
|
||||
- (NSString *)descriptionForEnvelopeType:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (NSString *)descriptionForEnvelopeType:(SSKEnvelope *)envelope
|
||||
{
|
||||
OWSAssert(envelope != nil);
|
||||
|
||||
switch (envelope.type) {
|
||||
case OWSSignalServiceProtosEnvelopeTypeReceipt:
|
||||
case SSKEnvelopeTypeReceipt:
|
||||
return @"DeliveryReceipt";
|
||||
case OWSSignalServiceProtosEnvelopeTypeUnknown:
|
||||
case SSKEnvelopeTypeUnknown:
|
||||
// Shouldn't happen
|
||||
OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeUnknown]);
|
||||
return @"Unknown";
|
||||
case OWSSignalServiceProtosEnvelopeTypeCiphertext:
|
||||
case SSKEnvelopeTypeCiphertext:
|
||||
return @"SignalEncryptedMessage";
|
||||
case OWSSignalServiceProtosEnvelopeTypeKeyExchange:
|
||||
case SSKEnvelopeTypeKeyExchange:
|
||||
// Unsupported
|
||||
OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeKeyExchange]);
|
||||
return @"KeyExchange";
|
||||
case OWSSignalServiceProtosEnvelopeTypePrekeyBundle:
|
||||
case SSKEnvelopeTypePrekeyBundle:
|
||||
return @"PreKeyEncryptedMessage";
|
||||
default:
|
||||
// Shouldn't happen
|
||||
@ -41,7 +42,7 @@ NSString *envelopeAddress(OWSSignalServiceProtosEnvelope *envelope)
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)descriptionForEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (NSString *)descriptionForEnvelope:(SSKEnvelope *)envelope
|
||||
{
|
||||
OWSAssert(envelope != nil);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSSignalServiceProtosEnvelope;
|
||||
@class SSKEnvelope;
|
||||
@class TSThread;
|
||||
@class YapDatabaseReadWriteTransaction;
|
||||
|
||||
@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
+ (instancetype)sharedManager;
|
||||
|
||||
// processEnvelope: can be called from any thread.
|
||||
- (void)processEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)processEnvelope:(SSKEnvelope *)envelope
|
||||
plaintextData:(NSData *_Nullable)plaintextData
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
#import "TSOutgoingMessage.h"
|
||||
#import "TSQuotedMessage.h"
|
||||
#import "TextSecureKitEnv.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
#import <YapDatabase/YapDatabase.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@ -157,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark - Blocking
|
||||
|
||||
- (BOOL)isEnvelopeBlocked:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (BOOL)isEnvelopeBlocked:(SSKEnvelope *)envelope
|
||||
{
|
||||
OWSAssert(envelope);
|
||||
|
||||
@ -166,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark - message handling
|
||||
|
||||
- (void)processEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)processEnvelope:(SSKEnvelope *)envelope
|
||||
plaintextData:(NSData *_Nullable)plaintextData
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -188,8 +189,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
OWSAssert(![self isEnvelopeBlocked:envelope]);
|
||||
|
||||
switch (envelope.type) {
|
||||
case OWSSignalServiceProtosEnvelopeTypeCiphertext:
|
||||
case OWSSignalServiceProtosEnvelopeTypePrekeyBundle:
|
||||
case SSKEnvelopeTypeCiphertext:
|
||||
case SSKEnvelopeTypePrekeyBundle:
|
||||
if (plaintextData) {
|
||||
[self handleEnvelope:envelope plaintextData:plaintextData transaction:transaction];
|
||||
} else {
|
||||
@ -197,15 +198,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@"%@ missing decrypted data for envelope: %@", self.logTag, [self descriptionForEnvelope:envelope]);
|
||||
}
|
||||
break;
|
||||
case OWSSignalServiceProtosEnvelopeTypeReceipt:
|
||||
case SSKEnvelopeTypeReceipt:
|
||||
OWSAssert(!plaintextData);
|
||||
[self handleDeliveryReceipt:envelope transaction:transaction];
|
||||
break;
|
||||
// Other messages are just dismissed for now.
|
||||
case OWSSignalServiceProtosEnvelopeTypeKeyExchange:
|
||||
case SSKEnvelopeTypeKeyExchange:
|
||||
DDLogWarn(@"Received Key Exchange Message, not supported");
|
||||
break;
|
||||
case OWSSignalServiceProtosEnvelopeTypeUnknown:
|
||||
case SSKEnvelopeTypeUnknown:
|
||||
DDLogWarn(@"Received an unknown message type");
|
||||
break;
|
||||
default:
|
||||
@ -214,7 +215,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleDeliveryReceipt:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleDeliveryReceipt:(SSKEnvelope *)envelope
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(envelope);
|
||||
@ -271,16 +272,16 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleEnvelope:(SSKEnvelope *)envelope
|
||||
plaintextData:(NSData *)plaintextData
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(envelope);
|
||||
OWSAssert(plaintextData);
|
||||
OWSAssert(transaction);
|
||||
OWSAssert(envelope.hasTimestamp && envelope.timestamp > 0);
|
||||
OWSAssert(envelope.hasSource && envelope.source.length > 0);
|
||||
OWSAssert(envelope.hasSourceDevice && envelope.sourceDevice > 0);
|
||||
OWSAssert(envelope.timestamp > 0);
|
||||
OWSAssert(envelope.source.length > 0);
|
||||
OWSAssert(envelope.sourceDevice > 0);
|
||||
|
||||
BOOL duplicateEnvelope = [self.incomingMessageFinder existsMessageWithTimestamp:envelope.timestamp
|
||||
sourceId:envelope.source
|
||||
@ -294,7 +295,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return;
|
||||
}
|
||||
|
||||
if (envelope.hasContent) {
|
||||
if (envelope.content != nil) {
|
||||
OWSSignalServiceProtosContent *content = [OWSSignalServiceProtosContent parseFromData:plaintextData];
|
||||
DDLogInfo(@"%@ handling content: <Content: %@>", self.logTag, [self descriptionForContent:content]);
|
||||
|
||||
@ -313,7 +314,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
} else {
|
||||
DDLogWarn(@"%@ Ignoring envelope. Content with no known payload", self.logTag);
|
||||
}
|
||||
} else if (envelope.hasLegacyMessage) { // DEPRECATED - Remove after all clients have been upgraded.
|
||||
} else if (envelope.legacyMessage != nil) { // DEPRECATED - Remove after all clients have been upgraded.
|
||||
OWSSignalServiceProtosDataMessage *dataMessage =
|
||||
[OWSSignalServiceProtosDataMessage parseFromData:plaintextData];
|
||||
DDLogInfo(
|
||||
@ -325,7 +326,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleIncomingEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope
|
||||
withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -394,7 +395,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
|
||||
- (void)sendGroupInfoRequest:(NSData *)groupId
|
||||
envelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
envelope:(SSKEnvelope *)envelope
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(groupId.length > 0);
|
||||
@ -428,7 +429,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return [TextSecureKitEnv sharedEnv].profileManager;
|
||||
}
|
||||
|
||||
- (void)handleIncomingEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope
|
||||
withReceiptMessage:(OWSSignalServiceProtosReceiptMessage *)receiptMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -463,7 +464,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleIncomingEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope
|
||||
withCallMessage:(OWSSignalServiceProtosCallMessage *)callMessage
|
||||
{
|
||||
OWSAssert(envelope);
|
||||
@ -498,7 +499,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
});
|
||||
}
|
||||
|
||||
- (void)handleReceivedGroupAvatarUpdateWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleReceivedGroupAvatarUpdateWithEnvelope:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -536,7 +537,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)handleReceivedMediaWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleReceivedMediaWithEnvelope:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -584,7 +585,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)handleIncomingEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope
|
||||
withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -719,7 +720,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleEndSessionMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleEndSessionMessageWithEnvelope:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -736,7 +737,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
[self.primaryStorage deleteAllSessionsForContact:envelope.source protocolContext:transaction];
|
||||
}
|
||||
|
||||
- (void)handleExpirationTimerUpdateMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleExpirationTimerUpdateMessageWithEnvelope:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -779,7 +780,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
[message saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
- (void)handleProfileKeyMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleProfileKeyMessageWithEnvelope:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
{
|
||||
OWSAssert(envelope);
|
||||
@ -804,7 +805,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
[profileManager setProfileKeyData:profileKey forRecipientId:recipientId];
|
||||
}
|
||||
|
||||
- (void)handleReceivedTextMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleReceivedTextMessageWithEnvelope:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -845,7 +846,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleGroupInfoRequest:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleGroupInfoRequest:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
@ -901,7 +902,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
[self sendGroupUpdateForThread:gThread message:message];
|
||||
}
|
||||
|
||||
- (TSIncomingMessage *_Nullable)handleReceivedEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (TSIncomingMessage *_Nullable)handleReceivedEnvelope:(SSKEnvelope *)envelope
|
||||
withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
@ -1083,7 +1084,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage
|
||||
thread:(TSThread *)thread
|
||||
envelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
envelope:(SSKEnvelope *)envelope
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(thread);
|
||||
@ -1203,7 +1204,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* Group or Contact thread for message, creating a new contact thread if necessary,
|
||||
* but never creating a new group thread.
|
||||
*/
|
||||
- (nullable TSThread *)threadForEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (nullable TSThread *)threadForEnvelope:(SSKEnvelope *)envelope
|
||||
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSSignalServiceProtosEnvelope;
|
||||
@class OWSStorage;
|
||||
|
||||
// This class is used to write incoming (encrypted, unprocessed)
|
||||
@ -18,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
+ (NSString *)databaseExtensionName;
|
||||
+ (void)asyncRegisterDatabaseExtension:(OWSStorage *)storage;
|
||||
|
||||
- (void)handleReceivedEnvelope:(OWSSignalServiceProtosEnvelope *)envelope;
|
||||
- (void)handleReceivedEnvelopeData:(NSData *)envelopeData;
|
||||
- (void)handleAnyUnprocessedEnvelopesAsync;
|
||||
|
||||
@end
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#import "TSYapDatabaseObject.h"
|
||||
#import "TextSecureKitEnv.h"
|
||||
#import "Threading.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
#import <YapDatabase/YapDatabaseAutoView.h>
|
||||
#import <YapDatabase/YapDatabaseConnection.h>
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
@ -30,11 +31,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@property (nonatomic, readonly) NSDate *createdAt;
|
||||
@property (nonatomic, readonly) NSData *envelopeData;
|
||||
@property (nonatomic, readonly, nullable) SSKEnvelope *envelopeProto;
|
||||
|
||||
- (instancetype)initWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithEnvelopeData:(NSData *)envelopeData NS_DESIGNATED_INITIALIZER;
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithUniqueId:(NSString *_Nullable)uniqueId NS_UNAVAILABLE;
|
||||
- (OWSSignalServiceProtosEnvelope *)envelopeProto;
|
||||
|
||||
@end
|
||||
|
||||
@ -47,16 +48,16 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return @"OWSMessageProcessingJob";
|
||||
}
|
||||
|
||||
- (instancetype)initWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (instancetype)initWithEnvelopeData:(NSData *)envelopeData
|
||||
{
|
||||
OWSAssert(envelope);
|
||||
OWSAssert(envelopeData);
|
||||
|
||||
self = [super initWithUniqueId:[NSUUID new].UUIDString];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_envelopeData = envelope.data;
|
||||
_envelopeData = envelopeData;
|
||||
_createdAt = [NSDate new];
|
||||
|
||||
return self;
|
||||
@ -67,9 +68,16 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return [super initWithCoder:coder];
|
||||
}
|
||||
|
||||
- (OWSSignalServiceProtosEnvelope *)envelopeProto
|
||||
- (nullable SSKEnvelope *)envelopeProto
|
||||
{
|
||||
return [OWSSignalServiceProtosEnvelope parseFromData:self.envelopeData];
|
||||
NSError *error;
|
||||
SSKEnvelope *_Nullable envelope = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error];
|
||||
if (error || envelope == nil) {
|
||||
OWSFail(@"%@ failed to parase envelope with error: %@", self.logTag, error);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return envelope;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -123,10 +131,10 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
||||
return job;
|
||||
}
|
||||
|
||||
- (void)addJobForEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)addJobForEnvelopeData:(NSData *)envelopeData
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
OWSMessageDecryptJob *job = [[OWSMessageDecryptJob alloc] initWithEnvelope:envelope];
|
||||
OWSMessageDecryptJob *job = [[OWSMessageDecryptJob alloc] initWithEnvelopeData:envelopeData];
|
||||
[job saveWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
@ -265,9 +273,9 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
||||
return queue;
|
||||
}
|
||||
|
||||
- (void)enqueueEnvelopeForProcessing:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)enqueueEnvelopeData:(NSData *)envelopeData
|
||||
{
|
||||
[self.finder addJobForEnvelope:envelope];
|
||||
[self.finder addJobForEnvelopeData:envelopeData];
|
||||
}
|
||||
|
||||
- (void)drainQueue
|
||||
@ -319,7 +327,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
||||
AssertOnDispatchQueue(self.serialQueue);
|
||||
OWSAssert(job);
|
||||
|
||||
OWSSignalServiceProtosEnvelope *_Nullable envelope = nil;
|
||||
SSKEnvelope *_Nullable envelope = nil;
|
||||
@try {
|
||||
envelope = job.envelopeProto;
|
||||
} @catch (NSException *exception) {
|
||||
@ -441,11 +449,11 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
||||
[self.processingQueue drainQueue];
|
||||
}
|
||||
|
||||
- (void)handleReceivedEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
- (void)handleReceivedEnvelopeData:(NSData *)envelopeData
|
||||
{
|
||||
// Drop any too-large messages on the floor. Well behaving clients should never send them.
|
||||
NSUInteger kMaxEnvelopeByteCount = 250 * 1024;
|
||||
if (envelope.serializedSize > kMaxEnvelopeByteCount) {
|
||||
if (envelopeData.length > kMaxEnvelopeByteCount) {
|
||||
OWSProdError([OWSAnalyticsEvents messageReceiverErrorOversizeMessage]);
|
||||
return;
|
||||
}
|
||||
@ -453,11 +461,11 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
||||
// Take note of any messages larger than we expect, but still process them.
|
||||
// This likely indicates a misbehaving sending client.
|
||||
NSUInteger kLargeEnvelopeWarningByteCount = 25 * 1024;
|
||||
if (envelope.serializedSize > kLargeEnvelopeWarningByteCount) {
|
||||
if (envelopeData.length > kLargeEnvelopeWarningByteCount) {
|
||||
OWSProdError([OWSAnalyticsEvents messageReceiverErrorLargeMessage]);
|
||||
}
|
||||
|
||||
[self.processingQueue enqueueEnvelopeForProcessing:envelope];
|
||||
[self.processingQueue enqueueEnvelopeData:envelopeData];
|
||||
[self.processingQueue drainQueue];
|
||||
}
|
||||
|
||||
|
||||
@ -747,10 +747,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
||||
return;
|
||||
}
|
||||
|
||||
OWSSignalServiceProtosEnvelope *envelope =
|
||||
[OWSSignalServiceProtosEnvelope parseFromData:decryptedPayload];
|
||||
|
||||
[self.messageReceiver handleReceivedEnvelope:envelope];
|
||||
[self.messageReceiver handleReceivedEnvelopeData:decryptedPayload];
|
||||
} @catch (NSException *exception) {
|
||||
OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription);
|
||||
// TODO: Add analytics.
|
||||
|
||||
194
SignalServiceKit/src/Protos/Generated/Fingerprint.pb.swift
Normal file
194
SignalServiceKit/src/Protos/Generated/Fingerprint.pb.swift
Normal file
@ -0,0 +1,194 @@
|
||||
// DO NOT EDIT.
|
||||
//
|
||||
// Generated by the Swift generator plugin for the protocol buffer compiler.
|
||||
// Source: Fingerprint.proto
|
||||
//
|
||||
// For information on using the generated types, please see the documenation:
|
||||
// https://github.com/apple/swift-protobuf/
|
||||
|
||||
/// iOS - since we use a modern proto-compiler, we must specify
|
||||
/// the legacy proto format.
|
||||
|
||||
import Foundation
|
||||
import SwiftProtobuf
|
||||
|
||||
// If the compiler emits an error on this type, it is because this file
|
||||
// was generated by a version of the `protoc` Swift plug-in that is
|
||||
// incompatible with the version of SwiftProtobuf to which you are linking.
|
||||
// Please ensure that your are building against the same version of the API
|
||||
// that was used to generate this file.
|
||||
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
|
||||
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
|
||||
typealias Version = _2
|
||||
}
|
||||
|
||||
struct FingerprintProtos_LogicalFingerprint {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
/// optional bytes identifier = 2;
|
||||
var identityData: Data {
|
||||
get {return _identityData ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_identityData = newValue}
|
||||
}
|
||||
/// Returns true if `identityData` has been explicitly set.
|
||||
var hasIdentityData: Bool {return self._identityData != nil}
|
||||
/// Clears the value of `identityData`. Subsequent reads from it will return its default value.
|
||||
mutating func clearIdentityData() {self._identityData = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _identityData: Data? = nil
|
||||
}
|
||||
|
||||
struct FingerprintProtos_LogicalFingerprints {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var version: UInt32 {
|
||||
get {return _storage._version ?? 0}
|
||||
set {_uniqueStorage()._version = newValue}
|
||||
}
|
||||
/// Returns true if `version` has been explicitly set.
|
||||
var hasVersion: Bool {return _storage._version != nil}
|
||||
/// Clears the value of `version`. Subsequent reads from it will return its default value.
|
||||
mutating func clearVersion() {_storage._version = nil}
|
||||
|
||||
var localFingerprint: FingerprintProtos_LogicalFingerprint {
|
||||
get {return _storage._localFingerprint ?? FingerprintProtos_LogicalFingerprint()}
|
||||
set {_uniqueStorage()._localFingerprint = newValue}
|
||||
}
|
||||
/// Returns true if `localFingerprint` has been explicitly set.
|
||||
var hasLocalFingerprint: Bool {return _storage._localFingerprint != nil}
|
||||
/// Clears the value of `localFingerprint`. Subsequent reads from it will return its default value.
|
||||
mutating func clearLocalFingerprint() {_storage._localFingerprint = nil}
|
||||
|
||||
var remoteFingerprint: FingerprintProtos_LogicalFingerprint {
|
||||
get {return _storage._remoteFingerprint ?? FingerprintProtos_LogicalFingerprint()}
|
||||
set {_uniqueStorage()._remoteFingerprint = newValue}
|
||||
}
|
||||
/// Returns true if `remoteFingerprint` has been explicitly set.
|
||||
var hasRemoteFingerprint: Bool {return _storage._remoteFingerprint != nil}
|
||||
/// Clears the value of `remoteFingerprint`. Subsequent reads from it will return its default value.
|
||||
mutating func clearRemoteFingerprint() {_storage._remoteFingerprint = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _storage = _StorageClass.defaultInstance
|
||||
}
|
||||
|
||||
// MARK: - Code below here is support for the SwiftProtobuf runtime.
|
||||
|
||||
fileprivate let _protobuf_package = "FingerprintProtos"
|
||||
|
||||
extension FingerprintProtos_LogicalFingerprint: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".LogicalFingerprint"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "identityData"),
|
||||
]
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularBytesField(value: &self._identityData)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
if let v = self._identityData {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 1)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: FingerprintProtos_LogicalFingerprint) -> Bool {
|
||||
if self._identityData != other._identityData {return false}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension FingerprintProtos_LogicalFingerprints: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".LogicalFingerprints"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "version"),
|
||||
2: .same(proto: "localFingerprint"),
|
||||
3: .same(proto: "remoteFingerprint"),
|
||||
]
|
||||
|
||||
fileprivate class _StorageClass {
|
||||
var _version: UInt32? = nil
|
||||
var _localFingerprint: FingerprintProtos_LogicalFingerprint? = nil
|
||||
var _remoteFingerprint: FingerprintProtos_LogicalFingerprint? = nil
|
||||
|
||||
static let defaultInstance = _StorageClass()
|
||||
|
||||
private init() {}
|
||||
|
||||
init(copying source: _StorageClass) {
|
||||
_version = source._version
|
||||
_localFingerprint = source._localFingerprint
|
||||
_remoteFingerprint = source._remoteFingerprint
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate mutating func _uniqueStorage() -> _StorageClass {
|
||||
if !isKnownUniquelyReferenced(&_storage) {
|
||||
_storage = _StorageClass(copying: _storage)
|
||||
}
|
||||
return _storage
|
||||
}
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
_ = _uniqueStorage()
|
||||
try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularUInt32Field(value: &_storage._version)
|
||||
case 2: try decoder.decodeSingularMessageField(value: &_storage._localFingerprint)
|
||||
case 3: try decoder.decodeSingularMessageField(value: &_storage._remoteFingerprint)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
|
||||
if let v = _storage._version {
|
||||
try visitor.visitSingularUInt32Field(value: v, fieldNumber: 1)
|
||||
}
|
||||
if let v = _storage._localFingerprint {
|
||||
try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
|
||||
}
|
||||
if let v = _storage._remoteFingerprint {
|
||||
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
|
||||
}
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: FingerprintProtos_LogicalFingerprints) -> Bool {
|
||||
if _storage !== other._storage {
|
||||
let storagesAreEqual: Bool = withExtendedLifetime((_storage, other._storage)) { (_args: (_StorageClass, _StorageClass)) in
|
||||
let _storage = _args.0
|
||||
let other_storage = _args.1
|
||||
if _storage._version != other_storage._version {return false}
|
||||
if _storage._localFingerprint != other_storage._localFingerprint {return false}
|
||||
if _storage._remoteFingerprint != other_storage._remoteFingerprint {return false}
|
||||
return true
|
||||
}
|
||||
if !storagesAreEqual {return false}
|
||||
}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
245
SignalServiceKit/src/Protos/Generated/Provisioning.pb.swift
Normal file
245
SignalServiceKit/src/Protos/Generated/Provisioning.pb.swift
Normal file
@ -0,0 +1,245 @@
|
||||
// DO NOT EDIT.
|
||||
//
|
||||
// Generated by the Swift generator plugin for the protocol buffer compiler.
|
||||
// Source: Provisioning.proto
|
||||
//
|
||||
// For information on using the generated types, please see the documenation:
|
||||
// https://github.com/apple/swift-protobuf/
|
||||
|
||||
//*
|
||||
// Copyright (C) 2014-2016 Open Whisper Systems
|
||||
//
|
||||
// Licensed according to the LICENSE file in this repository.
|
||||
|
||||
/// iOS - since we use a modern proto-compiler, we must specify
|
||||
/// the legacy proto format.
|
||||
|
||||
import Foundation
|
||||
import SwiftProtobuf
|
||||
|
||||
// If the compiler emits an error on this type, it is because this file
|
||||
// was generated by a version of the `protoc` Swift plug-in that is
|
||||
// incompatible with the version of SwiftProtobuf to which you are linking.
|
||||
// Please ensure that your are building against the same version of the API
|
||||
// that was used to generate this file.
|
||||
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
|
||||
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
|
||||
typealias Version = _2
|
||||
}
|
||||
|
||||
struct ProvisioningProto_ProvisionEnvelope {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var publicKey: Data {
|
||||
get {return _publicKey ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_publicKey = newValue}
|
||||
}
|
||||
/// Returns true if `publicKey` has been explicitly set.
|
||||
var hasPublicKey: Bool {return self._publicKey != nil}
|
||||
/// Clears the value of `publicKey`. Subsequent reads from it will return its default value.
|
||||
mutating func clearPublicKey() {self._publicKey = nil}
|
||||
|
||||
/// Encrypted ProvisionMessage
|
||||
var body: Data {
|
||||
get {return _body ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_body = newValue}
|
||||
}
|
||||
/// Returns true if `body` has been explicitly set.
|
||||
var hasBody: Bool {return self._body != nil}
|
||||
/// Clears the value of `body`. Subsequent reads from it will return its default value.
|
||||
mutating func clearBody() {self._body = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _publicKey: Data? = nil
|
||||
fileprivate var _body: Data? = nil
|
||||
}
|
||||
|
||||
struct ProvisioningProto_ProvisionMessage {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var identityKeyPublic: Data {
|
||||
get {return _identityKeyPublic ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_identityKeyPublic = newValue}
|
||||
}
|
||||
/// Returns true if `identityKeyPublic` has been explicitly set.
|
||||
var hasIdentityKeyPublic: Bool {return self._identityKeyPublic != nil}
|
||||
/// Clears the value of `identityKeyPublic`. Subsequent reads from it will return its default value.
|
||||
mutating func clearIdentityKeyPublic() {self._identityKeyPublic = nil}
|
||||
|
||||
var identityKeyPrivate: Data {
|
||||
get {return _identityKeyPrivate ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_identityKeyPrivate = newValue}
|
||||
}
|
||||
/// Returns true if `identityKeyPrivate` has been explicitly set.
|
||||
var hasIdentityKeyPrivate: Bool {return self._identityKeyPrivate != nil}
|
||||
/// Clears the value of `identityKeyPrivate`. Subsequent reads from it will return its default value.
|
||||
mutating func clearIdentityKeyPrivate() {self._identityKeyPrivate = nil}
|
||||
|
||||
var number: String {
|
||||
get {return _number ?? String()}
|
||||
set {_number = newValue}
|
||||
}
|
||||
/// Returns true if `number` has been explicitly set.
|
||||
var hasNumber: Bool {return self._number != nil}
|
||||
/// Clears the value of `number`. Subsequent reads from it will return its default value.
|
||||
mutating func clearNumber() {self._number = nil}
|
||||
|
||||
var provisioningCode: String {
|
||||
get {return _provisioningCode ?? String()}
|
||||
set {_provisioningCode = newValue}
|
||||
}
|
||||
/// Returns true if `provisioningCode` has been explicitly set.
|
||||
var hasProvisioningCode: Bool {return self._provisioningCode != nil}
|
||||
/// Clears the value of `provisioningCode`. Subsequent reads from it will return its default value.
|
||||
mutating func clearProvisioningCode() {self._provisioningCode = nil}
|
||||
|
||||
var userAgent: String {
|
||||
get {return _userAgent ?? String()}
|
||||
set {_userAgent = newValue}
|
||||
}
|
||||
/// Returns true if `userAgent` has been explicitly set.
|
||||
var hasUserAgent: Bool {return self._userAgent != nil}
|
||||
/// Clears the value of `userAgent`. Subsequent reads from it will return its default value.
|
||||
mutating func clearUserAgent() {self._userAgent = nil}
|
||||
|
||||
var profileKey: Data {
|
||||
get {return _profileKey ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_profileKey = newValue}
|
||||
}
|
||||
/// Returns true if `profileKey` has been explicitly set.
|
||||
var hasProfileKey: Bool {return self._profileKey != nil}
|
||||
/// Clears the value of `profileKey`. Subsequent reads from it will return its default value.
|
||||
mutating func clearProfileKey() {self._profileKey = nil}
|
||||
|
||||
var readReceipts: Bool {
|
||||
get {return _readReceipts ?? false}
|
||||
set {_readReceipts = newValue}
|
||||
}
|
||||
/// Returns true if `readReceipts` has been explicitly set.
|
||||
var hasReadReceipts: Bool {return self._readReceipts != nil}
|
||||
/// Clears the value of `readReceipts`. Subsequent reads from it will return its default value.
|
||||
mutating func clearReadReceipts() {self._readReceipts = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _identityKeyPublic: Data? = nil
|
||||
fileprivate var _identityKeyPrivate: Data? = nil
|
||||
fileprivate var _number: String? = nil
|
||||
fileprivate var _provisioningCode: String? = nil
|
||||
fileprivate var _userAgent: String? = nil
|
||||
fileprivate var _profileKey: Data? = nil
|
||||
fileprivate var _readReceipts: Bool? = nil
|
||||
}
|
||||
|
||||
// MARK: - Code below here is support for the SwiftProtobuf runtime.
|
||||
|
||||
fileprivate let _protobuf_package = "ProvisioningProto"
|
||||
|
||||
extension ProvisioningProto_ProvisionEnvelope: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".ProvisionEnvelope"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "publicKey"),
|
||||
2: .same(proto: "body"),
|
||||
]
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularBytesField(value: &self._publicKey)
|
||||
case 2: try decoder.decodeSingularBytesField(value: &self._body)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
if let v = self._publicKey {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 1)
|
||||
}
|
||||
if let v = self._body {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 2)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: ProvisioningProto_ProvisionEnvelope) -> Bool {
|
||||
if self._publicKey != other._publicKey {return false}
|
||||
if self._body != other._body {return false}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension ProvisioningProto_ProvisionMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".ProvisionMessage"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "identityKeyPublic"),
|
||||
2: .same(proto: "identityKeyPrivate"),
|
||||
3: .same(proto: "number"),
|
||||
4: .same(proto: "provisioningCode"),
|
||||
5: .same(proto: "userAgent"),
|
||||
6: .same(proto: "profileKey"),
|
||||
7: .same(proto: "readReceipts"),
|
||||
]
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularBytesField(value: &self._identityKeyPublic)
|
||||
case 2: try decoder.decodeSingularBytesField(value: &self._identityKeyPrivate)
|
||||
case 3: try decoder.decodeSingularStringField(value: &self._number)
|
||||
case 4: try decoder.decodeSingularStringField(value: &self._provisioningCode)
|
||||
case 5: try decoder.decodeSingularStringField(value: &self._userAgent)
|
||||
case 6: try decoder.decodeSingularBytesField(value: &self._profileKey)
|
||||
case 7: try decoder.decodeSingularBoolField(value: &self._readReceipts)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
if let v = self._identityKeyPublic {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 1)
|
||||
}
|
||||
if let v = self._identityKeyPrivate {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 2)
|
||||
}
|
||||
if let v = self._number {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 3)
|
||||
}
|
||||
if let v = self._provisioningCode {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 4)
|
||||
}
|
||||
if let v = self._userAgent {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 5)
|
||||
}
|
||||
if let v = self._profileKey {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 6)
|
||||
}
|
||||
if let v = self._readReceipts {
|
||||
try visitor.visitSingularBoolField(value: v, fieldNumber: 7)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: ProvisioningProto_ProvisionMessage) -> Bool {
|
||||
if self._identityKeyPublic != other._identityKeyPublic {return false}
|
||||
if self._identityKeyPrivate != other._identityKeyPrivate {return false}
|
||||
if self._number != other._number {return false}
|
||||
if self._provisioningCode != other._provisioningCode {return false}
|
||||
if self._userAgent != other._userAgent {return false}
|
||||
if self._profileKey != other._profileKey {return false}
|
||||
if self._readReceipts != other._readReceipts {return false}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
184
SignalServiceKit/src/Protos/Generated/SignalIOS.pb.swift
Normal file
184
SignalServiceKit/src/Protos/Generated/SignalIOS.pb.swift
Normal file
@ -0,0 +1,184 @@
|
||||
// DO NOT EDIT.
|
||||
//
|
||||
// Generated by the Swift generator plugin for the protocol buffer compiler.
|
||||
// Source: SignalIOS.proto
|
||||
//
|
||||
// For information on using the generated types, please see the documenation:
|
||||
// https://github.com/apple/swift-protobuf/
|
||||
|
||||
//*
|
||||
// Copyright (C) 2014-2016 Open Whisper Systems
|
||||
//
|
||||
// Licensed according to the LICENSE file in this repository.
|
||||
|
||||
/// iOS - since we use a modern proto-compiler, we must specify
|
||||
/// the legacy proto format.
|
||||
|
||||
import Foundation
|
||||
import SwiftProtobuf
|
||||
|
||||
// If the compiler emits an error on this type, it is because this file
|
||||
// was generated by a version of the `protoc` Swift plug-in that is
|
||||
// incompatible with the version of SwiftProtobuf to which you are linking.
|
||||
// Please ensure that your are building against the same version of the API
|
||||
// that was used to generate this file.
|
||||
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
|
||||
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
|
||||
typealias Version = _2
|
||||
}
|
||||
|
||||
struct IOSProtos_BackupSnapshot {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var entity: [IOSProtos_BackupSnapshot.BackupEntity] = []
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
struct BackupEntity {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var type: IOSProtos_BackupSnapshot.BackupEntity.TypeEnum {
|
||||
get {return _type ?? .unknown}
|
||||
set {_type = newValue}
|
||||
}
|
||||
/// Returns true if `type` has been explicitly set.
|
||||
var hasType: Bool {return self._type != nil}
|
||||
/// Clears the value of `type`. Subsequent reads from it will return its default value.
|
||||
mutating func clearType() {self._type = nil}
|
||||
|
||||
var entityData: Data {
|
||||
get {return _entityData ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_entityData = newValue}
|
||||
}
|
||||
/// Returns true if `entityData` has been explicitly set.
|
||||
var hasEntityData: Bool {return self._entityData != nil}
|
||||
/// Clears the value of `entityData`. Subsequent reads from it will return its default value.
|
||||
mutating func clearEntityData() {self._entityData = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
enum TypeEnum: SwiftProtobuf.Enum {
|
||||
typealias RawValue = Int
|
||||
case unknown // = 0
|
||||
case migration // = 1
|
||||
case thread // = 2
|
||||
case interaction // = 3
|
||||
case attachment // = 4
|
||||
|
||||
init() {
|
||||
self = .unknown
|
||||
}
|
||||
|
||||
init?(rawValue: Int) {
|
||||
switch rawValue {
|
||||
case 0: self = .unknown
|
||||
case 1: self = .migration
|
||||
case 2: self = .thread
|
||||
case 3: self = .interaction
|
||||
case 4: self = .attachment
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
||||
var rawValue: Int {
|
||||
switch self {
|
||||
case .unknown: return 0
|
||||
case .migration: return 1
|
||||
case .thread: return 2
|
||||
case .interaction: return 3
|
||||
case .attachment: return 4
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _type: IOSProtos_BackupSnapshot.BackupEntity.TypeEnum? = nil
|
||||
fileprivate var _entityData: Data? = nil
|
||||
}
|
||||
|
||||
init() {}
|
||||
}
|
||||
|
||||
// MARK: - Code below here is support for the SwiftProtobuf runtime.
|
||||
|
||||
fileprivate let _protobuf_package = "IOSProtos"
|
||||
|
||||
extension IOSProtos_BackupSnapshot: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".BackupSnapshot"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "entity"),
|
||||
]
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeRepeatedMessageField(value: &self.entity)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
if !self.entity.isEmpty {
|
||||
try visitor.visitRepeatedMessageField(value: self.entity, fieldNumber: 1)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: IOSProtos_BackupSnapshot) -> Bool {
|
||||
if self.entity != other.entity {return false}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension IOSProtos_BackupSnapshot.BackupEntity: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = IOSProtos_BackupSnapshot.protoMessageName + ".BackupEntity"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "type"),
|
||||
2: .same(proto: "entityData"),
|
||||
]
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularEnumField(value: &self._type)
|
||||
case 2: try decoder.decodeSingularBytesField(value: &self._entityData)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
if let v = self._type {
|
||||
try visitor.visitSingularEnumField(value: v, fieldNumber: 1)
|
||||
}
|
||||
if let v = self._entityData {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 2)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: IOSProtos_BackupSnapshot.BackupEntity) -> Bool {
|
||||
if self._type != other._type {return false}
|
||||
if self._entityData != other._entityData {return false}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension IOSProtos_BackupSnapshot.BackupEntity.TypeEnum: SwiftProtobuf._ProtoNameProviding {
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
0: .same(proto: "UNKNOWN"),
|
||||
1: .same(proto: "MIGRATION"),
|
||||
2: .same(proto: "THREAD"),
|
||||
3: .same(proto: "INTERACTION"),
|
||||
4: .same(proto: "ATTACHMENT"),
|
||||
]
|
||||
}
|
||||
4202
SignalServiceKit/src/Protos/Generated/SignalService.pb.swift
Normal file
4202
SignalServiceKit/src/Protos/Generated/SignalService.pb.swift
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,397 @@
|
||||
// DO NOT EDIT.
|
||||
//
|
||||
// Generated by the Swift generator plugin for the protocol buffer compiler.
|
||||
// Source: WebSocketResources.proto
|
||||
//
|
||||
// For information on using the generated types, please see the documenation:
|
||||
// https://github.com/apple/swift-protobuf/
|
||||
|
||||
//*
|
||||
// Copyright (C) 2014-2016 Open Whisper Systems
|
||||
//
|
||||
// Licensed according to the LICENSE file in this repository.
|
||||
|
||||
/// iOS - since we use a modern proto-compiler, we must specify
|
||||
/// the legacy proto format.
|
||||
|
||||
import Foundation
|
||||
import SwiftProtobuf
|
||||
|
||||
// If the compiler emits an error on this type, it is because this file
|
||||
// was generated by a version of the `protoc` Swift plug-in that is
|
||||
// incompatible with the version of SwiftProtobuf to which you are linking.
|
||||
// Please ensure that your are building against the same version of the API
|
||||
// that was used to generate this file.
|
||||
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
|
||||
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
|
||||
typealias Version = _2
|
||||
}
|
||||
|
||||
struct WebSocketProtos_WebSocketRequestMessage {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var verb: String {
|
||||
get {return _verb ?? String()}
|
||||
set {_verb = newValue}
|
||||
}
|
||||
/// Returns true if `verb` has been explicitly set.
|
||||
var hasVerb: Bool {return self._verb != nil}
|
||||
/// Clears the value of `verb`. Subsequent reads from it will return its default value.
|
||||
mutating func clearVerb() {self._verb = nil}
|
||||
|
||||
var path: String {
|
||||
get {return _path ?? String()}
|
||||
set {_path = newValue}
|
||||
}
|
||||
/// Returns true if `path` has been explicitly set.
|
||||
var hasPath: Bool {return self._path != nil}
|
||||
/// Clears the value of `path`. Subsequent reads from it will return its default value.
|
||||
mutating func clearPath() {self._path = nil}
|
||||
|
||||
var body: Data {
|
||||
get {return _body ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_body = newValue}
|
||||
}
|
||||
/// Returns true if `body` has been explicitly set.
|
||||
var hasBody: Bool {return self._body != nil}
|
||||
/// Clears the value of `body`. Subsequent reads from it will return its default value.
|
||||
mutating func clearBody() {self._body = nil}
|
||||
|
||||
var headers: [String] = []
|
||||
|
||||
var requestID: UInt64 {
|
||||
get {return _requestID ?? 0}
|
||||
set {_requestID = newValue}
|
||||
}
|
||||
/// Returns true if `requestID` has been explicitly set.
|
||||
var hasRequestID: Bool {return self._requestID != nil}
|
||||
/// Clears the value of `requestID`. Subsequent reads from it will return its default value.
|
||||
mutating func clearRequestID() {self._requestID = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _verb: String? = nil
|
||||
fileprivate var _path: String? = nil
|
||||
fileprivate var _body: Data? = nil
|
||||
fileprivate var _requestID: UInt64? = nil
|
||||
}
|
||||
|
||||
struct WebSocketProtos_WebSocketResponseMessage {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var requestID: UInt64 {
|
||||
get {return _requestID ?? 0}
|
||||
set {_requestID = newValue}
|
||||
}
|
||||
/// Returns true if `requestID` has been explicitly set.
|
||||
var hasRequestID: Bool {return self._requestID != nil}
|
||||
/// Clears the value of `requestID`. Subsequent reads from it will return its default value.
|
||||
mutating func clearRequestID() {self._requestID = nil}
|
||||
|
||||
var status: UInt32 {
|
||||
get {return _status ?? 0}
|
||||
set {_status = newValue}
|
||||
}
|
||||
/// Returns true if `status` has been explicitly set.
|
||||
var hasStatus: Bool {return self._status != nil}
|
||||
/// Clears the value of `status`. Subsequent reads from it will return its default value.
|
||||
mutating func clearStatus() {self._status = nil}
|
||||
|
||||
var message: String {
|
||||
get {return _message ?? String()}
|
||||
set {_message = newValue}
|
||||
}
|
||||
/// Returns true if `message` has been explicitly set.
|
||||
var hasMessage: Bool {return self._message != nil}
|
||||
/// Clears the value of `message`. Subsequent reads from it will return its default value.
|
||||
mutating func clearMessage() {self._message = nil}
|
||||
|
||||
var headers: [String] = []
|
||||
|
||||
var body: Data {
|
||||
get {return _body ?? SwiftProtobuf.Internal.emptyData}
|
||||
set {_body = newValue}
|
||||
}
|
||||
/// Returns true if `body` has been explicitly set.
|
||||
var hasBody: Bool {return self._body != nil}
|
||||
/// Clears the value of `body`. Subsequent reads from it will return its default value.
|
||||
mutating func clearBody() {self._body = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _requestID: UInt64? = nil
|
||||
fileprivate var _status: UInt32? = nil
|
||||
fileprivate var _message: String? = nil
|
||||
fileprivate var _body: Data? = nil
|
||||
}
|
||||
|
||||
struct WebSocketProtos_WebSocketMessage {
|
||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var type: WebSocketProtos_WebSocketMessage.TypeEnum {
|
||||
get {return _storage._type ?? .unknown}
|
||||
set {_uniqueStorage()._type = newValue}
|
||||
}
|
||||
/// Returns true if `type` has been explicitly set.
|
||||
var hasType: Bool {return _storage._type != nil}
|
||||
/// Clears the value of `type`. Subsequent reads from it will return its default value.
|
||||
mutating func clearType() {_storage._type = nil}
|
||||
|
||||
var request: WebSocketProtos_WebSocketRequestMessage {
|
||||
get {return _storage._request ?? WebSocketProtos_WebSocketRequestMessage()}
|
||||
set {_uniqueStorage()._request = newValue}
|
||||
}
|
||||
/// Returns true if `request` has been explicitly set.
|
||||
var hasRequest: Bool {return _storage._request != nil}
|
||||
/// Clears the value of `request`. Subsequent reads from it will return its default value.
|
||||
mutating func clearRequest() {_storage._request = nil}
|
||||
|
||||
var response: WebSocketProtos_WebSocketResponseMessage {
|
||||
get {return _storage._response ?? WebSocketProtos_WebSocketResponseMessage()}
|
||||
set {_uniqueStorage()._response = newValue}
|
||||
}
|
||||
/// Returns true if `response` has been explicitly set.
|
||||
var hasResponse: Bool {return _storage._response != nil}
|
||||
/// Clears the value of `response`. Subsequent reads from it will return its default value.
|
||||
mutating func clearResponse() {_storage._response = nil}
|
||||
|
||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||
|
||||
enum TypeEnum: SwiftProtobuf.Enum {
|
||||
typealias RawValue = Int
|
||||
case unknown // = 0
|
||||
case request // = 1
|
||||
case response // = 2
|
||||
|
||||
init() {
|
||||
self = .unknown
|
||||
}
|
||||
|
||||
init?(rawValue: Int) {
|
||||
switch rawValue {
|
||||
case 0: self = .unknown
|
||||
case 1: self = .request
|
||||
case 2: self = .response
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
||||
var rawValue: Int {
|
||||
switch self {
|
||||
case .unknown: return 0
|
||||
case .request: return 1
|
||||
case .response: return 2
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
fileprivate var _storage = _StorageClass.defaultInstance
|
||||
}
|
||||
|
||||
// MARK: - Code below here is support for the SwiftProtobuf runtime.
|
||||
|
||||
fileprivate let _protobuf_package = "WebSocketProtos"
|
||||
|
||||
extension WebSocketProtos_WebSocketRequestMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".WebSocketRequestMessage"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "verb"),
|
||||
2: .same(proto: "path"),
|
||||
3: .same(proto: "body"),
|
||||
5: .same(proto: "headers"),
|
||||
4: .same(proto: "requestId"),
|
||||
]
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularStringField(value: &self._verb)
|
||||
case 2: try decoder.decodeSingularStringField(value: &self._path)
|
||||
case 3: try decoder.decodeSingularBytesField(value: &self._body)
|
||||
case 4: try decoder.decodeSingularUInt64Field(value: &self._requestID)
|
||||
case 5: try decoder.decodeRepeatedStringField(value: &self.headers)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
if let v = self._verb {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 1)
|
||||
}
|
||||
if let v = self._path {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 2)
|
||||
}
|
||||
if let v = self._body {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 3)
|
||||
}
|
||||
if let v = self._requestID {
|
||||
try visitor.visitSingularUInt64Field(value: v, fieldNumber: 4)
|
||||
}
|
||||
if !self.headers.isEmpty {
|
||||
try visitor.visitRepeatedStringField(value: self.headers, fieldNumber: 5)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: WebSocketProtos_WebSocketRequestMessage) -> Bool {
|
||||
if self._verb != other._verb {return false}
|
||||
if self._path != other._path {return false}
|
||||
if self._body != other._body {return false}
|
||||
if self.headers != other.headers {return false}
|
||||
if self._requestID != other._requestID {return false}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension WebSocketProtos_WebSocketResponseMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".WebSocketResponseMessage"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "requestId"),
|
||||
2: .same(proto: "status"),
|
||||
3: .same(proto: "message"),
|
||||
5: .same(proto: "headers"),
|
||||
4: .same(proto: "body"),
|
||||
]
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularUInt64Field(value: &self._requestID)
|
||||
case 2: try decoder.decodeSingularUInt32Field(value: &self._status)
|
||||
case 3: try decoder.decodeSingularStringField(value: &self._message)
|
||||
case 4: try decoder.decodeSingularBytesField(value: &self._body)
|
||||
case 5: try decoder.decodeRepeatedStringField(value: &self.headers)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
if let v = self._requestID {
|
||||
try visitor.visitSingularUInt64Field(value: v, fieldNumber: 1)
|
||||
}
|
||||
if let v = self._status {
|
||||
try visitor.visitSingularUInt32Field(value: v, fieldNumber: 2)
|
||||
}
|
||||
if let v = self._message {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 3)
|
||||
}
|
||||
if let v = self._body {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 4)
|
||||
}
|
||||
if !self.headers.isEmpty {
|
||||
try visitor.visitRepeatedStringField(value: self.headers, fieldNumber: 5)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: WebSocketProtos_WebSocketResponseMessage) -> Bool {
|
||||
if self._requestID != other._requestID {return false}
|
||||
if self._status != other._status {return false}
|
||||
if self._message != other._message {return false}
|
||||
if self.headers != other.headers {return false}
|
||||
if self._body != other._body {return false}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension WebSocketProtos_WebSocketMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||
static let protoMessageName: String = _protobuf_package + ".WebSocketMessage"
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
1: .same(proto: "type"),
|
||||
2: .same(proto: "request"),
|
||||
3: .same(proto: "response"),
|
||||
]
|
||||
|
||||
fileprivate class _StorageClass {
|
||||
var _type: WebSocketProtos_WebSocketMessage.TypeEnum? = nil
|
||||
var _request: WebSocketProtos_WebSocketRequestMessage? = nil
|
||||
var _response: WebSocketProtos_WebSocketResponseMessage? = nil
|
||||
|
||||
static let defaultInstance = _StorageClass()
|
||||
|
||||
private init() {}
|
||||
|
||||
init(copying source: _StorageClass) {
|
||||
_type = source._type
|
||||
_request = source._request
|
||||
_response = source._response
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate mutating func _uniqueStorage() -> _StorageClass {
|
||||
if !isKnownUniquelyReferenced(&_storage) {
|
||||
_storage = _StorageClass(copying: _storage)
|
||||
}
|
||||
return _storage
|
||||
}
|
||||
|
||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||
_ = _uniqueStorage()
|
||||
try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
|
||||
while let fieldNumber = try decoder.nextFieldNumber() {
|
||||
switch fieldNumber {
|
||||
case 1: try decoder.decodeSingularEnumField(value: &_storage._type)
|
||||
case 2: try decoder.decodeSingularMessageField(value: &_storage._request)
|
||||
case 3: try decoder.decodeSingularMessageField(value: &_storage._response)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||
try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
|
||||
if let v = _storage._type {
|
||||
try visitor.visitSingularEnumField(value: v, fieldNumber: 1)
|
||||
}
|
||||
if let v = _storage._request {
|
||||
try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
|
||||
}
|
||||
if let v = _storage._response {
|
||||
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
|
||||
}
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
func _protobuf_generated_isEqualTo(other: WebSocketProtos_WebSocketMessage) -> Bool {
|
||||
if _storage !== other._storage {
|
||||
let storagesAreEqual: Bool = withExtendedLifetime((_storage, other._storage)) { (_args: (_StorageClass, _StorageClass)) in
|
||||
let _storage = _args.0
|
||||
let other_storage = _args.1
|
||||
if _storage._type != other_storage._type {return false}
|
||||
if _storage._request != other_storage._request {return false}
|
||||
if _storage._response != other_storage._response {return false}
|
||||
return true
|
||||
}
|
||||
if !storagesAreEqual {return false}
|
||||
}
|
||||
if unknownFields != other.unknownFields {return false}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension WebSocketProtos_WebSocketMessage.TypeEnum: SwiftProtobuf._ProtoNameProviding {
|
||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||
0: .same(proto: "UNKNOWN"),
|
||||
1: .same(proto: "REQUEST"),
|
||||
2: .same(proto: "RESPONSE"),
|
||||
]
|
||||
}
|
||||
149
SignalServiceKit/src/Protos/ProtoWrappers/SSKEnvelope.swift
Normal file
149
SignalServiceKit/src/Protos/ProtoWrappers/SSKEnvelope.swift
Normal file
@ -0,0 +1,149 @@
|
||||
//
|
||||
// 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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user