Fix incorrect key pair usage

This commit is contained in:
Niels Andriesse 2019-04-30 15:12:15 +10:00
parent dc80c17261
commit 5eddb9274b
6 changed files with 26 additions and 22 deletions

View File

@ -561,7 +561,7 @@
B821F2F52272CCD9002C88C0 /* spanish.txt in Resources */ = {isa = PBXBuildFile; fileRef = B821F2F12272CCD9002C88C0 /* spanish.txt */; };
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 */; };
B821F2FA2272CEEE002C88C0 /* OnboardingKeyPairViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F92272CEEE002C88C0 /* OnboardingKeyPairViewController.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 */; };
@ -1351,7 +1351,7 @@
B821F2F12272CCD9002C88C0 /* spanish.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = spanish.txt; path = mnemonic/spanish.txt; sourceTree = "<group>"; };
B821F2F22272CCD9002C88C0 /* english.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = english.txt; path = mnemonic/english.txt; sourceTree = "<group>"; };
B821F2F72272CED3002C88C0 /* OnboardingAccountDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingAccountDetailsViewController.swift; sourceTree = "<group>"; };
B821F2F92272CEEE002C88C0 /* OnboardingPublicKeyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingPublicKeyViewController.swift; sourceTree = "<group>"; };
B821F2F92272CEEE002C88C0 /* OnboardingKeyPairViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingKeyPairViewController.swift; sourceTree = "<group>"; };
B8C915222277FDC30028E4A9 /* ECKeyPair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ECKeyPair.swift; path = ../../../SignalServiceKit/src/Util/ECKeyPair.swift; sourceTree = "<group>"; };
B90418E4183E9DD40038554A /* DateUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateUtil.h; sourceTree = "<group>"; };
B90418E5183E9DD40038554A /* DateUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DateUtil.m; sourceTree = "<group>"; };
@ -1542,7 +1542,7 @@
3448E15D221333F5004B052E /* OnboardingController.swift */,
3448E15B22133274004B052E /* OnboardingPermissionsViewController.swift */,
34A4C61F22175C5C0042EF2E /* OnboardingProfileViewController.swift */,
B821F2F92272CEEE002C88C0 /* OnboardingPublicKeyViewController.swift */,
B821F2F92272CEEE002C88C0 /* OnboardingKeyPairViewController.swift */,
3448E15F22134C88004B052E /* OnboardingSplashViewController.swift */,
34A4C61D221613D00042EF2E /* OnboardingVerificationViewController.swift */,
346E9D5321B040B600562252 /* RegistrationController.swift */,
@ -3691,7 +3691,7 @@
457C87B82032645C008D52D6 /* DebugUINotifications.swift in Sources */,
4C21D5D8223AC60F00EF8A77 /* PhotoCapture.swift in Sources */,
4C13C9F620E57BA30089A98B /* ColorPickerViewController.swift in Sources */,
B821F2FA2272CEEE002C88C0 /* OnboardingPublicKeyViewController.swift in Sources */,
B821F2FA2272CEEE002C88C0 /* OnboardingKeyPairViewController.swift in Sources */,
4CC1ECFB211A553000CC13BE /* AppUpdateNag.swift in Sources */,
3448E16022134C89004B052E /* OnboardingSplashViewController.swift in Sources */,
34B6A903218B3F63007C4606 /* TypingIndicatorView.swift in Sources */,

View File

@ -76,6 +76,6 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle
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"))
}
}
onboardingController.pushPublicKeyViewController(from: self, userName: normalizedName)
onboardingController.pushKeyPairViewController(from: self, userName: normalizedName)
}
}

View File

