Support ASCII-armored and iTunes uploaded SSH key

This commit is contained in:
Bob Sun 2017-04-02 11:21:24 -07:00
parent 894a6cc54c
commit 97d66a8acc
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
11 changed files with 487 additions and 113 deletions

View file

@ -12,15 +12,14 @@ import SVProgressHUD
class SSHKeySettingTableViewController: UITableViewController {
@IBOutlet weak var passphraseTextField: UITextField!
@IBOutlet weak var privateKeyURLTextField: UITextField!
@IBOutlet weak var publicKeyURLTextField: UITextField!
let passwordStore = PasswordStore.shared
override func viewDidLoad() {
super.viewDidLoad()
passphraseTextField.text = Utils.getPasswordFromKeychain(name: "gitRepositorySSHPrivateKeyPassphrase") ?? ""
privateKeyURLTextField.text = Defaults[.gitRepositorySSHPrivateKeyURL]?.absoluteString
publicKeyURLTextField.text = Defaults[.gitRepositorySSHPublicKeyURL]?.absoluteString
privateKeyURLTextField.text = Defaults[.gitSSHPrivateKeyURL]?.absoluteString
publicKeyURLTextField.text = Defaults[.gitSSHPublicKeyURL]?.absoluteString
var doneBarButtonItem: UIBarButtonItem?
doneBarButtonItem = UIBarButtonItem(title: "Done",
@ -41,18 +40,42 @@ class SSHKeySettingTableViewController: UITableViewController {
return
}
Defaults[.gitRepositorySSHPublicKeyURL] = publicKeyURL
Defaults[.gitRepositorySSHPrivateKeyURL] = privateKeyURL
Utils.addPasswordToKeychain(name: "gitRepositorySSHPrivateKeyPassphrase", password: passphraseTextField.text!)
Defaults[.gitSSHPublicKeyURL] = publicKeyURL
Defaults[.gitSSHPrivateKeyURL] = privateKeyURL
do {
try Data(contentsOf: publicKeyURL).write(to: Globals.sshPublicKeyURL, options: .atomic)
try Data(contentsOf: privateKeyURL).write(to: Globals.sshPrivateKeyURL, options: .atomic)
try Data(contentsOf: publicKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPublicKeyPath), options: .atomic)
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPrivateKeyPath), options: .atomic)
} catch {
Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil)
}
navigationController!.popViewController(animated: true)
Defaults[.gitSSHKeySource] = "url"
let alert = UIAlertController(
title: "PGP Passphrase",
message: "Please fill in the passphrase for your Git Repository SSH key.",
preferredStyle: UIAlertControllerStyle.alert
)
alert.addAction(
UIAlertAction(
title: "OK",
style: UIAlertActionStyle.default,
handler: {_ in
Utils.addPasswordToKeychain(
name: "gitSSHPrivateKeyPassphrase",
password: alert.textFields!.first!.text!
)
self.navigationController!.popViewController(animated: true)
}
)
)
alert.addTextField(
configurationHandler: {(textField: UITextField!) in
textField.text = self.passwordStore.gitSSHPrivateKeyPassphrase
textField.isSecureTextEntry = true
})
self.present(alert, animated: true, completion: nil)
}
}