Provide info about the iTunes File Sharing

- only when key files are not existed (not downloaded/pasted/imported)
This commit is contained in:
Yishi Lin 2017-06-07 16:54:54 +08:00
parent 3cde0d954c
commit 6daa84df30
3 changed files with 34 additions and 17 deletions

View file

@ -40,9 +40,9 @@ class GitServerSettingTableViewController: UITableViewController {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) 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 { if let sshLabel = sshLabel {
sshLabel.isEnabled = gitSSHKeyExists() sshLabel.isEnabled = passwordStore.gitSSHKeyExists()
} }
} }
override func viewDidLoad() { override func viewDidLoad() {
@ -89,7 +89,7 @@ class GitServerSettingTableViewController: UITableViewController {
authenticationMethod = "Password" authenticationMethod = "Password"
} else if cell == authSSHKeyCell { } 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) Utils.alert(title: "Cannot Select SSH Key", message: "Please setup SSH key first.", controller: self, completion: nil)
authenticationMethod = "Password" authenticationMethod = "Password"
} else { } else {
@ -118,16 +118,12 @@ class GitServerSettingTableViewController: UITableViewController {
doClone() doClone()
} }
} }
private func gitSSHKeyExists() -> Bool {
return FileManager.default.fileExists(atPath: Globals.gitSSHPrivateKeyPath)
}
func showSSHKeyActionSheet() { func showSSHKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
var urlActionTitle = "Download from URL" var urlActionTitle = "Download from URL"
var armorActionTitle = "ASCII-Armor Encrypted Key" var armorActionTitle = "ASCII-Armor Encrypted Key"
var fileActionTitle = "Use Uploaded Keys" var fileActionTitle = "Use Imported Keys"
if Defaults[.gitSSHKeySource] == "url" { if Defaults[.gitSSHKeySource] == "url" {
urlActionTitle = "\(urlActionTitle)" urlActionTitle = "\(urlActionTitle)"
@ -146,11 +142,19 @@ class GitServerSettingTableViewController: UITableViewController {
optionMenu.addAction(urlAction) optionMenu.addAction(urlAction)
optionMenu.addAction(armorAction) 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 let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in
Defaults[.gitSSHKeySource] = "file" Defaults[.gitSSHKeySource] = "file"
} }
optionMenu.addAction(fileAction) 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 { if Defaults[.gitSSHKeySource] != nil {

View file

@ -257,17 +257,12 @@ class SettingsTableViewController: UITableViewController {
let appDelegate = UIApplication.shared.delegate as! AppDelegate let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration) 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() { func showPGPKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
var urlActionTitle = "Download from URL" var urlActionTitle = "Download from URL"
var armorActionTitle = "ASCII-Armor Encrypted Key" var armorActionTitle = "ASCII-Armor Encrypted Key"
var fileActionTitle = "Use Uploaded Keys" var fileActionTitle = "Use Imported Keys"
if Defaults[.pgpKeySource] == "url" { if Defaults[.pgpKeySource] == "url" {
urlActionTitle = "\(urlActionTitle)" urlActionTitle = "\(urlActionTitle)"
@ -286,7 +281,7 @@ class SettingsTableViewController: UITableViewController {
optionMenu.addAction(urlAction) optionMenu.addAction(urlAction)
optionMenu.addAction(armorAction) optionMenu.addAction(armorAction)
if (pgpKeyExists()) { if passwordStore.pgpKeyExists() {
let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in
SVProgressHUD.setDefaultMaskType(.black) 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) optionMenu.addAction(fileAction)
} }
if Defaults[.pgpKeySource] != nil { if Defaults[.pgpKeySource] != nil {
let deleteAction = UIAlertAction(title: "Remove PGP Keys", style: .destructive) { _ in let deleteAction = UIAlertAction(title: "Remove PGP Keys", style: .destructive) { _ in
self.passwordStore.removePGPKeys() self.passwordStore.removePGPKeys()

View file

@ -805,4 +805,14 @@ class PasswordStore {
Defaults.remove(.gitSSHPrivateKeyURL) Defaults.remove(.gitSSHPrivateKeyURL)
Utils.removeKeychain(name: ".gitSSHPrivateKeyPassphrase") 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)
}
} }