2017-01-22 01:42:36 +08:00
|
|
|
//
|
|
|
|
|
// PGPKeySettingTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 21/1/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2017-01-22 01:42:36 +08:00
|
|
|
|
|
|
|
|
class PGPKeySettingTableViewController: UITableViewController {
|
|
|
|
|
|
2017-02-10 22:15:01 +08:00
|
|
|
@IBOutlet weak var pgpPublicKeyURLTextField: UITextField!
|
|
|
|
|
@IBOutlet weak var pgpPrivateKeyURLTextField: UITextField!
|
2017-02-17 14:58:27 +08:00
|
|
|
var pgpPassphrase: String?
|
2017-03-16 22:39:03 -07:00
|
|
|
let passwordStore = PasswordStore.shared
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-01-22 01:42:36 +08:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2017-02-19 22:10:36 +08:00
|
|
|
tableView.rowHeight = UITableViewAutomaticDimension
|
2017-06-13 11:42:49 +08:00
|
|
|
pgpPublicKeyURLTextField.text = SharedDefaults[.pgpPublicKeyURL]?.absoluteString
|
|
|
|
|
pgpPrivateKeyURLTextField.text = SharedDefaults[.pgpPrivateKeyURL]?.absoluteString
|
2017-03-16 22:39:03 -07:00
|
|
|
pgpPassphrase = passwordStore.pgpKeyPassphrase
|
2017-01-22 01:42:36 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-05-11 22:55:55 -07:00
|
|
|
private func validatePGPKeyURL(input: String?) -> Bool {
|
|
|
|
|
guard let path = input, let url = URL(string: path) else {
|
2019-01-14 20:57:45 +01:00
|
|
|
Utils.alert(title: "CannotSavePgpKey".localize(), message: "SetPgpKeyUrlFirst.".localize(), controller: self, completion: nil)
|
2017-05-11 22:55:55 -07:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
guard let scheme = url.scheme, scheme == "https", scheme == "https" else {
|
2019-01-14 20:57:45 +01:00
|
|
|
Utils.alert(title: "CannotSavePgpKey".localize(), message: "HttpNotSupported.".localize(), controller: self, completion: nil)
|
2017-05-11 22:55:55 -07:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-02-17 14:58:27 +08:00
|
|
|
@IBAction func save(_ sender: Any) {
|
2017-07-27 21:12:58 +08:00
|
|
|
guard validatePGPKeyURL(input: pgpPublicKeyURLTextField.text) == true,
|
|
|
|
|
validatePGPKeyURL(input: pgpPrivateKeyURLTextField.text) == true else {
|
|
|
|
|
return
|
|
|
|
|
}
|
2019-01-14 20:57:45 +01:00
|
|
|
let savePassphraseAlert = UIAlertController(title: "Passphrase".localize(), message: "WantToSavePassphrase?".localize(), preferredStyle: UIAlertControllerStyle.alert)
|
2017-06-07 21:11:01 +08:00
|
|
|
// no
|
2019-01-14 20:57:45 +01:00
|
|
|
savePassphraseAlert.addAction(UIAlertAction(title: "No".localize(), style: UIAlertActionStyle.default) { _ in
|
2017-06-07 21:11:01 +08:00
|
|
|
self.pgpPassphrase = nil
|
2017-10-08 21:37:58 +08:00
|
|
|
SharedDefaults[.isRememberPGPPassphraseOn] = false
|
2017-06-07 21:11:01 +08:00
|
|
|
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
|
|
|
|
|
})
|
|
|
|
|
// yes
|
2019-01-14 20:57:45 +01:00
|
|
|
savePassphraseAlert.addAction(UIAlertAction(title: "Yes".localize(), style: UIAlertActionStyle.destructive) {_ in
|
2017-06-07 21:11:01 +08:00
|
|
|
// ask for the passphrase
|
2019-01-14 20:57:45 +01:00
|
|
|
let alert = UIAlertController(title: "Passphrase".localize(), message: "FillInPgpPassphrase.".localize(), preferredStyle: UIAlertControllerStyle.alert)
|
|
|
|
|
alert.addAction(UIAlertAction(title: "Ok".localize(), style: UIAlertActionStyle.default, handler: {_ in
|
2017-06-07 21:11:01 +08:00
|
|
|
self.pgpPassphrase = alert.textFields?.first?.text
|
2017-10-08 21:37:58 +08:00
|
|
|
SharedDefaults[.isRememberPGPPassphraseOn] = true
|
2017-06-07 21:11:01 +08:00
|
|
|
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
|
|
|
|
|
}))
|
|
|
|
|
alert.addTextField(configurationHandler: {(textField: UITextField!) in
|
|
|
|
|
textField.text = self.pgpPassphrase
|
|
|
|
|
textField.isSecureTextEntry = true
|
|
|
|
|
})
|
|
|
|
|
self.present(alert, animated: true, completion: nil)
|
2017-02-17 14:58:27 +08:00
|
|
|
})
|
2017-06-07 21:11:01 +08:00
|
|
|
self.present(savePassphraseAlert, animated: true, completion: nil)
|
2017-02-17 14:58:27 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
|
|
|
|
|
2017-01-22 01:42:36 +08:00
|
|
|
}
|