From 3d29480c29a86bb13c1ef4514a90760a3785a86a Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 10 Feb 2020 12:01:23 +1100 Subject: [PATCH 1/5] Don't include an auth token with encrypted file uploads Also refactor a bit --- .../ConversationView/Cells/OWSMessageCell.m | 2 +- .../ConversationView/ConversationViewItem.m | 2 +- .../src/Loki/API/LokiDotNetAPI.swift | 26 +++++++---- .../src/Loki/API/LokiStorageAPI.swift | 2 +- .../API/Public Chat/LokiPublicChatAPI.swift | 44 ++++++++++--------- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 9f557822a..5d008a6c3 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -302,7 +302,7 @@ NS_ASSUME_NONNULL_BEGIN publicChat = [LKDatabaseUtilities getPublicChatForThreadID:self.viewItem.interaction.uniqueThreadId transaction: transaction]; }]; if (publicChat != nil) { - BOOL isModerator = [LKPublicChatAPI isUserModerator:incomingMessage.authorId forGroup:publicChat.channel onServer:publicChat.server]; + BOOL isModerator = [LKPublicChatAPI isUserModerator:incomingMessage.authorId forChannel:publicChat.channel onServer:publicChat.server]; UIImage *moderatorIcon = [UIImage imageNamed:@"Crown"]; self.moderatorIconImageView.image = moderatorIcon; self.moderatorIconImageView.hidden = !isModerator; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 2a4387478..0dd09d203 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -1271,7 +1271,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) if (interationType == OWSInteractionType_IncomingMessage) { // Only allow deletion on incoming messages if the user has moderation permission - return [LKPublicChatAPI isUserModerator:self.userHexEncodedPublicKey forGroup:publicChat.channel onServer:publicChat.server]; + return [LKPublicChatAPI isUserModerator:self.userHexEncodedPublicKey forChannel:publicChat.channel onServer:publicChat.server]; } // Only allow deletion on outgoing messages if the user was the sender (i.e. it was not sent from another linked device) diff --git a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift index 6c2530c9d..7ba93fcb6 100644 --- a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift @@ -41,10 +41,11 @@ public class LokiDotNetAPI : NSObject { public static func uploadAttachment(_ attachment: TSAttachmentStream, with attachmentID: String, to server: String) -> Promise { let isEncryptionRequired = (server == LokiStorageAPI.server) return Promise() { seal in - getAuthToken(for: server).done(on: DispatchQueue.global()) { token in + func proceed(with token: String? = nil) { + // Get the attachment let data: Data guard let unencryptedAttachmentData = try? attachment.readDataFromFile() else { - print("[Loki] Couldn't read attachment data from disk.") + print("[Loki] Couldn't read attachment from disk.") return seal.reject(Error.generic) } // Encrypt the attachment if needed @@ -68,10 +69,12 @@ public class LokiDotNetAPI : NSObject { var request = AFHTTPRequestSerializer().multipartFormRequest(withMethod: "POST", urlString: url, parameters: parameters, constructingBodyWith: { formData in formData.appendPart(withFileData: data, name: "content", fileName: UUID().uuidString, mimeType: "application/binary") }, error: &error) - request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + if let token = token { + request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + } if let error = error { print("[Loki] Couldn't upload attachment due to error: \(error).") - throw error + return seal.reject(error) } // Send the request func parseResponse(_ response: Any) { @@ -117,9 +120,16 @@ public class LokiDotNetAPI : NSObject { }) task.resume() } - }.catch(on: DispatchQueue.global()) { error in - print("[Loki] Couldn't upload attachment.") - seal.reject(error) + } + if server == LokiStorageAPI.server { + proceed() // Uploads to the Loki File Server shouldn't include any personally identifiable information so don't include an auth token + } else { + getAuthToken(for: server).done(on: DispatchQueue.global()) { token in + proceed(with: token) + }.catch(on: DispatchQueue.global()) { error in + print("[Loki] Couldn't upload attachment due to error: \(error).") + seal.reject(error) + } } } } @@ -148,7 +158,7 @@ public class LokiDotNetAPI : NSObject { throw Error.parsingFailed } // Discard the "05" prefix if needed - if (serverPublicKey.count == 33) { + if serverPublicKey.count == 33 { let hexEncodedServerPublicKey = serverPublicKey.toHexString() serverPublicKey = Data.data(fromHex: hexEncodedServerPublicKey.substring(from: 2))! } diff --git a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift b/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift index 7efa46b65..85a429f91 100644 --- a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift @@ -168,7 +168,7 @@ public final class LokiStorageAPI : LokiDotNetAPI { }) task.resume() }.catch { error in - print("[Loki] Couldn't upload profile picture.") + print("[Loki] Couldn't upload profile picture due to error: \(error).") seal.reject(error) } } diff --git a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift index 7a0b1f3b1..fc97ab67c 100644 --- a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift +++ b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift @@ -12,13 +12,10 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { // MARK: Public Chat private static let channelInfoType = "net.patter-app.settings" private static let attachmentType = "net.app.core.oembed" - public static let avatarType = "network.loki.messenger.avatar" + public static let profilePictureType = "network.loki.messenger.avatar" @objc public static let publicChatMessageType = "network.loki.messenger.publicChat" - @objc public static let defaultChats: [LokiPublicChat] = { - var result: [LokiPublicChat] = [] - return result - }() + @objc public static let defaultChats: [LokiPublicChat] = [] // Currently unused // MARK: Convenience private static var userDisplayName: String { @@ -70,6 +67,11 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { } } + public static func clearCaches(for channel: UInt64, on server: String) { + removeLastMessageServerID(for: channel, on: server) + removeLastDeletionServerID(for: channel, on: server) + } + // MARK: Public API public static func getMessages(for channel: UInt64, on server: String) -> Promise<[LokiPublicChatMessage]> { var queryParameters = "include_annotations=1" @@ -97,23 +99,26 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { } var avatar: LokiPublicChatMessage.Avatar? = nil let displayName = user["name"] as? String ?? NSLocalizedString("Anonymous", comment: "") - if let userAnnotations = user["annotations"] as? [JSON], let avatarAnnotation = userAnnotations.first(where: { $0["type"] as? String == avatarType }), + if let userAnnotations = user["annotations"] as? [JSON], let avatarAnnotation = userAnnotations.first(where: { $0["type"] as? String == profilePictureType }), let avatarValue = avatarAnnotation["value"] as? JSON, let profileKeyString = avatarValue["profileKey"] as? String, let profileKey = Data(base64Encoded: profileKeyString), let url = avatarValue["url"] as? String { avatar = LokiPublicChatMessage.Avatar(profileKey: profileKey, url: url) } let lastMessageServerID = getLastMessageServerID(for: channel, on: server) if serverID > (lastMessageServerID ?? 0) { setLastMessageServerID(for: channel, on: server, to: serverID) } let quote: LokiPublicChatMessage.Quote? - if let quoteAsJSON = value["quote"] as? JSON, let quotedMessageTimestamp = quoteAsJSON["id"] as? UInt64, let quoteeHexEncodedPublicKey = quoteAsJSON["author"] as? String, let quotedMessageBody = quoteAsJSON["text"] as? String { + if let quoteAsJSON = value["quote"] as? JSON, let quotedMessageTimestamp = quoteAsJSON["id"] as? UInt64, let quoteeHexEncodedPublicKey = quoteAsJSON["author"] as? String, + let quotedMessageBody = quoteAsJSON["text"] as? String { let quotedMessageServerID = message["reply_to"] as? UInt64 - quote = LokiPublicChatMessage.Quote(quotedMessageTimestamp: quotedMessageTimestamp, quoteeHexEncodedPublicKey: quoteeHexEncodedPublicKey, quotedMessageBody: quotedMessageBody, quotedMessageServerID: quotedMessageServerID) + quote = LokiPublicChatMessage.Quote(quotedMessageTimestamp: quotedMessageTimestamp, quoteeHexEncodedPublicKey: quoteeHexEncodedPublicKey, quotedMessageBody: quotedMessageBody, + quotedMessageServerID: quotedMessageServerID) } else { quote = nil } let signature = LokiPublicChatMessage.Signature(data: Data(hex: hexEncodedSignatureData), version: signatureVersion) let attachmentsAsJSON = annotations.filter { $0["type"] as? String == attachmentType } let attachments: [LokiPublicChatMessage.Attachment] = attachmentsAsJSON.compactMap { attachmentAsJSON in - guard let value = attachmentAsJSON["value"] as? JSON, let kindAsString = value["lokiType"] as? String, let kind = LokiPublicChatMessage.Attachment.Kind(rawValue: kindAsString), let serverID = value["id"] as? UInt64, let contentType = value["contentType"] as? String, let size = value["size"] as? UInt, let url = value["url"] as? String else { return nil } + guard let value = attachmentAsJSON["value"] as? JSON, let kindAsString = value["lokiType"] as? String, let kind = LokiPublicChatMessage.Attachment.Kind(rawValue: kindAsString), + let serverID = value["id"] as? UInt64, let contentType = value["contentType"] as? String, let size = value["size"] as? UInt, let url = value["url"] as? String else { return nil } let fileName = value["fileName"] as? String ?? UUID().description let width = value["width"] as? UInt ?? 0 let height = value["height"] as? UInt ?? 0 @@ -127,9 +132,11 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { return nil } } - return LokiPublicChatMessage.Attachment(kind: kind, server: server, serverID: serverID, contentType: contentType, size: size, fileName: fileName, flags: flags, width: width, height: height, caption: caption, url: url, linkPreviewURL: linkPreviewURL, linkPreviewTitle: linkPreviewTitle) + return LokiPublicChatMessage.Attachment(kind: kind, server: server, serverID: serverID, contentType: contentType, size: size, fileName: fileName, flags: flags, + width: width, height: height, caption: caption, url: url, linkPreviewURL: linkPreviewURL, linkPreviewTitle: linkPreviewTitle) } - let result = LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, avatar: avatar, body: body, type: publicChatMessageType, timestamp: timestamp, quote: quote, attachments: attachments, signature: signature) + let result = LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, avatar: avatar, + body: body, type: publicChatMessageType, timestamp: timestamp, quote: quote, attachments: attachments, signature: signature) guard result.hasValidSignature() else { print("[Loki] Ignoring public chat message with invalid signature.") return nil @@ -260,7 +267,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { public static func getUserCount(for channel: UInt64, on server: String) -> Promise { return getAuthToken(for: server).then(on: DispatchQueue.global()) { token -> Promise in - let queryParameters = "count=2500" + let queryParameters = "count=200" let url = URL(string: "\(server)/channels/\(channel)/subscribers?\(queryParameters)")! let request = TSRequest(url: url) request.allHTTPHeaderFields = [ "Content-Type" : "application/json", "Authorization" : "Bearer \(token)" ] @@ -306,7 +313,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { } } - @objc (isUserModerator:forGroup:onServer:) + @objc(isUserModerator:forChannel:onServer:) public static func isUserModerator(_ hexEncodedPublicString: String, for channel: UInt64, on server: String) -> Bool { return moderators[server]?[channel]?.contains(hexEncodedPublicString) ?? false } @@ -322,13 +329,13 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { print("Couldn't update display name due to error: \(error).") throw error } - }.retryingIfNeeded(maxRetryCount: 3) + }.retryingIfNeeded(maxRetryCount: maxRetryCount) } public static func setProfilePictureURL(to url: String?, using profileKey: Data, on server: String) -> Promise { print("[Loki] Updating profile picture on server: \(server).") return getAuthToken(for: server).then(on: DispatchQueue.global()) { token -> Promise in - var annotation: JSON = [ "type" : avatarType ] + var annotation: JSON = [ "type" : profilePictureType ] if let url = url { annotation["value"] = [ "profileKey" : profileKey.base64EncodedString(), "url" : url ] } @@ -340,7 +347,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { print("[Loki] Couldn't update profile picture due to error: \(error).") throw error } - }.retryingIfNeeded(maxRetryCount: 3) + }.retryingIfNeeded(maxRetryCount: maxRetryCount) } public static func getInfo(for channel: UInt64, on server: String) -> Promise { @@ -366,11 +373,6 @@ public final class LokiPublicChatAPI : LokiDotNetAPI { return LokiFileServerProxy(for: server).perform(request).map { _ in } } - @objc public static func clearCaches(for channel: UInt64, on server: String) { - removeLastMessageServerID(for: channel, on: server) - removeLastDeletionServerID(for: channel, on: server) - } - // MARK: Public API (Obj-C) @objc(getMessagesForGroup:onServer:) public static func objc_getMessages(for group: UInt64, on server: String) -> AnyPromise { From dfd4340c79f9330546d3ed4101411cda0710ab0a Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 10 Feb 2020 14:36:52 +1100 Subject: [PATCH 2/5] Use file-dev in debug mode --- Signal/Signal-Info.plist | 7 +++++++ SignalServiceKit/src/Loki/API/LokiStorageAPI.swift | 8 ++++---- SignalShareExtension/Info.plist | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index bd0d2f1b4..342d37adb 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -76,6 +76,13 @@ NSIncludesSubdomains + file-dev.lokinet.org + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + imaginary.stream NSExceptionAllowsInsecureHTTPLoads diff --git a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift b/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift index 85a429f91..cd6bc20aa 100644 --- a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift @@ -4,11 +4,11 @@ import PromiseKit public final class LokiStorageAPI : LokiDotNetAPI { // MARK: Settings -// #if DEBUG -// private static let server = "http://file-dev.lokinet.org" -// #else + #if DEBUG + @objc public static let server = "http://file-dev.lokinet.org" + #else @objc public static let server = "https://file.getsession.org" -// #endif + #endif private static let deviceLinkType = "network.loki.messenger.devicemapping" private static let attachmentType = "net.app.core.oembed" diff --git a/SignalShareExtension/Info.plist b/SignalShareExtension/Info.plist index d683534dc..1b6e9e0bd 100644 --- a/SignalShareExtension/Info.plist +++ b/SignalShareExtension/Info.plist @@ -26,6 +26,13 @@ NSExceptionDomains + file-dev.lokinet.org + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + 149.56.148.124 NSExceptionAllowsInsecureHTTPLoads From d502aeaa80296742bd4e8c2387a6902c5671576a Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 10 Feb 2020 14:38:33 +1100 Subject: [PATCH 3/5] Use a dummy auth token instead of no token at all --- SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift index 7ba93fcb6..4dd5a968f 100644 --- a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift @@ -41,7 +41,7 @@ public class LokiDotNetAPI : NSObject { public static func uploadAttachment(_ attachment: TSAttachmentStream, with attachmentID: String, to server: String) -> Promise { let isEncryptionRequired = (server == LokiStorageAPI.server) return Promise() { seal in - func proceed(with token: String? = nil) { + func proceed(with token: String) { // Get the attachment let data: Data guard let unencryptedAttachmentData = try? attachment.readDataFromFile() else { @@ -69,9 +69,7 @@ public class LokiDotNetAPI : NSObject { var request = AFHTTPRequestSerializer().multipartFormRequest(withMethod: "POST", urlString: url, parameters: parameters, constructingBodyWith: { formData in formData.appendPart(withFileData: data, name: "content", fileName: UUID().uuidString, mimeType: "application/binary") }, error: &error) - if let token = token { - request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization") - } + request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization") if let error = error { print("[Loki] Couldn't upload attachment due to error: \(error).") return seal.reject(error) @@ -122,7 +120,7 @@ public class LokiDotNetAPI : NSObject { } } if server == LokiStorageAPI.server { - proceed() // Uploads to the Loki File Server shouldn't include any personally identifiable information so don't include an auth token + proceed(with: "loki") // Uploads to the Loki File Server shouldn't include any personally identifiable information so use a dummy auth token } else { getAuthToken(for: server).done(on: DispatchQueue.global()) { token in proceed(with: token) From cc40862740ea9589812508b80e4b815e847a37d6 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 10 Feb 2020 14:40:53 +1100 Subject: [PATCH 4/5] =?UTF-8?q?Rename=20LokiStorageAPI=20=E2=86=92=20LokiF?= =?UTF-8?q?ileServerAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Signal/src/AppDelegate.m | 4 ++-- .../src/Loki/View Controllers/DeviceLinkingModal.swift | 4 ++-- Signal/src/Loki/View Controllers/DeviceLinksVC.swift | 2 +- Signal/src/Loki/View Controllers/LandingVC.swift | 2 +- SignalMessaging/profiles/OWSProfileManager.m | 2 +- SignalServiceKit/src/Loki/API/LokiAPI.swift | 2 +- SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift | 8 ++++---- .../{LokiStorageAPI.swift => LokiFileServerAPI.swift} | 4 ++-- SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift | 2 +- SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift | 2 +- .../src/Loki/API/Public Chat/LokiPublicChatPoller.swift | 2 +- SignalServiceKit/src/Messages/OWSMessageManager.m | 2 +- SignalServiceKit/src/Messages/OWSMessageSender.m | 3 --- SignalServiceKit/src/Network/API/OWSUploadOperation.m | 9 ++++----- 14 files changed, 22 insertions(+), 26 deletions(-) rename SignalServiceKit/src/Loki/API/{LokiStorageAPI.swift => LokiFileServerAPI.swift} (99%) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 42944860a..531e1760e 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -777,7 +777,7 @@ static NSTimeInterval launchStartedAt; [self startLongPollerIfNeeded]; // Loki: Get device links - [LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; + [LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; if (![UIApplication sharedApplication].isRegisteredForRemoteNotifications) { OWSLogInfo(@"Retrying to register for remote notifications since user hasn't registered yet."); @@ -1448,7 +1448,7 @@ static NSTimeInterval launchStartedAt; [self startLongPollerIfNeeded]; // Loki: Get device links - [LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; + [LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; } } diff --git a/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift b/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift index d18aa4a6c..9ce16ef95 100644 --- a/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift +++ b/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift @@ -175,7 +175,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate { dismiss(animated: true, completion: nil) let master = DeviceLink.Device(hexEncodedPublicKey: deviceLink.master.hexEncodedPublicKey, signature: linkingAuthorizationMessage.masterSignature) let signedDeviceLink = DeviceLink(between: master, and: deviceLink.slave) - LokiStorageAPI.addDeviceLink(signedDeviceLink).done { + LokiFileServerAPI.addDeviceLink(signedDeviceLink).done { self.delegate?.handleDeviceLinkAuthorized(signedDeviceLink) // Intentionally capture self strongly }.catch { error in print("[Loki] Failed to add device link due to error: \(error).") @@ -191,7 +191,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate { subtitleLabel.text = NSLocalizedString("Your device has been linked successfully", comment: "") mnemonicLabel.isHidden = true buttonStackView.isHidden = true - LokiStorageAPI.addDeviceLink(deviceLink).catch { error in + LokiFileServerAPI.addDeviceLink(deviceLink).catch { error in print("[Loki] Failed to add device link due to error: \(error).") } Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in diff --git a/Signal/src/Loki/View Controllers/DeviceLinksVC.swift b/Signal/src/Loki/View Controllers/DeviceLinksVC.swift index c99cd79f8..3b54c62bc 100644 --- a/Signal/src/Loki/View Controllers/DeviceLinksVC.swift +++ b/Signal/src/Loki/View Controllers/DeviceLinksVC.swift @@ -152,7 +152,7 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView } private func removeDeviceLink(_ deviceLink: DeviceLink) { - LokiStorageAPI.removeDeviceLink(deviceLink).done { [weak self] in + LokiFileServerAPI.removeDeviceLink(deviceLink).done { [weak self] in let linkedDeviceHexEncodedPublicKey = deviceLink.other.hexEncodedPublicKey guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: linkedDeviceHexEncodedPublicKey)) else { return } let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)! diff --git a/Signal/src/Loki/View Controllers/LandingVC.swift b/Signal/src/Loki/View Controllers/LandingVC.swift index 04b772263..3369edc3c 100644 --- a/Signal/src/Loki/View Controllers/LandingVC.swift +++ b/Signal/src/Loki/View Controllers/LandingVC.swift @@ -157,7 +157,7 @@ final class LandingVC : UIViewController, LinkDeviceVCDelegate, DeviceLinkingMod TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey TSAccountManager.sharedInstance().didRegister() setUserInteractionEnabled(false) - let _ = LokiStorageAPI.getDeviceLinks(associatedWith: hexEncodedPublicKey).done(on: DispatchQueue.main) { [weak self] deviceLinks in + let _ = LokiFileServerAPI.getDeviceLinks(associatedWith: hexEncodedPublicKey).done(on: DispatchQueue.main) { [weak self] deviceLinks in guard let self = self else { return } defer { self.setUserInteractionEnabled(true) } guard deviceLinks.count < 2 else { diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index fb944741f..386247089 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -411,7 +411,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); NSData *encryptedAvatarData = [self encryptProfileData:avatarData profileKey:newProfileKey]; OWSAssertDebug(encryptedAvatarData.length > 0); - [[LKStorageAPI setProfilePicture:encryptedAvatarData] + [[LKFileServerAPI setProfilePicture:encryptedAvatarData] .thenOn(dispatch_get_main_queue(), ^(NSString *url) { [self.localUserProfile updateWithProfileKey:newProfileKey dbConnection:self.dbConnection completion:^{ successBlock(url); diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index 1a98fdc76..42533db9f 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -132,7 +132,7 @@ public final class LokiAPI : NSObject { if timeSinceLastUpdate > deviceLinkUpdateInterval { storage.dbReadConnection.read { transaction in let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey - LokiStorageAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done(on: DispatchQueue.global()) { _ in + LokiFileServerAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done(on: DispatchQueue.global()) { _ in getDestinations() lastDeviceLinkUpdate[hexEncodedPublicKey] = Date() }.catch(on: DispatchQueue.global()) { error in diff --git a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift index 4dd5a968f..c2846a275 100644 --- a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift @@ -1,6 +1,6 @@ import PromiseKit -/// Base class for `LokiStorageAPI` and `LokiPublicChatAPI`. +/// Base class for `LokiFileServerAPI` and `LokiPublicChatAPI`. public class LokiDotNetAPI : NSObject { // MARK: Convenience @@ -39,7 +39,7 @@ public class LokiDotNetAPI : NSObject { // MARK: Attachments (Public API) public static func uploadAttachment(_ attachment: TSAttachmentStream, with attachmentID: String, to server: String) -> Promise { - let isEncryptionRequired = (server == LokiStorageAPI.server) + let isEncryptionRequired = (server == LokiFileServerAPI.server) return Promise() { seal in func proceed(with token: String) { // Get the attachment @@ -88,7 +88,7 @@ public class LokiDotNetAPI : NSObject { attachment.save() seal.fulfill(()) } - let isProxyingRequired = (server == LokiStorageAPI.server) // Don't proxy open group requests for now + let isProxyingRequired = (server == LokiFileServerAPI.server) // Don't proxy open group requests for now if isProxyingRequired { let _ = LokiFileServerProxy(for: server).performLokiFileServerNSURLRequest(request as NSURLRequest).done { responseObject in parseResponse(responseObject) @@ -119,7 +119,7 @@ public class LokiDotNetAPI : NSObject { task.resume() } } - if server == LokiStorageAPI.server { + if server == LokiFileServerAPI.server { proceed(with: "loki") // Uploads to the Loki File Server shouldn't include any personally identifiable information so use a dummy auth token } else { getAuthToken(for: server).done(on: DispatchQueue.global()) { token in diff --git a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift similarity index 99% rename from SignalServiceKit/src/Loki/API/LokiStorageAPI.swift rename to SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift index cd6bc20aa..e19e880db 100644 --- a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift @@ -1,7 +1,7 @@ import PromiseKit -@objc(LKStorageAPI) -public final class LokiStorageAPI : LokiDotNetAPI { +@objc(LKFileServerAPI) +public final class LokiFileServerAPI : LokiDotNetAPI { // MARK: Settings #if DEBUG diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift index a705d6fb5..a4ce4c848 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift @@ -37,7 +37,7 @@ internal class LokiFileServerProxy : LokiHTTPClient { // MARK: Proxying override internal func perform(_ request: TSRequest, withCompletionQueue queue: DispatchQueue = DispatchQueue.main) -> LokiAPI.RawResponsePromise { - let isLokiFileServer = (server == LokiStorageAPI.server) + let isLokiFileServer = (server == LokiFileServerAPI.server) guard isLokiFileServer else { return super.perform(request, withCompletionQueue: queue) } // Don't proxy open group requests for now return performLokiFileServerNSURLRequest(request, withCompletionQueue: queue) } diff --git a/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift b/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift index 78df64c27..3ff398758 100644 --- a/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift @@ -13,7 +13,7 @@ public enum LokiRSSFeedProxy { } public static func fetchContent(for url: String) -> Promise { - let server = LokiStorageAPI.server + let server = LokiFileServerAPI.server let endpoints = [ "messenger-updates/feed" : "loki/v1/rss/messenger", "loki.network/feed" : "loki/v1/rss/loki" ] let endpoint = endpoints.first { url.lowercased().contains($0.key) }!.value let url = URL(string: server + "/" + endpoint)! diff --git a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift index c2054c4e7..466558199 100644 --- a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift +++ b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift @@ -192,7 +192,7 @@ public final class LokiPublicChatPoller : NSObject { if !hexEncodedPublicKeysToUpdate.isEmpty { let storage = OWSPrimaryStorage.shared() storage.dbReadConnection.read { transaction in - LokiStorageAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in + LokiFileServerAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in proceed() hexEncodedPublicKeysToUpdate.forEach { LokiAPI.lastDeviceLinkUpdate[$0] = Date() diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index a6da66994..4af814e77 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1249,7 +1249,7 @@ NS_ASSUME_NONNULL_BEGIN }]) { return; } - [LKStorageAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet *deviceLinks) { + [LKFileServerAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet *deviceLinks) { if ([deviceLinks contains:^BOOL(LKDeviceLink *deviceLink) { return [deviceLink.master.hexEncodedPublicKey isEqual:senderHexEncodedPublicKey] && [deviceLink.slave.hexEncodedPublicKey isEqual:userHexEncodedPublicKey]; }]) { diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index e170eee2d..2be40dd06 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -484,9 +484,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; }); } failure:^(NSError *error) { - OWSLogError(@"Could not obtain UD sender certificate: %@", error); - - // Proceed using non-UD message sends. dispatch_async([OWSDispatch sendingQueue], ^{ [self sendMessageToService:message senderCertificate:nil success:success failure:failure]; }); diff --git a/SignalServiceKit/src/Network/API/OWSUploadOperation.m b/SignalServiceKit/src/Network/API/OWSUploadOperation.m index 4db81cfe8..0077f00fc 100644 --- a/SignalServiceKit/src/Network/API/OWSUploadOperation.m +++ b/SignalServiceKit/src/Network/API/OWSUploadOperation.m @@ -65,14 +65,13 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f; - (void)run { __block TSAttachmentStream *attachmentStream; - [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { attachmentStream = [TSAttachmentStream fetchObjectWithUniqueID:self.attachmentId transaction:transaction]; }]; if (!attachmentStream) { - OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotLoadAttachment]); NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError(); - // Not finding local attachment is a terminal failure. + // Not finding a local attachment is a terminal failure error.isRetryable = NO; [self reportError:error]; return; @@ -90,9 +89,9 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f; [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { publicChat = [LKDatabaseUtilities getPublicChatForThreadID:self.threadID transaction:transaction]; }]; - NSString *server = (publicChat != nil) ? publicChat.server : LKStorageAPI.server; + NSString *server = (publicChat != nil) ? publicChat.server : LKFileServerAPI.server; - [[LKStorageAPI uploadAttachment:attachmentStream withID:self.attachmentId toServer:server] + [[LKFileServerAPI uploadAttachment:attachmentStream withID:self.attachmentId toServer:server] .thenOn(dispatch_get_main_queue(), ^() { [self reportSuccess]; }) From 58f4181b59c938e9f82e463197fb71ec43004037 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 10 Feb 2020 14:43:45 +1100 Subject: [PATCH 5/5] Update Pods --- Pods | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pods b/Pods index 9aa5aae61..edac100a2 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 9aa5aae61fd7223a84239fc521184396aa3bedb7 +Subproject commit edac100a2bda084edbba3291b080615aa26e5948