@ -123,10 +123,10 @@ public class OnboardingController: NSObject {
viewController.navigationController?.pushViewController(accountDetailsVC, animated: true)
}
func pushPublicKeyViewController(from viewController: UIViewController, userName: String?) {
func pushKeyPairViewController(from viewController: UIViewController, userName: String?) {
AssertIsOnMainThread()
let publicKeyVC = OnboardingPublicKeyViewController(onboardingController: self, userName: userName)
viewController.navigationController?.pushViewController(publicKeyVC, animated: true)
let keyPairVC = OnboardingKeyPairViewController(onboardingController: self, userName: userName)
viewController.navigationController?.pushViewController(keyPairVC, animated: true)
}
public func onboardingRegistrationSucceeded(viewController: UIViewController) {

View File

@ -1,13 +1,12 @@
final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
final class OnboardingKeyPairViewController : OnboardingBaseViewController {
private var keyPair: ECKeyPair! { didSet { updateMnemonic() } }
private var hexEncodedPublicKey: String!
private var mnemonic: String! { didSet { mnemonicLabel.text = mnemonic } }
private var userName: String?
private lazy var mnemonicLabel: UILabel = {
let result = createExplanationLabel(text: "")
result.accessibilityIdentifier = "onboarding.publicKeyStep.mnemonicLabel"
result.accessibilityIdentifier = "onboarding.keyPairStep.mnemonicLabel"
result.alpha = 0.8
var fontTraits = result.font.fontDescriptor.symbolicTraits
fontTraits.insert(.traitItalic)
@ -17,7 +16,7 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
private lazy var copyButton: OWSFlatButton = {
let result = createLinkButton(title: NSLocalizedString("Copy", comment: ""), selector: #selector(copyMnemonic))
result.accessibilityIdentifier = "onboarding.publicKeyStep.copyButton"
result.accessibilityIdentifier = "onboarding.keyPairStep.copyButton"
return result
}()
@ -47,13 +46,13 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
view.backgroundColor = Theme.backgroundColor
view.layoutMargins = .zero
let titleLabel = createTitleLabel(text: NSLocalizedString("Create Your Loki Messenger Account", comment: ""))
titleLabel.accessibilityIdentifier = "onboarding.publicKeyStep.titleLabel"
titleLabel.accessibilityIdentifier = "onboarding.keyPairStep.titleLabel"
let topSpacer = UIView.vStretchingSpacer()
let explanationLabel = createExplanationLabel(text: NSLocalizedString("Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device.", comment: ""))
explanationLabel.accessibilityIdentifier = "onboarding.publicKeyStep.explanationLabel"
explanationLabel.accessibilityIdentifier = "onboarding.keyPairStep.explanationLabel"
let bottomSpacer = UIView.vStretchingSpacer()
let registerButton = createButton(title: NSLocalizedString("Register", comment: ""), selector: #selector(register))
registerButton.accessibilityIdentifier = "onboarding.publicKeyStep.registerButton"
registerButton.accessibilityIdentifier = "onboarding.keyPairStep.registerButton"
let stackView = UIStackView(arrangedSubviews: [
titleLabel,
topSpacer,
@ -83,8 +82,7 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
}
private func updateMnemonic() {
hexEncodedPublicKey = keyPair.hexEncodedPublicKey
mnemonic = Mnemonic.encode(hexEncodedString: hexEncodedPublicKey)
mnemonic = Mnemonic.encode(hexEncodedString: keyPair.hexEncodedPrivateKey)
}
@objc private func copyMnemonic() {
@ -101,7 +99,7 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
@objc private func register() {
let accountManager = TSAccountManager.sharedInstance()
accountManager.phoneNumberAwaitingVerification = hexEncodedPublicKey
accountManager.phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey
accountManager.didRegister()
let onSuccess: () -> Void = { [weak self] in
guard let strongSelf = self else { return }

View File

@ -20,8 +20,6 @@ public struct ServiceNode {
// MARK: API
private static func invoke(_ method: Method, parameters: [String:String] = [:]) -> Promise<Response> {
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)
}
@ -29,6 +27,7 @@ public struct ServiceNode {
public static func sendTestMessage() -> Promise<Response> {
let ttl = String(4 * 24 * 60 * 60 * 1000)
let parameters = [
"pubKey" : "0371e72be8dd42ff77105e474a3ac26a503d017fb4562409c639eaf5965f5b31", // TODO: Receiver's public key
"ttl" : ttl,
"nonce" : "AAAAAAAA5rs=", // TODO: Proof of work
"timestamp" : "1556259498201", // TODO: Message send time
@ -38,7 +37,10 @@ public struct ServiceNode {
}
public static func retrieveAllMessages() -> Promise<Response> {
let parameters = [ "lastHash" : "" ]
let parameters = [
"pubKey" : OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey,
"lastHash" : ""
]
return invoke(.retrieveAllMessages, parameters: parameters)
}
}

View File

@ -1,7 +1,11 @@
extension ECKeyPair {
var hexEncodedPrivateKey: String {
return privateKey.map { String(format: "%02hhx", $0) }.joined()
}
var hexEncodedPublicKey: String {
return publicKey.map { String(format: "%02hhx", $0) }.joined()
return "05" + publicKey.map { String(format: "%02hhx", $0) }.joined()
}
}