Request ssh key password, if it is not set, but the key is encrypted

This commit is contained in:
Evgeny Morozov 2017-02-23 16:34:22 +03:00
parent 5c7fb97dbb
commit 04ceeb87dc
2 changed files with 67 additions and 7 deletions

View file

@ -113,7 +113,15 @@ class SettingsTableViewController: UITableViewController {
if auth == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password!))
} else {
gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: username, password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Globals.sshPublicKeyURL, privateKeyFile: Globals.sshPrivateKeyURL))
gitCredential = GitCredential(
credential: GitCredential.Credential.ssh(
userName: username,
password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!,
publicKeyFile: Globals.sshPublicKeyURL,
privateKeyFile: Globals.sshPrivateKeyURL,
passwordNotSetCallback: self.requestSshKeyPassword
)
)
}
let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
dispatchQueue.async {
@ -179,7 +187,32 @@ class SettingsTableViewController: UITableViewController {
touchIDSwitch.isEnabled = false
}
}
func requestSshKeyPassword() -> String {
let sem = DispatchSemaphore(value: 0)
var newPassword = ""
DispatchQueue.main.async {
SVProgressHUD.dismiss()
let alert = UIAlertController(title: "Password", message: "Please fill in the password of your SSH key.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
newPassword = alert.textFields!.first!.text!
sem.signal()
}))
alert.addTextField(configurationHandler: {(textField: UITextField!) in
textField.text = PasswordStore.shared.gitRepositoryPassword
textField.isSecureTextEntry = true
})
self.present(alert, animated: true, completion: nil)
}
let _ = sem.wait(timeout: DispatchTime.distantFuture)
return newPassword
}
func actOnPasswordStoreErasedNotification() {
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
touchIDSwitch.isOn = false