diff --git a/ChatSecure/Classes/Controllers/FileTransferManager.swift b/ChatSecure/Classes/Controllers/FileTransferManager.swift index 73dea9479..b6f3a8f5d 100644 --- a/ChatSecure/Classes/Controllers/FileTransferManager.swift +++ b/ChatSecure/Classes/Controllers/FileTransferManager.swift @@ -732,19 +732,6 @@ public extension OTRXMPPRoomMessage { // MARK: - Extensions -fileprivate extension XMPPMessage { - /** XEP-0066: Out of Band Data jabber:x:oob */ - var outOfBandURL: URL? { - guard let oob = elements(forXmlns: "jabber:x:oob").first, - let urlElement = oob.elements(forName: "url").first, - let urlString = urlElement.stringValue else { - return nil - } - let url = URL(string: urlString) - return url - } -} - fileprivate struct HTTPServer { /// service jid for upload service let jid: XMPPJID diff --git a/ChatSecure/Classes/Controllers/MessageQueueHandler.swift b/ChatSecure/Classes/Controllers/MessageQueueHandler.swift index b9a468f9b..342213316 100644 --- a/ChatSecure/Classes/Controllers/MessageQueueHandler.swift +++ b/ChatSecure/Classes/Controllers/MessageQueueHandler.swift @@ -351,8 +351,9 @@ public class MessageQueueHandler:NSObject { //Ensure protocol is connected or if not and autologin then connnect if (accountProtocol.connectionStatus == .connected) { // Add the buddy to our roster - let jid = XMPPJID(string: buddy.username) - accountProtocol.xmppRoster.addUser(jid, withNickname:buddy.displayName) + if let jid = XMPPJID(string: buddy.username) { + accountProtocol.xmppRoster.addUser(jid, withNickname:buddy.displayName) + } completion(true, 0.0) } else if (account.autologin == true) { self.waitingForAccount(account.uniqueId, action: OutstandingActionInfo(action: addBuddyAction, timer: nil, completion: completion)) @@ -386,8 +387,9 @@ public class MessageQueueHandler:NSObject { if accountProtocol.connectionStatus == .connected, let jidStr = removeBuddyAction.buddyJid { // Add the buddy to our roster - let jid = XMPPJID(string: jidStr) - accountProtocol.xmppRoster.removeUser(jid) + if let jid = XMPPJID(string: jidStr) { + accountProtocol.xmppRoster.removeUser(jid) + } completion(true, 0.0) } else if (account.autologin == true) { self.waitingForAccount(account.uniqueId, action: OutstandingActionInfo(action: removeBuddyAction, timer: nil, completion: completion)) diff --git a/ChatSecure/Classes/Controllers/OTROMEMOSignalCoordinator.swift b/ChatSecure/Classes/Controllers/OTROMEMOSignalCoordinator.swift index 1c18dfbaa..6a9dca5c1 100644 --- a/ChatSecure/Classes/Controllers/OTROMEMOSignalCoordinator.swift +++ b/ChatSecure/Classes/Controllers/OTROMEMOSignalCoordinator.swift @@ -428,16 +428,17 @@ import SignalProtocolObjC } var relatedBuddyUsername: String? = fromJID.bare var innerMessage = message - if (message.isTrustedMessageCarbon(forMyJID: ourJID)) { + if message.isTrustedMessageCarbon(forMyJID: ourJID), + let forwarded = message.messageCarbonForwarded { //This came from another of our devices this is really going to be an outgoing message - innerMessage = message.messageCarbonForwarded() - if (message.isReceivedMessageCarbon()) { + innerMessage = forwarded + if (message.isReceivedMessageCarbon) { relatedBuddyUsername = innerMessage.from?.bare } else { relatedBuddyUsername = innerMessage.to?.bare - let outgoingMessage = OTROutgoingMessage() - outgoingMessage?.dateSent = Date() - databaseMessage = outgoingMessage! + let outgoingMessage = OTROutgoingMessage()! + outgoingMessage.dateSent = Date() + databaseMessage = outgoingMessage } } diff --git a/ChatSecure/Classes/Controllers/OTRXMPPChangePasswordManager.swift b/ChatSecure/Classes/Controllers/OTRXMPPChangePasswordManager.swift index dd83801d1..36eb479cf 100644 --- a/ChatSecure/Classes/Controllers/OTRXMPPChangePasswordManager.swift +++ b/ChatSecure/Classes/Controllers/OTRXMPPChangePasswordManager.swift @@ -11,12 +11,12 @@ import XMPPFramework open class OTRXMPPChangePasswordManager:NSObject { - fileprivate let completion:(_ success:Bool,_ error:NSError?) -> Void + fileprivate let completion:(_ success:Bool,_ error:Error?) -> Void fileprivate let registrationModule:XMPPRegistration fileprivate let password:String fileprivate let xmppStream:XMPPStream - public init(newPassword:String, xmppStream:XMPPStream, completion:@escaping (_ success:Bool,_ error:NSError?) -> Void) { + public init(newPassword:String, xmppStream:XMPPStream, completion:@escaping (_ success:Bool,_ error:Error?) -> Void) { self.registrationModule = XMPPRegistration() self.xmppStream = xmppStream self.registrationModule.activate(self.xmppStream) @@ -39,11 +39,11 @@ open class OTRXMPPChangePasswordManager:NSObject { extension OTRXMPPChangePasswordManager:XMPPRegistrationDelegate { - public func passwordChangeSuccessful(_ sender: XMPPRegistration!) { + public func passwordChangeSuccessful(_ sender: XMPPRegistration) { self.completion(true,nil) } - public func passwordChangeFailed(_ sender: XMPPRegistration!, withError error: Error!) { - self.completion(false,error as NSError) + public func passwordChangeFailed(_ sender: XMPPRegistration, withError error: Error?) { + self.completion(false,error) } } diff --git a/ChatSecure/Classes/Model/Yap Storage/OTRXMPPRoomMessage.swift b/ChatSecure/Classes/Model/Yap Storage/OTRXMPPRoomMessage.swift index c10fc2b52..fb2589c42 100644 --- a/ChatSecure/Classes/Model/Yap Storage/OTRXMPPRoomMessage.swift +++ b/ChatSecure/Classes/Model/Yap Storage/OTRXMPPRoomMessage.swift @@ -356,9 +356,9 @@ public extension OTRXMPPRoomMessage { /// Marks our sent messages as delivered when we receive a matching receipt @objc public static func handleDeliveryReceiptResponse(message: XMPPMessage, writeConnection: YapDatabaseConnection) { guard message.isGroupChatMessage, - message.hasReceiptResponse(), + message.hasReceiptResponse, !message.isErrorMessage, - let messageId = message.receiptResponseID() else { + let messageId = message.receiptResponseID else { return } writeConnection.asyncReadWrite { (transaction) in @@ -381,9 +381,9 @@ public extension OTRXMPPRoomMessage { /// Sends a response receipt when receiving a delivery receipt request @objc public static func handleDeliveryReceiptRequest(message: XMPPMessage, xmppStream:XMPPStream) { - guard message.hasReceiptRequest(), - !message.hasReceiptResponse(), - let response = message.generateReceiptResponse() else { + guard message.hasReceiptRequest, + !message.hasReceiptResponse, + let response = message.generateReceiptResponse else { return } xmppStream.send(response) diff --git a/ChatSecureTests/OTROMEMOIntegrationTest.swift b/ChatSecureTests/OTROMEMOIntegrationTest.swift index 812046cb9..acbf66832 100644 --- a/ChatSecureTests/OTROMEMOIntegrationTest.swift +++ b/ChatSecureTests/OTROMEMOIntegrationTest.swift @@ -32,9 +32,11 @@ class OTROMEMOIntegrationTest: XCTestCase { } /** Create two user accounts and save each other as buddies */ - func setupTwoAccounts(_ name:String) { - let aliceName = "\(name)-alice" - let bobName = "\(name)-bob" + func setupTwoAccounts(_ inName:String) { + let charactersToRemove = CharacterSet.alphanumerics.inverted + let name = inName.components(separatedBy: charactersToRemove).joined().lowercased() + let aliceName = "\(name).alice" + let bobName = "\(name).bob" self.aliceUser = self.setupUserWithName(aliceName,buddyName: bobName) self.aliceOmemoModule = OTROMEMOTestModule(omemoStorage: self.aliceUser!.signalOMEMOCoordinator, xmlNamespace: .conversationsLegacy, dispatchQueue: nil) self.aliceOmemoModule?.addDelegate(self.aliceUser!.signalOMEMOCoordinator, delegateQueue: self.aliceUser!.signalOMEMOCoordinator.workQueue) @@ -81,7 +83,7 @@ class OTROMEMOIntegrationTest: XCTestCase { */ func testDeviceSetup() { self.setupTwoAccounts(#function) - self.bobOmemoModule?.xmppStreamDidAuthenticate(nil) + self.bobOmemoModule?.xmppStreamDidAuthenticate(XMPPStream()) let buddy = self.bobUser!.buddy let connection = self.bobUser?.databaseManager.readOnlyDatabaseConnection connection?.read({ (transaction) in @@ -99,7 +101,7 @@ class OTROMEMOIntegrationTest: XCTestCase { */ func testFetchingBundleSetup() { self.setupTwoAccounts(#function) - self.bobOmemoModule?.xmppStreamDidAuthenticate(nil) + self.bobOmemoModule?.xmppStreamDidAuthenticate(XMPPStream()) let expectation = self.expectation(description: "Sending Message") let messageText = "This is message from Bob to Alice" let message = OTROutgoingMessage()! @@ -136,7 +138,7 @@ class OTROMEMOIntegrationTest: XCTestCase { func testRemoveDevice() { self.setupTwoAccounts(#function) - self.bobOmemoModule?.xmppStreamDidAuthenticate(nil) + self.bobOmemoModule?.xmppStreamDidAuthenticate(XMPPStream()) let expectation = self.expectation(description: "Remove Devices") let deviceNumber = NSNumber(value: 5 as Int32) let device = OTROMEMODevice(deviceId: deviceNumber, trustLevel: OMEMOTrustLevel.trustedTofu, parentKey: self.bobUser!.account.uniqueId, parentCollection: OTRAccount.collection, publicIdentityKeyData: nil, lastSeenDate: nil) diff --git a/ChatSecureTests/OTROMEMOTestModule.swift b/ChatSecureTests/OTROMEMOTestModule.swift index 09d64c43a..d505faecb 100644 --- a/ChatSecureTests/OTROMEMOTestModule.swift +++ b/ChatSecureTests/OTROMEMOTestModule.swift @@ -23,19 +23,19 @@ class OTROMEMOTestModule: OMEMOModule { override var xmppStream:XMPPStream { get { let stream = XMPPStream() - stream?.myJID = XMPPJID(string:self.thisUser.account.username) - return stream! + stream.myJID = XMPPJID(string:self.thisUser.account.username) + return stream } } /** Manually called after all the otherUser and thisUser are setup */ - override func xmppStreamDidAuthenticate(_ sender: XMPPStream!) { - + override func xmppStreamDidAuthenticate(_ sender: XMPPStream) { let bundle = otherUser?.bundle() XCTAssertNotNil(bundle) let device = bundle?.deviceId XCTAssertNotNil(device) - let otherJID = XMPPJID(string:otherUser?.username())! + let otherUserStr = otherUser!.username() + let otherJID = XMPPJID(string:otherUserStr)! let ourJID = XMPPJID(string:thisUser.account.username)! //After authentication fake receiving devices from other buddy self.omemoStorage.storeDeviceIds([NSNumber(value: device! as UInt32)], for: otherJID) @@ -50,7 +50,7 @@ class OTROMEMOTestModule: OMEMOModule { //Empty responses so not nil and have correct elementID. let response = XMPPIQ(type: "get", to: nil, elementID: elementId, child: nil) let outgoing = XMPPIQ(type: "get", to: nil, elementID: elementId, child: nil) - (multicastDelegate as AnyObject).omemo!(self, fetchedBundle: self.otherUser!.bundle(), from: jid, responseIq: response!, outgoingIq: outgoing!) + (multicastDelegate as AnyObject).omemo!(self, fetchedBundle: self.otherUser!.bundle(), from: jid, responseIq: response, outgoingIq: outgoing) } } @@ -59,15 +59,15 @@ class OTROMEMOTestModule: OMEMOModule { /** When we send key data we automtically route that data to the other user to decrypto*/ override func sendKeyData(_ keyData: [OMEMOKeyData], iv: Data, to toJID: XMPPJID, payload: Data?, elementId: String?) { - self.otherUser?.receiveKeyData(keyData, iv: iv, fromJID: XMPPJID(string:thisUser.account.username), senderDeviceId:(thisUser.signalOMEMOCoordinator.fetchMyBundle()?.deviceId)!, payload: payload, elementId: elementId) + self.otherUser?.receiveKeyData(keyData, iv: iv, fromJID: XMPPJID(string:thisUser.account.username)!, senderDeviceId:(thisUser.signalOMEMOCoordinator.fetchMyBundle()?.deviceId)!, payload: payload, elementId: elementId) //self.otherUser.signalOMEMOCoordinator.omemo(self, receivedKeyData: keyData, iv: iv, senderDeviceId: (thisUser.signalOMEMOCoordinator.fetchMyBundle()?.deviceId)!, fromJID: XMPPJID.jidWithString(thisUser.account.username), payload: payload, message: dummyMessage) } override func removeDeviceIds(_ deviceIds: [NSNumber], elementId: String?) { self.moduleQueue.async { let multicastDelegate = self.value(forKey: "multicastDelegate")! - let element = XMPPIQ(type: "resutl", to: self.xmppStream.myJID, elementID: elementId) - (multicastDelegate as AnyObject).omemo!(self, deviceListUpdate: [NSNumber](), from:self.xmppStream.myJID, incomingElement:element!) + let element = XMPPIQ(type: "result", to: self.xmppStream.myJID, elementID: elementId) + (multicastDelegate as AnyObject).omemo!(self, deviceListUpdate: [NSNumber](), from:self.xmppStream.myJID!, incomingElement:element) } } } @@ -79,7 +79,7 @@ extension OTROMEMOTestModule: OTROMEMOTestModuleProtocol { func receiveKeyData(_ keyData: [OMEMOKeyData], iv: Data, fromJID: XMPPJID, senderDeviceId:UInt32, payload: Data?, elementId: String?) { let dummyMessage = XMPPMessage(type: "chat", elementID: "1234") - self.thisUser.signalOMEMOCoordinator.omemo(self, receivedKeyData: keyData, iv: iv, senderDeviceId: senderDeviceId, from: fromJID, payload: payload, message: dummyMessage!) + self.thisUser.signalOMEMOCoordinator.omemo(self, receivedKeyData: keyData, iv: iv, senderDeviceId: senderDeviceId, from: fromJID, payload: payload, message: dummyMessage) } func bundle() -> OMEMOBundle { diff --git a/Submodules/XMPPFramework b/Submodules/XMPPFramework index 40cca81a2..65577a65c 160000 --- a/Submodules/XMPPFramework +++ b/Submodules/XMPPFramework @@ -1 +1 @@ -Subproject commit 40cca81a28af70165a7904781fe6d2d5e7a6b065 +Subproject commit 65577a65ca6ba67dfe34c8e43185fd7e7600c384