diff --git a/pass/Controllers/GitServerSettingTableViewController.swift b/pass/Controllers/GitServerSettingTableViewController.swift index 94667a1..e9fb482 100644 --- a/pass/Controllers/GitServerSettingTableViewController.swift +++ b/pass/Controllers/GitServerSettingTableViewController.swift @@ -40,9 +40,9 @@ class GitServerSettingTableViewController: UITableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - // Grey out ssh option if ssh_key and ssh_key.pub are not present + // Grey out ssh option if ssh_key is not present if let sshLabel = sshLabel { - sshLabel.isEnabled = gitSSHKeyExists() + sshLabel.isEnabled = passwordStore.gitSSHKeyExists() } } override func viewDidLoad() { @@ -89,7 +89,7 @@ class GitServerSettingTableViewController: UITableViewController { authenticationMethod = "Password" } else if cell == authSSHKeyCell { - if !gitSSHKeyExists() { + if !passwordStore.gitSSHKeyExists() { Utils.alert(title: "Cannot Select SSH Key", message: "Please setup SSH key first.", controller: self, completion: nil) authenticationMethod = "Password" } else { @@ -118,16 +118,12 @@ class GitServerSettingTableViewController: UITableViewController { doClone() } } - - private func gitSSHKeyExists() -> Bool { - return FileManager.default.fileExists(atPath: Globals.gitSSHPrivateKeyPath) - } - + func showSSHKeyActionSheet() { let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) var urlActionTitle = "Download from URL" var armorActionTitle = "ASCII-Armor Encrypted Key" - var fileActionTitle = "Use Uploaded Keys" + var fileActionTitle = "Use Imported Keys" if Defaults[.gitSSHKeySource] == "url" { urlActionTitle = "✓ \(urlActionTitle)" @@ -146,11 +142,19 @@ class GitServerSettingTableViewController: UITableViewController { optionMenu.addAction(urlAction) optionMenu.addAction(armorAction) - if (gitSSHKeyExists()) { + if passwordStore.gitSSHKeyExists() { + // might keys updated via iTunes, or downloaded/pasted inside the app let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in Defaults[.gitSSHKeySource] = "file" } optionMenu.addAction(fileAction) + } else { + let fileAction = UIAlertAction(title: "iTunes File Sharing", style: .default) { _ in + let title = "Import via iTunes File Sharing" + let message = "Copy your private key from your computer to Pass for iOS with the name \"ssh_key\" (without quotes)." + Utils.alert(title: title, message: message, controller: self) + } + optionMenu.addAction(fileAction) } if Defaults[.gitSSHKeySource] != nil { diff --git a/pass/Controllers/SettingsTableViewController.swift b/pass/Controllers/SettingsTableViewController.swift index 0cd10b2..9875c8e 100644 --- a/pass/Controllers/SettingsTableViewController.swift +++ b/pass/Controllers/SettingsTableViewController.swift @@ -257,17 +257,12 @@ class SettingsTableViewController: UITableViewController { let appDelegate = UIApplication.shared.delegate as! AppDelegate appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration) } - - func pgpKeyExists() -> Bool { - return FileManager.default.fileExists(atPath: Globals.pgpPublicKeyPath) && - FileManager.default.fileExists(atPath: Globals.pgpPrivateKeyPath) - } func showPGPKeyActionSheet() { let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) var urlActionTitle = "Download from URL" var armorActionTitle = "ASCII-Armor Encrypted Key" - var fileActionTitle = "Use Uploaded Keys" + var fileActionTitle = "Use Imported Keys" if Defaults[.pgpKeySource] == "url" { urlActionTitle = "✓ \(urlActionTitle)" @@ -286,7 +281,7 @@ class SettingsTableViewController: UITableViewController { optionMenu.addAction(urlAction) optionMenu.addAction(armorAction) - if (pgpKeyExists()) { + if passwordStore.pgpKeyExists() { let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in SVProgressHUD.setDefaultMaskType(.black) @@ -337,9 +332,17 @@ class SettingsTableViewController: UITableViewController { } + optionMenu.addAction(fileAction) + } else { + let fileAction = UIAlertAction(title: "iTunes File Sharing", style: .default) { _ in + let title = "Import via iTunes File Sharing" + let message = "Copy your public and private key from your computer to Pass for iOS with the name \"gpg_key.pub\" and \"gpg_key\" (without quotes)." + Utils.alert(title: title, message: message, controller: self) + } optionMenu.addAction(fileAction) } + if Defaults[.pgpKeySource] != nil { let deleteAction = UIAlertAction(title: "Remove PGP Keys", style: .destructive) { _ in self.passwordStore.removePGPKeys() diff --git a/pass/Models/PasswordStore.swift b/pass/Models/PasswordStore.swift index 3a258c8..157eba0 100644 --- a/pass/Models/PasswordStore.swift +++ b/pass/Models/PasswordStore.swift @@ -805,4 +805,14 @@ class PasswordStore { Defaults.remove(.gitSSHPrivateKeyURL) Utils.removeKeychain(name: ".gitSSHPrivateKeyPassphrase") } + + func gitSSHKeyExists() -> Bool { + let fm = FileManager.default + return fm.fileExists(atPath: Globals.gitSSHPrivateKeyPath) + } + + func pgpKeyExists() -> Bool { + let fm = FileManager.default + return fm.fileExists(atPath: Globals.pgpPublicKeyPath) && fm.fileExists(atPath: Globals.pgpPrivateKeyPath) + } }