diff --git a/pass/Controllers/GitRepositoryAuthenticationSettingTableViewController.swift b/pass/Controllers/GitRepositoryAuthenticationSettingTableViewController.swift index 809559b..b2a9578 100644 --- a/pass/Controllers/GitRepositoryAuthenticationSettingTableViewController.swift +++ b/pass/Controllers/GitRepositoryAuthenticationSettingTableViewController.swift @@ -18,7 +18,7 @@ class GitRepositoryAuthenticationSettingTableViewController: UITableViewControll override func viewDidLoad() { super.viewDidLoad() navigationItem.title = "Auth Method" - switch selectedMethod! { + switch selectedMethod ?? "" { case "Password": passwordCell.accessoryType = UITableViewCellAccessoryType.checkmark case "SSH Key": diff --git a/pass/Controllers/PGPKeySettingTableViewController.swift b/pass/Controllers/PGPKeySettingTableViewController.swift index 149c5c5..f2663cb 100644 --- a/pass/Controllers/PGPKeySettingTableViewController.swift +++ b/pass/Controllers/PGPKeySettingTableViewController.swift @@ -24,6 +24,12 @@ class PGPKeySettingTableViewController: UITableViewController { override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { if identifier == "savePGPKeySegue" { + guard pgpPublicKeyURLTextField.text != nil else { + return false + } + guard pgpPrivateKeyURLTextField.text != nil else { + return false + } if URL(string: pgpPublicKeyURLTextField.text!)!.scheme! == "http" && URL(string: pgpPrivateKeyURLTextField.text!)!.scheme! == "http" { let alertMessage = "HTTP connection is not supported." diff --git a/pass/Controllers/SettingsTableViewController.swift b/pass/Controllers/SettingsTableViewController.swift index 9f88df0..2e3d702 100644 --- a/pass/Controllers/SettingsTableViewController.swift +++ b/pass/Controllers/SettingsTableViewController.swift @@ -26,7 +26,11 @@ class SettingsTableViewController: UITableViewController { @IBAction func save(segue: UIStoryboardSegue) { if let controller = segue.source as? PGPKeySettingTableViewController { - if Defaults[.pgpKeyID] == nil { + if Defaults[.pgpKeyID] == nil || + Defaults[.pgpPrivateKeyURL] != URL(string: controller.pgpPrivateKeyURLTextField.text!) || + Defaults[.pgpPublicKeyURL] != URL(string: controller.pgpPublicKeyURLTextField.text!) || + Defaults[.pgpKeyPassphrase] != controller.pgpKeyPassphraseTextField.text! + { Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!) Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!) Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text! diff --git a/pass/Models/PasswordStore.swift b/pass/Models/PasswordStore.swift index c681cbf..2452d17 100644 --- a/pass/Models/PasswordStore.swift +++ b/pass/Models/PasswordStore.swift @@ -80,8 +80,13 @@ class PasswordStore { try pgpPrivateData.write(to: URL(fileURLWithPath: pgpPrivateKeyLocalPath), options: .atomic) pgp.importKeys(fromFile: pgpPublicKeyLocalPath, allowDuplicates: false) + if pgp.getKeysOf(.public).count == 0 { + throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import public key."]) + } pgp.importKeys(fromFile: pgpPrivateKeyLocalPath, allowDuplicates: false) - + if pgp.getKeysOf(.secret).count == 0 { + throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import seceret key."]) + } let key = pgp.getKeysOf(.public)[0] Defaults[.pgpKeyID] = key.keyID!.shortKeyString if let gpgUser = key.users[0] as? PGPUser {