From e72c4a405f9c098b128104403835f2d5aa6de5d8 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 13:43:05 +1000 Subject: [PATCH 01/17] Fix typo --- Signal/src/Loki/View Controllers/LandingVC.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/src/Loki/View Controllers/LandingVC.swift b/Signal/src/Loki/View Controllers/LandingVC.swift index 51acccbac..6a23b6f11 100644 --- a/Signal/src/Loki/View Controllers/LandingVC.swift +++ b/Signal/src/Loki/View Controllers/LandingVC.swift @@ -85,7 +85,7 @@ final class LandingVC : BaseVC, LinkDeviceVCDelegate, DeviceLinkingModalDelegate topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor, multiplier: 1).isActive = true // Show device unlinked alert if needed if UserDefaults.standard[.wasUnlinked] { - let alert = UIAlertController(title: "Device Unlinked", message: NSLocalizedString("vc_landing_device_unlinked_dialog_title", comment: ""), preferredStyle: .alert) + let alert = UIAlertController(title: "Device Unlinked", message: NSLocalizedString("vc_landing_device_unlinked_modal_title", comment: ""), preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), accessibilityIdentifier: nil, style: .default, handler: nil)) present(alert, animated: true, completion: nil) UserDefaults.removeAll() From 6286569245f4ff6919403a6b4ddcd24e76db1659 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 13:56:11 +1000 Subject: [PATCH 02/17] Fix typo --- Signal/src/Loki/View Controllers/PNModeVC.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/src/Loki/View Controllers/PNModeVC.swift b/Signal/src/Loki/View Controllers/PNModeVC.swift index f2293b421..f09be912d 100644 --- a/Signal/src/Loki/View Controllers/PNModeVC.swift +++ b/Signal/src/Loki/View Controllers/PNModeVC.swift @@ -83,7 +83,7 @@ final class PNModeVC : BaseVC, OptionViewDelegate { @objc private func register() { guard selectedOptionView != nil else { - let title = NSLocalizedString("vc_pn_mode_no_option_picked_dialog_title", comment: "") + let title = NSLocalizedString("vc_pn_mode_no_option_picked_modal_title", comment: "") let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil)) return present(alert, animated: true, completion: nil) From 2d48b69a00a3142a039f48b9e0ff6ee701eae4bb Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 14:27:08 +1000 Subject: [PATCH 03/17] Add debug log --- SignalServiceKit/src/Loki/API/DotNetAPI.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/DotNetAPI.swift b/SignalServiceKit/src/Loki/API/DotNetAPI.swift index cda061895..f8f5879df 100644 --- a/SignalServiceKit/src/Loki/API/DotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/DotNetAPI.swift @@ -142,7 +142,9 @@ public class DotNetAPI : NSObject { let parameters: JSON = [ "type" : attachmentType, "Content-Type" : "application/binary" ] var error: NSError? 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") + let uuid = UUID().uuidString + print("[Loki] File UUID: \(uuid)") + formData.appendPart(withFileData: data, name: "content", fileName: uuid, mimeType: "application/binary") }, error: &error) request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization") if let error = error { From 329b11509681f58908922790c5184670add0a3d9 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 15:24:26 +1000 Subject: [PATCH 04/17] Add debug log --- SignalServiceKit/src/Loki/API/DotNetAPI.swift | 1 + .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/SignalServiceKit/src/Loki/API/DotNetAPI.swift b/SignalServiceKit/src/Loki/API/DotNetAPI.swift index f8f5879df..a75923c3c 100644 --- a/SignalServiceKit/src/Loki/API/DotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/DotNetAPI.swift @@ -134,6 +134,7 @@ public class DotNetAPI : NSObject { data = unencryptedAttachmentData } // Check the file size if needed + print("[Loki] File size: \(data.count)") if data.count > FileServerAPI.maxFileSize { return seal.reject(DotNetAPIError.maxFileSizeExceeded) } diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index 523eca12d..a9f7db009 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -290,6 +290,10 @@ public enum OnionRequestAPI { let url = "\(guardSnode.address):\(guardSnode.port)/onion_req" let finalEncryptionResult = intermediate.finalEncryptionResult let onion = finalEncryptionResult.ciphertext + if case Destination.server = destination, onion.count > FileServerAPI.maxFileSize { + print("[Loki] Onion request size: ~\(onion.count)") + throw DotNetAPI.DotNetAPIError.maxFileSizeExceeded + } let parameters: JSON = [ "ciphertext" : onion.base64EncodedString(), "ephemeral_key" : finalEncryptionResult.ephemeralPublicKey.toHexString() From d95b63895ea1323e727d74be2fcf717244a10421 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 15:50:14 +1000 Subject: [PATCH 05/17] Update file size limit for onion requests --- SignalServiceKit/src/Loki/API/DotNetAPI.swift | 2 +- SignalServiceKit/src/Loki/API/FileServerAPI.swift | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/DotNetAPI.swift b/SignalServiceKit/src/Loki/API/DotNetAPI.swift index a75923c3c..4671a7b05 100644 --- a/SignalServiceKit/src/Loki/API/DotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/DotNetAPI.swift @@ -135,7 +135,7 @@ public class DotNetAPI : NSObject { } // Check the file size if needed print("[Loki] File size: \(data.count)") - if data.count > FileServerAPI.maxFileSize { + if Double(data.count) > Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier { return seal.reject(DotNetAPIError.maxFileSizeExceeded) } // Create the request diff --git a/SignalServiceKit/src/Loki/API/FileServerAPI.swift b/SignalServiceKit/src/Loki/API/FileServerAPI.swift index 288ee5712..73a378acd 100644 --- a/SignalServiceKit/src/Loki/API/FileServerAPI.swift +++ b/SignalServiceKit/src/Loki/API/FileServerAPI.swift @@ -7,11 +7,17 @@ public final class FileServerAPI : DotNetAPI { private static let attachmentType = "net.app.core.oembed" private static let deviceLinkType = "network.loki.messenger.devicemapping" - internal static let fileServerPublicKey = "62509D59BDEEC404DD0D489C1E15BA8F94FD3D619B01C1BF48A9922BFCB7311C" + internal static let fileServerPublicKey = "2662315C4E728FDBDEC61F69ECA2316BFF267AA8931197907A1C944C7C4E667A" public static let maxFileSize = 10_000_000 // 10 MB + /// The file server has a file size limit of `maxFileSize`, which the Service Nodes try to enforce as well. However, the limit applied by the Service Nodes + /// is on the **HTTP request** and not the file size. Because of onion request encryption, a file that's about 4 MB will result in a request that's about 15 MB. + /// On average the multiplier appears to be about 3.4, so when checking whether the file will exceed the file size limit when uploading a file we just divide + /// the size of the file by this number. The alternative would be to actually check the size of the HTTP request but that's only possible after proof of work + /// has been calculated and the onion request encryption has happened, which takes several seconds. + public static let fileSizeORMultiplier = 3.4 - @objc public static let server = "https://file.getsession.org" + @objc public static let server = "https://file-dev.getsession.org" // MARK: Storage override internal class var authTokenCollection: String { return "LokiStorageAuthTokenCollection" } @@ -153,7 +159,7 @@ public final class FileServerAPI : DotNetAPI { } public static func uploadProfilePicture(_ profilePicture: Data) -> Promise { - guard profilePicture.count < maxFileSize else { return Promise(error: DotNetAPIError.maxFileSizeExceeded) } + guard Double(profilePicture.count) < Double(maxFileSize) / fileSizeORMultiplier else { return Promise(error: DotNetAPIError.maxFileSizeExceeded) } let url = "\(server)/files" let parameters: JSON = [ "type" : attachmentType, "Content-Type" : "application/binary" ] var error: NSError? From d9fae413463434f0612e5061ee015de09bb0e983 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 16:08:44 +1000 Subject: [PATCH 06/17] Compress images as needed --- .../src/Messages/Attachments/OWSMediaUtils.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SignalServiceKit/src/Messages/Attachments/OWSMediaUtils.swift b/SignalServiceKit/src/Messages/Attachments/OWSMediaUtils.swift index 3ec42e904..c74223e9a 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSMediaUtils.swift +++ b/SignalServiceKit/src/Messages/Attachments/OWSMediaUtils.swift @@ -115,15 +115,15 @@ public enum OWSMediaError: Error { * https://github.com/signalapp/Signal-Android/blob/master/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java */ @objc - public static let kMaxFileSizeAnimatedImage = UInt(25 * 1024 * 1024) + public static var kMaxFileSizeAnimatedImage: UInt { UInt(Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier) } @objc - public static let kMaxFileSizeImage = UInt(6 * 1024 * 1024) + public static var kMaxFileSizeImage: UInt { UInt(Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier) } @objc - public static let kMaxFileSizeVideo = UInt(100 * 1024 * 1024) + public static var kMaxFileSizeVideo: UInt { UInt(Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier) } @objc - public static let kMaxFileSizeAudio = UInt(100 * 1024 * 1024) + public static var kMaxFileSizeAudio: UInt { UInt(Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier) } @objc - public static let kMaxFileSizeGeneric = UInt(100 * 1024 * 1024) + public static var kMaxFileSizeGeneric: UInt { UInt(Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier) } @objc public static let kMaxVideoDimensions: CGFloat = 3 * 1024 From 87024b7eb9a5849cb87bd1db983b3edd564afe28 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 16:27:09 +1000 Subject: [PATCH 07/17] Undo debug commit --- SignalServiceKit/src/Loki/API/FileServerAPI.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/FileServerAPI.swift b/SignalServiceKit/src/Loki/API/FileServerAPI.swift index 73a378acd..901ca22cb 100644 --- a/SignalServiceKit/src/Loki/API/FileServerAPI.swift +++ b/SignalServiceKit/src/Loki/API/FileServerAPI.swift @@ -7,7 +7,7 @@ public final class FileServerAPI : DotNetAPI { private static let attachmentType = "net.app.core.oembed" private static let deviceLinkType = "network.loki.messenger.devicemapping" - internal static let fileServerPublicKey = "2662315C4E728FDBDEC61F69ECA2316BFF267AA8931197907A1C944C7C4E667A" + internal static let fileServerPublicKey = "62509D59BDEEC404DD0D489C1E15BA8F94FD3D619B01C1BF48A9922BFCB7311C" public static let maxFileSize = 10_000_000 // 10 MB /// The file server has a file size limit of `maxFileSize`, which the Service Nodes try to enforce as well. However, the limit applied by the Service Nodes @@ -17,7 +17,7 @@ public final class FileServerAPI : DotNetAPI { /// has been calculated and the onion request encryption has happened, which takes several seconds. public static let fileSizeORMultiplier = 3.4 - @objc public static let server = "https://file-dev.getsession.org" + @objc public static let server = "https://file.getsession.org" // MARK: Storage override internal class var authTokenCollection: String { return "LokiStorageAuthTokenCollection" } From 9dd385451b2217ec1e7a8e64660cd48fff6a768c Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 16:28:47 +1000 Subject: [PATCH 08/17] Clean --- .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index a9f7db009..f4d68b75c 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -290,7 +290,7 @@ public enum OnionRequestAPI { let url = "\(guardSnode.address):\(guardSnode.port)/onion_req" let finalEncryptionResult = intermediate.finalEncryptionResult let onion = finalEncryptionResult.ciphertext - if case Destination.server = destination, onion.count > FileServerAPI.maxFileSize { + if case Destination.server = destination { print("[Loki] Onion request size: ~\(onion.count)") throw DotNetAPI.DotNetAPIError.maxFileSizeExceeded } From 13a3eb0d64f4e0c4104e923b56144642a1c581fe Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 16:29:43 +1000 Subject: [PATCH 09/17] Debug --- .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index f4d68b75c..b004203a0 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -292,7 +292,6 @@ public enum OnionRequestAPI { let onion = finalEncryptionResult.ciphertext if case Destination.server = destination { print("[Loki] Onion request size: ~\(onion.count)") - throw DotNetAPI.DotNetAPIError.maxFileSizeExceeded } let parameters: JSON = [ "ciphertext" : onion.base64EncodedString(), From 8ca36f42f39de9644952c08ea2c6cfdf59527c71 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 16:46:00 +1000 Subject: [PATCH 10/17] Prevent crash --- .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index b004203a0..92aaa1fcd 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -300,7 +300,7 @@ public enum OnionRequestAPI { let destinationSymmetricKey = intermediate.destinationSymmetricKey HTTP.execute(.post, url, parameters: parameters).done2 { rawResponse in guard let json = rawResponse as? JSON, let base64EncodedIVAndCiphertext = json["result"] as? String, - let ivAndCiphertext = Data(base64Encoded: base64EncodedIVAndCiphertext) else { return seal.reject(HTTP.Error.invalidJSON) } + let ivAndCiphertext = Data(base64Encoded: base64EncodedIVAndCiphertext), ivAndCiphertext.count > ivSize else { return seal.reject(HTTP.Error.invalidJSON) } let iv = ivAndCiphertext[0.. Date: Fri, 31 Jul 2020 16:46:29 +1000 Subject: [PATCH 11/17] Update build number --- Signal.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 267c7ba11..3e2dc81e9 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4081,7 +4081,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4143,7 +4143,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4197,7 +4197,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4267,7 +4267,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4329,7 +4329,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4392,7 +4392,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4593,7 +4593,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4661,7 +4661,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 92; + CURRENT_PROJECT_VERSION = 93; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", From 5f983928037c4dda8fce1ad8e16187df4e4e2a16 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 31 Jul 2020 17:03:41 +1000 Subject: [PATCH 12/17] Clean --- .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index 92aaa1fcd..c92131ac8 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -300,7 +300,7 @@ public enum OnionRequestAPI { let destinationSymmetricKey = intermediate.destinationSymmetricKey HTTP.execute(.post, url, parameters: parameters).done2 { rawResponse in guard let json = rawResponse as? JSON, let base64EncodedIVAndCiphertext = json["result"] as? String, - let ivAndCiphertext = Data(base64Encoded: base64EncodedIVAndCiphertext), ivAndCiphertext.count > ivSize else { return seal.reject(HTTP.Error.invalidJSON) } + let ivAndCiphertext = Data(base64Encoded: base64EncodedIVAndCiphertext), ivAndCiphertext.count >= ivSize else { return seal.reject(HTTP.Error.invalidJSON) } let iv = ivAndCiphertext[0.. Date: Mon, 3 Aug 2020 09:10:24 +1000 Subject: [PATCH 13/17] Unregister the user from APNs when they clear their account --- Signal/src/AppDelegate.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 4c4767cea..d00367ab4 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -936,6 +936,13 @@ static NSTimeInterval launchStartedAt; - (void)handleDataNukeRequested:(NSNotification *)notification { + NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults; + BOOL isUsingFullAPNs = [userDefaults boolForKey:@"isUsingFullAPNs"]; + NSString *hexEncodedDeviceToken = [userDefaults stringForKey:@"deviceToken"]; + if (isUsingFullAPNs && hexEncodedDeviceToken != nil) { + NSData *deviceToken = [NSData dataFromHexString:hexEncodedDeviceToken]; + [[LKPushNotificationManager registerWithToken:deviceToken isForcedUpdate:YES] retainUntilComplete]; // This actually unregisters the user; we should rename the function + } [ThreadUtil deleteAllContent]; [SSKEnvironment.shared.messageSenderJobQueue clearAllJobs]; [SSKEnvironment.shared.identityManager clearIdentityKey]; From f28aad9ac2bea1194c35c50e16c17cc159f7f080 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 3 Aug 2020 09:11:50 +1000 Subject: [PATCH 14/17] Fix copy --- SignalServiceKit/src/Loki/Crypto/Mnemonic.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SignalServiceKit/src/Loki/Crypto/Mnemonic.swift b/SignalServiceKit/src/Loki/Crypto/Mnemonic.swift index ae2b5fc35..d7b01aa7c 100644 --- a/SignalServiceKit/src/Loki/Crypto/Mnemonic.swift +++ b/SignalServiceKit/src/Loki/Crypto/Mnemonic.swift @@ -49,11 +49,11 @@ public enum Mnemonic { public var errorDescription: String? { switch self { - case .generic: return NSLocalizedString("Something went wrong. Please check your seed and try again.", comment: "") - case .inputTooShort: return NSLocalizedString("Looks like you didn't enter enough words. Please check your seed and try again.", comment: "") - case .missingLastWord: return NSLocalizedString("You seem to be missing the last word of your seed. Please check what you entered and try again.", comment: "") - case .invalidWord: return NSLocalizedString("There appears to be an invalid word in your seed. Please check what you entered and try again.", comment: "") - case .verificationFailed: return NSLocalizedString("Your seed couldn't be verified. Please check what you entered and try again.", comment: "") + case .generic: return NSLocalizedString("Something went wrong. Please check your recovery phrase and try again.", comment: "") + case .inputTooShort: return NSLocalizedString("Looks like you didn't enter enough words. Please check your recovery phrase and try again.", comment: "") + case .missingLastWord: return NSLocalizedString("You seem to be missing the last word of your recovery phrase. Please check what you entered and try again.", comment: "") + case .invalidWord: return NSLocalizedString("There appears to be an invalid word in your recovery phrase. Please check what you entered and try again.", comment: "") + case .verificationFailed: return NSLocalizedString("Your recovery phrase couldn't be verified. Please check what you entered and try again.", comment: "") } } } From 37c1bb9a4ba98c414c78877e5493d6d238a6c721 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 3 Aug 2020 09:53:27 +1000 Subject: [PATCH 15/17] Avoid race condition --- .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index c92131ac8..6c69578e1 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -284,7 +284,7 @@ public enum OnionRequestAPI { internal static func sendOnionRequest(with payload: JSON, to destination: Destination, isJSONRequired: Bool = true) -> Promise { let (promise, seal) = Promise.pending() var guardSnode: Snode! - DispatchQueue.global(qos: .userInitiated).async { + SnodeAPI.workQueue.async { // Avoid race conditions on `guardSnodes` and `paths` buildOnion(around: payload, targetedAt: destination).done2 { intermediate in guardSnode = intermediate.guardSnode let url = "\(guardSnode.address):\(guardSnode.port)/onion_req" From b5f1f481afe4d2f7c122b9d2c61cc6e886bed172 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 3 Aug 2020 09:54:05 +1000 Subject: [PATCH 16/17] Avoid race condition --- Signal/src/Loki/Utilities/IP2Country.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Signal/src/Loki/Utilities/IP2Country.swift b/Signal/src/Loki/Utilities/IP2Country.swift index 2b29cd7d0..85e4353b0 100644 --- a/Signal/src/Loki/Utilities/IP2Country.swift +++ b/Signal/src/Loki/Utilities/IP2Country.swift @@ -1,10 +1,12 @@ import SwiftCSV final class IP2Country { + var countryNamesCache: [String:String] = [:] private lazy var ipv4Table = try! CSV(name: "GeoLite2-Country-Blocks-IPv4", extension: "csv", bundle: .main, delimiter: ",", encoding: .utf8, loadColumns: true)! private lazy var countryNamesTable = try! CSV(name: "GeoLite2-Country-Locations-English", extension: "csv", bundle: .main, delimiter: ",", encoding: .utf8, loadColumns: true)! - var countryNamesCache: [String:String] = [:] + + private static let workQueue = DispatchQueue(label: "IP2Country.workQueue", qos: .utility) // It's important that this is a serial queue static var isInitialized = false @@ -44,7 +46,7 @@ final class IP2Country { } @objc func populateCacheIfNeededAsync() { - DispatchQueue.global(qos: .utility).async { + IP2Country.workQueue.async { let _ = self.populateCacheIfNeeded() } } From 0bdffd60b7ae7e40dbee3485f57c7f9a2772d5b1 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 3 Aug 2020 09:58:01 +1000 Subject: [PATCH 17/17] Fix bad estimate --- SignalServiceKit/src/Loki/API/FileServerAPI.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/FileServerAPI.swift b/SignalServiceKit/src/Loki/API/FileServerAPI.swift index 901ca22cb..b0bec9313 100644 --- a/SignalServiceKit/src/Loki/API/FileServerAPI.swift +++ b/SignalServiceKit/src/Loki/API/FileServerAPI.swift @@ -11,11 +11,11 @@ public final class FileServerAPI : DotNetAPI { public static let maxFileSize = 10_000_000 // 10 MB /// The file server has a file size limit of `maxFileSize`, which the Service Nodes try to enforce as well. However, the limit applied by the Service Nodes - /// is on the **HTTP request** and not the file size. Because of onion request encryption, a file that's about 4 MB will result in a request that's about 15 MB. - /// On average the multiplier appears to be about 3.4, so when checking whether the file will exceed the file size limit when uploading a file we just divide + /// is on the **HTTP request** and not the file size. Because of onion request encryption, a file that's about 4 MB will result in a request that's about 18 MB. + /// On average the multiplier appears to be about 4.4, so when checking whether the file will exceed the file size limit when uploading a file we just divide /// the size of the file by this number. The alternative would be to actually check the size of the HTTP request but that's only possible after proof of work /// has been calculated and the onion request encryption has happened, which takes several seconds. - public static let fileSizeORMultiplier = 3.4 + public static let fileSizeORMultiplier = 4.4 @objc public static let server = "https://file.getsession.org"