diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 770065d8f..2e8aca0a7 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -562,6 +562,7 @@ B821F2F62272CCD9002C88C0 /* english.txt in Resources */ = {isa = PBXBuildFile; fileRef = B821F2F22272CCD9002C88C0 /* english.txt */; }; B821F2F82272CED3002C88C0 /* OnboardingAccountDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F72272CED3002C88C0 /* OnboardingAccountDetailsViewController.swift */; }; B821F2FA2272CEEE002C88C0 /* OnboardingPublicKeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F92272CEEE002C88C0 /* OnboardingPublicKeyViewController.swift */; }; + B8C915232277FDC30028E4A9 /* ECKeyPair.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C915222277FDC30028E4A9 /* ECKeyPair.swift */; }; B90418E6183E9DD40038554A /* DateUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = B90418E5183E9DD40038554A /* DateUtil.m */; }; B9EB5ABD1884C002007CBB57 /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9EB5ABC1884C002007CBB57 /* MessageUI.framework */; }; BFF3FB9730634F37D25903F4 /* Pods_Signal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D17BB5C25D615AB49813100C /* Pods_Signal.framework */; }; @@ -1351,6 +1352,7 @@ B821F2F22272CCD9002C88C0 /* english.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = english.txt; path = mnemonic/english.txt; sourceTree = ""; }; B821F2F72272CED3002C88C0 /* OnboardingAccountDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingAccountDetailsViewController.swift; sourceTree = ""; }; B821F2F92272CEEE002C88C0 /* OnboardingPublicKeyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingPublicKeyViewController.swift; sourceTree = ""; }; + B8C915222277FDC30028E4A9 /* ECKeyPair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ECKeyPair.swift; path = ../../../SignalServiceKit/src/Util/ECKeyPair.swift; sourceTree = ""; }; B90418E4183E9DD40038554A /* DateUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateUtil.h; sourceTree = ""; }; B90418E5183E9DD40038554A /* DateUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DateUtil.m; sourceTree = ""; }; B97940251832BD2400BD66CB /* UIUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIUtil.h; sourceTree = ""; }; @@ -2429,6 +2431,7 @@ B90418E4183E9DD40038554A /* DateUtil.h */, 3496956121A301A100DCFE74 /* Backup */, B90418E5183E9DD40038554A /* DateUtil.m */, + B8C915222277FDC30028E4A9 /* ECKeyPair.swift */, 34B0796C1FCF46B000E248C2 /* MainAppContext.h */, 34B0796B1FCF46B000E248C2 /* MainAppContext.m */, B821F2EC2272CBC0002C88C0 /* Mnemonic.swift */, @@ -3693,6 +3696,7 @@ 3448E16022134C89004B052E /* OnboardingSplashViewController.swift in Sources */, 34B6A903218B3F63007C4606 /* TypingIndicatorView.swift in Sources */, 458E38371D668EBF0094BD24 /* OWSDeviceProvisioningURLParser.m in Sources */, + B8C915232277FDC30028E4A9 /* ECKeyPair.swift in Sources */, 34B6A905218B4C91007C4606 /* TypingIndicatorInteraction.swift in Sources */, 4517642B1DE939FD00EDB8B9 /* ContactCell.swift in Sources */, 34EA69402194933900702471 /* MediaDownloadView.swift in Sources */, diff --git a/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift index 603820538..09ae89e0d 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift @@ -1,5 +1,3 @@ -import UIKit -import PromiseKit final class OnboardingAccountDetailsViewController : OnboardingBaseViewController { @@ -41,7 +39,7 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle let passwordLabel = createExplanationLabel(text: NSLocalizedString("Type an optional password for added security", comment: "")) passwordLabel.accessibilityIdentifier = "onboarding.accountDetailsStep.passwordLabel" let bottomSpacer = UIView.vStretchingSpacer() - let nextButton = createButton(title: NSLocalizedString("Next", comment: ""), selector: #selector(updateProfile)) + let nextButton = createButton(title: NSLocalizedString("Next", comment: ""), selector: #selector(handleNextButtonPressed)) nextButton.accessibilityIdentifier = "onboarding.accountDetailsStep.nextButton" let stackView = UIStackView(arrangedSubviews: [ titleLabel, @@ -72,16 +70,12 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle displayNameTextField.becomeFirstResponder() } - @objc private func updateProfile() { + @objc private func handleNextButtonPressed() { if let normalizedName = normalizedName { guard !OWSProfileManager.shared().isProfileNameTooLong(normalizedName) else { return OWSAlerts.showErrorAlert(message: NSLocalizedString("PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG", comment: "Error message shown when user tries to update profile with a profile name that is too long")) } } - goToSeedStep() - } - - @objc private func goToSeedStep() { onboardingController.pushPublicKeyViewController(from: self, userName: normalizedName) } } diff --git a/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift index 73a80f3df..95facc407 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift @@ -1,5 +1,3 @@ -import UIKit -import PromiseKit final class OnboardingPublicKeyViewController : OnboardingBaseViewController { private var keyPair: ECKeyPair! { didSet { updateMnemonic() } } @@ -32,6 +30,17 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController { super.loadView() setUpViewHierarchy() updateKeyPair() + // Test + // ================ + let _ = ServiceNode.retrieveAllMessages().done { result in + print(result.task.originalRequest!) + print(result.task.response!) + } + let _ = ServiceNode.sendTestMessage().done { result in + print(result.task.originalRequest!) + print(result.task.response!) + } + // ================ } private func setUpViewHierarchy() { @@ -69,12 +78,12 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController { private func updateKeyPair() { let identityManager = OWSIdentityManager.shared() - identityManager.generateNewIdentityKey() // Generates and stores a new key pair + identityManager.generateNewIdentityKey() // Generate and store a new identity key pair keyPair = identityManager.identityKeyPair()! } private func updateMnemonic() { - hexEncodedPublicKey = keyPair.publicKey.map { String(format: "%02hhx", $0) }.joined() + hexEncodedPublicKey = keyPair.hexEncodedPublicKey mnemonic = Mnemonic.encode(hexEncodedString: hexEncodedPublicKey) } diff --git a/SignalServiceKit/src/Network/API/ServiceNode.swift b/SignalServiceKit/src/Network/API/ServiceNode.swift new file mode 100644 index 000000000..5e1355f36 --- /dev/null +++ b/SignalServiceKit/src/Network/API/ServiceNode.swift @@ -0,0 +1,44 @@ +import PromiseKit + +public struct ServiceNode { + + private static var snodeURL: String { return textSecureServerURL } + private static var port: String { return "8080" } + private static var apiVersion: String { return "v1" } + + // MARK: Types + private enum Method : String { + case retrieveAllMessages = "retrieve" + case send = "store" + } + + public typealias Response = TSNetworkManager.NetworkManagerResult + + // MARK: Lifecycle + private init() { } + + // MARK: API + private static func invoke(_ method: Method, parameters: [String:String] = [:]) -> Promise { + let url = URL(string: "\(snodeURL):\(port)/\(apiVersion)/storage_rpc")! + var parameters = parameters + parameters["pubKey"] = "050371e72be8dd42ff77105e474a3ac26a503d017fb4562409c639eaf5965f5b31" // OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey + let request = TSRequest(url: url, method: "POST", parameters: [ "method" : method.rawValue, "params" : parameters ]) + return TSNetworkManager.shared().makePromise(request: request) + } + + public static func sendTestMessage() -> Promise { + let ttl = String(4 * 24 * 60 * 60 * 1000) + let parameters = [ + "ttl" : ttl, + "nonce" : "AAAAAAAA5rs=", // TODO: Proof of work + "timestamp" : "1556259498201", // TODO: Message send time + "data" : "CAESvgMKA1BVVBIPL2FwaS92MS9tZXNzYWdlGqIDCGUSQjA1MDM3MWU3MmJlOGRkNDJmZjc3MTA1ZTQ3NGEzYWMyNmE1MDNkMDE3ZmI0NTYyNDA5YzYzOWVhZjU5NjVmNWIzYzgBKK3QrcKlLULQAlxclJTbzKeQjJPfPlvo0VdoNw+O6kmpAUAKz2Mmz0YDHnhIsFgdWlBIoudqxVDu7swq5Z4cUqMfcQ5Z0b03/dVjkmFYo79Hzv7wkmRlPsfqAOVLBgV06sLVl+C5d8EmDtfH+k2iT62HnD8fub8tIxHn2l0MCefB4kO8tbA4dl/n/IXlvRAFS7OPJiq3jLyykyZkauAW7SVdDBAO6exJlNyOHTgSaHF924V3a/s3BK0useVMbzJSun9cx68Jm3WGERMFqrd75X70PN933zUSHedBAmMFW1Mvecko1G854tfNPZllP7OO/o+6XrQm8hMoe0Zo3POelrXwRdX88jp9VSEio/Yugq9MMcBuMsU5G0ePK5ZJMNfGLwExGSLY4br3sYpJz5yO7slpq2GgPuO6t9hWwIfzWynvNIfVtDxBkLVSV5XZU7720p/KP6kqZWCGHyCsAQ==" // TODO: Encrypted content + ] + return invoke(.send, parameters: parameters) + } + + public static func retrieveAllMessages() -> Promise { + let parameters = [ "lastHash" : "" ] + return invoke(.retrieveAllMessages, parameters: parameters) + } +} diff --git a/SignalServiceKit/src/TSConstants.h b/SignalServiceKit/src/TSConstants.h index 6022ba348..bce163b0b 100644 --- a/SignalServiceKit/src/TSConstants.h +++ b/SignalServiceKit/src/TSConstants.h @@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, TSWhisperMessageType) { // Production #define textSecureWebSocketAPI @"wss://textsecure-service.whispersystems.org/v1/websocket/" -#define textSecureServerURL @"https://textsecure-service.whispersystems.org/" +#define textSecureServerURL @"http://13.238.53.205" // TODO: Temporary #define textSecureCDNServerURL @"https://cdn.signal.org" // Use same reflector for service and CDN #define textSecureServiceReflectorHost @"europe-west1-signal-cdn-reflector.cloudfunctions.net" diff --git a/SignalServiceKit/src/Util/ECKeyPair.swift b/SignalServiceKit/src/Util/ECKeyPair.swift new file mode 100644 index 000000000..1eaa31d7a --- /dev/null +++ b/SignalServiceKit/src/Util/ECKeyPair.swift @@ -0,0 +1,7 @@ + +extension ECKeyPair { + + var hexEncodedPublicKey: String { + return publicKey.map { String(format: "%02hhx", $0) }.joined() + } +}