From 70166c99019acb2ee9443a4a06fee848f7aa1d37 Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Mon, 20 Feb 2017 11:48:39 +0800 Subject: [PATCH] fix a bug caused by keychain modifications --- ...epositorySettingsTableViewController.swift | 1 - pass/Helpers/DefaultsKeys.swift | 6 ++-- pass/Models/PasswordStore.swift | 31 ++++++++----------- pass/Views/TextViewTableViewCell.xib | 9 ++++-- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/pass/Controllers/PasswordRepositorySettingsTableViewController.swift b/pass/Controllers/PasswordRepositorySettingsTableViewController.swift index e05125f..ee80d4e 100644 --- a/pass/Controllers/PasswordRepositorySettingsTableViewController.swift +++ b/pass/Controllers/PasswordRepositorySettingsTableViewController.swift @@ -82,7 +82,6 @@ class PasswordRepositorySettingsTableViewController: BasicStaticTableViewControl NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL) Defaults[.gitRepositoryUsername] = username - PasswordStore.shared.gitRepositoryPassword = password Defaults[.gitRepositoryAuthenticationMethod] = auth Defaults[.gitRepositoryPasswordAttempts] = 0 SVProgressHUD.showSuccess(withStatus: "Done") diff --git a/pass/Helpers/DefaultsKeys.swift b/pass/Helpers/DefaultsKeys.swift index b9f0711..375849e 100644 --- a/pass/Helpers/DefaultsKeys.swift +++ b/pass/Helpers/DefaultsKeys.swift @@ -17,9 +17,9 @@ extension DefaultsKeys { static let pgpPublicKeyArmor = DefaultsKey("pgpPublicKeyArmor") static let pgpPrivateKeyArmor = DefaultsKey("pgpPrivateKeyArmor") - - static let pgpPrivateKeyURLPassphrase = DefaultsKey("pgpPrivateKeyURLPassphrase") - static let pgpPrivateKeyArmorPassphrase = DefaultsKey("pgpPrivateKeyArmorPassphrase") +// +// static let pgpPrivateKeyURLPassphrase = DefaultsKey("pgpPrivateKeyURLPassphrase") +// static let pgpPrivateKeyArmorPassphrase = DefaultsKey("pgpPrivateKeyArmorPassphrase") static let pgpKeyID = DefaultsKey("pgpKeyID") static let pgpKeyUserID = DefaultsKey("pgpKeyUserID") diff --git a/pass/Models/PasswordStore.swift b/pass/Models/PasswordStore.swift index 6267342..ba26ff5 100644 --- a/pass/Models/PasswordStore.swift +++ b/pass/Models/PasswordStore.swift @@ -84,21 +84,19 @@ class PasswordStore { let pgp: ObjectivePGP = ObjectivePGP() var pgpKeyPassphrase: String? { - didSet { - if pgpKeyPassphrase != nil { - Utils.addPasswrodToKeychain(name: "pgpKeyPassphrase", password: pgpKeyPassphrase!) - } else { - Utils.removeKeychain(name: "pgpKeyPassphrase") - } + set { + Utils.addPasswrodToKeychain(name: "pgpKeyPassphrase", password: newValue!) + } + get { + return Utils.getPasswordFromKeychain(name: "pgpKeyPassphrase") } } - var gitRepositoryPassword: String? { - didSet { - if gitRepositoryPassword != nil { - Utils.addPasswrodToKeychain(name: "gitRepositoryPassword", password: gitRepositoryPassword!) - } else { - Utils.removeKeychain(name: "gitRepositoryPassword") - } + var gitRepositoryPassword: String? { + set { + Utils.addPasswrodToKeychain(name: "gitRepositoryPassword", password: newValue!) + } + get { + return Utils.getPasswordFromKeychain(name: "gitRepositoryPassword") } } @@ -119,14 +117,12 @@ class PasswordStore { } if Defaults[.gitRepositoryAuthenticationMethod] == "Password" { - gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername]!, password: PasswordStore.shared.gitRepositoryPassword!)) + gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername]!, password: Utils.getPasswordFromKeychain(name: "gitRepositoryPassword") ?? "")) } else if Defaults[.gitRepositoryAuthenticationMethod] == "SSH Key"{ gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: Defaults[.gitRepositoryUsername]!, password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Globals.sshPublicKeyURL, privateKeyFile: Globals.sshPrivateKeyURL)) } else { gitCredential = nil } - pgpKeyPassphrase = Utils.getPasswordFromKeychain(name: "pgpKeyPassphrase") - gitRepositoryPassword = Utils.getPasswordFromKeychain(name: "gitRepositoryPassword") } @@ -465,8 +461,7 @@ class PasswordStore { Utils.removeFileIfExists(at: Globals.sshPublicKeyURL) Utils.removeAllKeychain() - pgpKeyPassphrase = nil - gitRepositoryPassword = nil + deleteCoreData(entityName: "PasswordEntity") deleteCoreData(entityName: "PasswordCategoryEntity") diff --git a/pass/Views/TextViewTableViewCell.xib b/pass/Views/TextViewTableViewCell.xib index e0da857..bfed387 100644 --- a/pass/Views/TextViewTableViewCell.xib +++ b/pass/Views/TextViewTableViewCell.xib @@ -1,11 +1,11 @@ - + - + @@ -19,9 +19,12 @@ - + + + +