2017-01-19 21:15:47 +08:00
|
|
|
//
|
|
|
|
|
// SettingsTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 18/1/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
import SVProgressHUD
|
|
|
|
|
import CoreData
|
2017-01-22 01:42:36 +08:00
|
|
|
import SwiftyUserDefaults
|
2017-02-07 20:24:58 +08:00
|
|
|
import PasscodeLock
|
2017-01-19 21:15:47 +08:00
|
|
|
|
|
|
|
|
class SettingsTableViewController: UITableViewController {
|
2017-02-07 20:24:58 +08:00
|
|
|
|
2017-03-02 16:51:46 +08:00
|
|
|
lazy var touchIDSwitch: UISwitch = {
|
|
|
|
|
let uiSwitch = UISwitch(frame: CGRect.zero)
|
|
|
|
|
uiSwitch.onTintColor = Globals.blue
|
|
|
|
|
uiSwitch.addTarget(self, action: #selector(touchIDSwitchAction), for: UIControlEvents.valueChanged)
|
|
|
|
|
return uiSwitch
|
|
|
|
|
}()
|
2017-02-07 20:57:06 +08:00
|
|
|
|
2017-01-22 01:42:36 +08:00
|
|
|
@IBOutlet weak var pgpKeyTableViewCell: UITableViewCell!
|
2017-02-07 17:56:31 +08:00
|
|
|
@IBOutlet weak var touchIDTableViewCell: UITableViewCell!
|
|
|
|
|
@IBOutlet weak var passcodeTableViewCell: UITableViewCell!
|
2017-02-21 13:07:14 +08:00
|
|
|
@IBOutlet weak var passwordRepositoryTableViewCell: UITableViewCell!
|
2017-02-09 21:45:31 +08:00
|
|
|
|
2017-02-17 13:44:25 +08:00
|
|
|
@IBAction func cancelPGPKey(segue: UIStoryboardSegue) {
|
2017-01-19 21:15:47 +08:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 13:44:25 +08:00
|
|
|
@IBAction func savePGPKey(segue: UIStoryboardSegue) {
|
2017-02-09 21:45:31 +08:00
|
|
|
if let controller = segue.source as? PGPKeySettingTableViewController {
|
2017-02-17 14:58:27 +08:00
|
|
|
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
|
|
|
|
|
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
|
2017-02-19 22:10:36 +08:00
|
|
|
PasswordStore.shared.pgpKeyPassphrase = controller.pgpPassphrase
|
2017-02-17 14:58:27 +08:00
|
|
|
Defaults[.pgpKeySource] = "url"
|
2017-02-17 13:44:25 +08:00
|
|
|
|
2017-02-17 14:58:27 +08:00
|
|
|
SVProgressHUD.setDefaultMaskType(.black)
|
|
|
|
|
SVProgressHUD.setDefaultStyle(.light)
|
|
|
|
|
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
|
|
|
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
|
|
|
|
do {
|
2017-03-16 22:06:39 -07:00
|
|
|
try PasswordStore.shared.initPGPKey(from: Defaults[.pgpPublicKeyURL]!, keyType: .public)
|
|
|
|
|
try PasswordStore.shared.initPGPKey(from: Defaults[.pgpPrivateKeyURL]!, keyType: .secret)
|
2017-02-17 14:58:27 +08:00
|
|
|
DispatchQueue.main.async {
|
2017-03-16 22:06:39 -07:00
|
|
|
self.pgpKeyTableViewCell.detailTextLabel?.text = PasswordStore.shared.pgpKeyID
|
2017-02-20 22:02:49 +08:00
|
|
|
SVProgressHUD.showSuccess(withStatus: "Success")
|
2017-02-17 14:58:27 +08:00
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
Utils.alert(title: "Rememver to Remove the Key", message: "Remember to remove the key from the server.", controller: self, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
self.pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
|
|
|
|
|
SVProgressHUD.showError(withStatus: error.localizedDescription)
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
2017-01-22 01:42:36 +08:00
|
|
|
}
|
|
|
|
|
}
|
2017-02-17 14:58:27 +08:00
|
|
|
}
|
2017-01-22 01:42:36 +08:00
|
|
|
|
2017-02-17 13:44:25 +08:00
|
|
|
} else if let controller = segue.source as? PGPKeyArmorSettingTableViewController {
|
|
|
|
|
Defaults[.pgpKeySource] = "armor"
|
2017-02-19 22:10:36 +08:00
|
|
|
PasswordStore.shared.pgpKeyPassphrase = controller.pgpPassphrase
|
2017-02-28 12:25:52 +08:00
|
|
|
if Defaults[.isRememberPassphraseOn] {
|
2017-03-06 12:49:00 -08:00
|
|
|
Utils.addPasswordToKeychain(name: "pgpKeyPassphrase", password: controller.pgpPassphrase!)
|
2017-02-28 12:25:52 +08:00
|
|
|
}
|
2017-02-19 22:10:36 +08:00
|
|
|
|
2017-02-17 13:44:25 +08:00
|
|
|
Defaults[.pgpPublicKeyArmor] = controller.armorPublicKeyTextView.text!
|
|
|
|
|
Defaults[.pgpPrivateKeyArmor] = controller.armorPrivateKeyTextView.text!
|
|
|
|
|
|
|
|
|
|
SVProgressHUD.setDefaultMaskType(.black)
|
|
|
|
|
SVProgressHUD.setDefaultStyle(.light)
|
|
|
|
|
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
|
|
|
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
|
|
|
|
do {
|
2017-03-16 22:06:39 -07:00
|
|
|
try PasswordStore.shared.initPGPKey(with: controller.armorPublicKeyTextView.text, keyType: .public)
|
|
|
|
|
try PasswordStore.shared.initPGPKey(with: controller.armorPrivateKeyTextView.text, keyType: .secret)
|
2017-02-17 13:44:25 +08:00
|
|
|
DispatchQueue.main.async {
|
2017-03-16 22:06:39 -07:00
|
|
|
self.pgpKeyTableViewCell.detailTextLabel?.text = PasswordStore.shared.pgpKeyID
|
2017-02-20 22:02:49 +08:00
|
|
|
SVProgressHUD.showSuccess(withStatus: "Success")
|
2017-02-17 13:44:25 +08:00
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
self.pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
|
|
|
|
|
SVProgressHUD.showError(withStatus: error.localizedDescription)
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-19 21:15:47 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-21 13:07:14 +08:00
|
|
|
@IBAction func cancelGitServerSetting(segue: UIStoryboardSegue) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func saveGitServerSetting(segue: UIStoryboardSegue) {
|
|
|
|
|
if let controller = segue.source as? GitServerSettingTableViewController {
|
|
|
|
|
let gitRepostiroyURL = controller.gitRepositoryURLTextField.text!
|
|
|
|
|
let username = controller.usernameTextField.text!
|
|
|
|
|
let password = controller.password
|
|
|
|
|
let auth = controller.authenticationMethod
|
|
|
|
|
|
|
|
|
|
if Defaults[.gitRepositoryURL] == nil ||
|
|
|
|
|
Defaults[.gitRepositoryURL]!.absoluteString != gitRepostiroyURL ||
|
|
|
|
|
auth != Defaults[.gitRepositoryAuthenticationMethod] ||
|
|
|
|
|
username != Defaults[.gitRepositoryUsername] ||
|
2017-02-27 17:30:33 +08:00
|
|
|
password != PasswordStore.shared.gitRepositoryPassword ||
|
2017-03-02 17:26:46 +08:00
|
|
|
PasswordStore.shared.repositoryExisted() == false {
|
2017-02-21 13:07:14 +08:00
|
|
|
|
|
|
|
|
SVProgressHUD.setDefaultMaskType(.black)
|
|
|
|
|
SVProgressHUD.setDefaultStyle(.light)
|
|
|
|
|
SVProgressHUD.show(withStatus: "Prepare Repository")
|
|
|
|
|
var gitCredential: GitCredential
|
|
|
|
|
if auth == "Password" {
|
|
|
|
|
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password!))
|
|
|
|
|
} else {
|
2017-02-23 16:34:22 +03:00
|
|
|
gitCredential = GitCredential(
|
|
|
|
|
credential: GitCredential.Credential.ssh(
|
|
|
|
|
userName: username,
|
2017-02-23 18:39:43 +03:00
|
|
|
password: Utils.getPasswordFromKeychain(name: "gitRepositorySSHPrivateKeyPassphrase") ?? "",
|
2017-02-23 16:34:22 +03:00
|
|
|
publicKeyFile: Globals.sshPublicKeyURL,
|
|
|
|
|
privateKeyFile: Globals.sshPrivateKeyURL,
|
|
|
|
|
passwordNotSetCallback: self.requestSshKeyPassword
|
|
|
|
|
)
|
|
|
|
|
)
|
2017-02-21 13:07:14 +08:00
|
|
|
}
|
|
|
|
|
let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
|
|
|
|
|
dispatchQueue.async {
|
|
|
|
|
do {
|
|
|
|
|
try PasswordStore.shared.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,
|
|
|
|
|
credential: gitCredential,
|
|
|
|
|
transferProgressBlock:{ (git_transfer_progress, stop) in
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
checkoutProgressBlock: { (path, completedSteps, totalSteps) in
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch")
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
PasswordStore.shared.updatePasswordEntityCoreData()
|
|
|
|
|
Defaults[.lastUpdatedTime] = Date()
|
|
|
|
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
|
|
|
|
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
|
|
|
|
|
Defaults[.gitRepositoryUsername] = username
|
|
|
|
|
Defaults[.gitRepositoryAuthenticationMethod] = auth
|
|
|
|
|
Defaults[.gitRepositoryPasswordAttempts] = 0
|
|
|
|
|
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryURL]?.host
|
|
|
|
|
SVProgressHUD.showSuccess(withStatus: "Done")
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
print(error)
|
|
|
|
|
SVProgressHUD.showError(withStatus: error.localizedDescription)
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 21:15:47 +08:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2017-02-09 11:31:49 +08:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(SettingsTableViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
|
2017-02-21 17:36:51 +08:00
|
|
|
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryURL]?.host
|
2017-02-07 17:56:31 +08:00
|
|
|
touchIDTableViewCell.accessoryView = touchIDSwitch
|
2017-02-26 20:59:27 +08:00
|
|
|
setPGPKeyTableViewCellDetailText()
|
|
|
|
|
setPasswordRepositoryTableViewCellDetailText()
|
|
|
|
|
setTouchIDSwitch()
|
|
|
|
|
setPasscodeLockRepositoryTableViewCellDetailText()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func setPasscodeLockRepositoryTableViewCellDetailText() {
|
|
|
|
|
if PasscodeLockRepository().hasPasscode {
|
|
|
|
|
self.passcodeTableViewCell.detailTextLabel?.text = "On"
|
|
|
|
|
} else {
|
|
|
|
|
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
|
|
|
|
|
touchIDSwitch.isEnabled = false
|
|
|
|
|
Globals.passcodeConfiguration.isTouchIDAllowed = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func setPGPKeyTableViewCellDetailText() {
|
2017-03-16 22:06:39 -07:00
|
|
|
if let pgpKeyID = PasswordStore.shared.pgpKeyID {
|
|
|
|
|
pgpKeyTableViewCell.detailTextLabel?.text = pgpKeyID
|
2017-02-09 11:31:49 +08:00
|
|
|
} else {
|
2017-03-16 22:06:39 -07:00
|
|
|
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
|
2017-02-09 11:31:49 +08:00
|
|
|
}
|
2017-02-26 20:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func setPasswordRepositoryTableViewCellDetailText() {
|
|
|
|
|
if Defaults[.gitRepositoryURL] == nil {
|
|
|
|
|
passwordRepositoryTableViewCell.detailTextLabel?.text = "Not Set"
|
|
|
|
|
} else {
|
|
|
|
|
passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryURL]!.host
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func setTouchIDSwitch() {
|
2017-02-07 20:24:58 +08:00
|
|
|
if Defaults[.isTouchIDOn] {
|
|
|
|
|
touchIDSwitch.isOn = true
|
|
|
|
|
} else {
|
|
|
|
|
touchIDSwitch.isOn = false
|
|
|
|
|
}
|
2017-02-07 17:56:31 +08:00
|
|
|
}
|
2017-02-23 16:34:22 +03:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 11:31:49 +08:00
|
|
|
func actOnPasswordStoreErasedNotification() {
|
2017-02-26 20:59:27 +08:00
|
|
|
setPGPKeyTableViewCellDetailText()
|
|
|
|
|
setPasswordRepositoryTableViewCellDetailText()
|
|
|
|
|
setTouchIDSwitch()
|
|
|
|
|
setPasscodeLockRepositoryTableViewCellDetailText()
|
2017-02-09 11:31:49 +08:00
|
|
|
|
|
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
|
|
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 17:56:31 +08:00
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
|
if tableView.cellForRow(at: indexPath) == passcodeTableViewCell {
|
2017-02-07 20:24:58 +08:00
|
|
|
if Defaults[.passcodeKey] != nil{
|
|
|
|
|
showPasscodeActionSheet()
|
|
|
|
|
} else {
|
|
|
|
|
setPasscodeLock()
|
|
|
|
|
}
|
2017-02-17 13:44:25 +08:00
|
|
|
} else if tableView.cellForRow(at: indexPath) == pgpKeyTableViewCell {
|
|
|
|
|
showPGPKeyActionSheet()
|
2017-02-07 17:56:31 +08:00
|
|
|
}
|
2017-02-17 13:44:25 +08:00
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
2017-02-07 16:45:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
|
super.viewWillAppear(animated)
|
2017-01-19 21:15:47 +08:00
|
|
|
}
|
2017-02-07 17:56:31 +08:00
|
|
|
|
|
|
|
|
func touchIDSwitchAction(uiSwitch: UISwitch) {
|
|
|
|
|
if uiSwitch.isOn {
|
2017-02-07 20:57:06 +08:00
|
|
|
Defaults[.isTouchIDOn] = true
|
2017-02-08 10:15:38 +08:00
|
|
|
Globals.passcodeConfiguration.isTouchIDAllowed = true
|
2017-02-07 17:56:31 +08:00
|
|
|
} else {
|
2017-02-07 20:57:06 +08:00
|
|
|
Defaults[.isTouchIDOn] = false
|
2017-02-08 10:15:38 +08:00
|
|
|
Globals.passcodeConfiguration.isTouchIDAllowed = false
|
2017-02-07 17:56:31 +08:00
|
|
|
}
|
2017-02-08 14:53:07 +08:00
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
|
|
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
|
2017-02-07 17:56:31 +08:00
|
|
|
}
|
2017-02-24 17:59:04 +03:00
|
|
|
|
|
|
|
|
func pgpKeyExists() -> Bool {
|
|
|
|
|
return FileManager.default.fileExists(atPath: Globals.pgpPublicKeyPath) &&
|
|
|
|
|
FileManager.default.fileExists(atPath: Globals.pgpPrivateKeyPath)
|
|
|
|
|
}
|
2017-02-07 17:56:31 +08:00
|
|
|
|
2017-02-17 13:44:25 +08:00
|
|
|
func showPGPKeyActionSheet() {
|
|
|
|
|
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
|
|
|
|
var urlActionTitle = "Download from URL"
|
|
|
|
|
var armorActionTitle = "ASCII-Armor Encrypted Key"
|
2017-02-28 17:16:51 +08:00
|
|
|
var fileActionTitle = "Use Uploaded Keys"
|
2017-02-17 13:44:25 +08:00
|
|
|
|
|
|
|
|
if Defaults[.pgpKeySource] == "url" {
|
|
|
|
|
urlActionTitle = "✓ \(urlActionTitle)"
|
|
|
|
|
} else if Defaults[.pgpKeySource] == "armor" {
|
|
|
|
|
armorActionTitle = "✓ \(armorActionTitle)"
|
2017-02-24 17:59:04 +03:00
|
|
|
} else if Defaults[.pgpKeySource] == "file" {
|
|
|
|
|
fileActionTitle = "✓ \(fileActionTitle)"
|
2017-02-17 13:44:25 +08:00
|
|
|
}
|
|
|
|
|
let urlAction = UIAlertAction(title: urlActionTitle, style: .default) { _ in
|
|
|
|
|
self.performSegue(withIdentifier: "setPGPKeyByURLSegue", sender: self)
|
|
|
|
|
}
|
|
|
|
|
let armorAction = UIAlertAction(title: armorActionTitle, style: .default) { _ in
|
|
|
|
|
self.performSegue(withIdentifier: "setPGPKeyByASCIISegue", sender: self)
|
|
|
|
|
}
|
|
|
|
|
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
|
|
|
|
optionMenu.addAction(urlAction)
|
|
|
|
|
optionMenu.addAction(armorAction)
|
2017-02-24 17:59:04 +03:00
|
|
|
|
|
|
|
|
if (pgpKeyExists()) {
|
|
|
|
|
let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in
|
|
|
|
|
|
|
|
|
|
SVProgressHUD.setDefaultMaskType(.black)
|
|
|
|
|
SVProgressHUD.setDefaultStyle(.light)
|
|
|
|
|
SVProgressHUD.show(withStatus: "Reading PGP key")
|
|
|
|
|
|
|
|
|
|
let alert = UIAlertController(
|
|
|
|
|
title: "PGP Passphrase",
|
|
|
|
|
message: "Please fill in the passphrase for your PGP key.",
|
|
|
|
|
preferredStyle: UIAlertControllerStyle.alert
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
alert.addAction(
|
|
|
|
|
UIAlertAction(
|
|
|
|
|
title: "OK",
|
|
|
|
|
style: UIAlertActionStyle.default,
|
|
|
|
|
handler: {_ in
|
2017-03-06 12:49:00 -08:00
|
|
|
Utils.addPasswordToKeychain(
|
2017-02-24 17:59:04 +03:00
|
|
|
name: "pgpKeyPassphrase",
|
|
|
|
|
password: alert.textFields!.first!.text!
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
alert.addTextField(
|
|
|
|
|
configurationHandler: {(textField: UITextField!) in
|
|
|
|
|
textField.text = Utils.getPasswordFromKeychain(name: "pgpKeyPassphrase") ?? ""
|
|
|
|
|
textField.isSecureTextEntry = true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
2017-03-16 22:06:39 -07:00
|
|
|
PasswordStore.shared.initPGPKeys()
|
2017-02-24 17:59:04 +03:00
|
|
|
|
|
|
|
|
let key: PGPKey = PasswordStore.shared.getPgpPrivateKey()
|
|
|
|
|
Defaults[.pgpKeySource] = "file"
|
|
|
|
|
|
|
|
|
|
if (key.isEncrypted) {
|
|
|
|
|
SVProgressHUD.dismiss()
|
|
|
|
|
self.present(alert, animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SVProgressHUD.dismiss()
|
2017-03-16 22:06:39 -07:00
|
|
|
self.pgpKeyTableViewCell.detailTextLabel?.text = PasswordStore.shared.pgpKeyID
|
2017-02-24 17:59:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
optionMenu.addAction(fileAction)
|
|
|
|
|
}
|
2017-02-17 13:44:25 +08:00
|
|
|
|
|
|
|
|
if Defaults[.pgpKeySource] != nil {
|
|
|
|
|
let deleteAction = UIAlertAction(title: "Remove PGP Keys", style: .destructive) { _ in
|
|
|
|
|
Utils.removePGPKeys()
|
|
|
|
|
self.pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
|
|
|
|
|
}
|
|
|
|
|
optionMenu.addAction(deleteAction)
|
|
|
|
|
}
|
|
|
|
|
optionMenu.addAction(cancelAction)
|
2017-02-22 18:18:59 +08:00
|
|
|
optionMenu.popoverPresentationController?.sourceView = pgpKeyTableViewCell
|
|
|
|
|
optionMenu.popoverPresentationController?.sourceRect = pgpKeyTableViewCell.bounds
|
2017-02-17 13:44:25 +08:00
|
|
|
self.present(optionMenu, animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 17:56:31 +08:00
|
|
|
func showPasscodeActionSheet() {
|
2017-02-08 10:15:38 +08:00
|
|
|
let passcodeChangeViewController = PasscodeLockViewController(state: .change, configuration: Globals.passcodeConfiguration)
|
|
|
|
|
let passcodeRemoveViewController = PasscodeLockViewController(state: .remove, configuration: Globals.passcodeConfiguration)
|
2017-02-07 20:24:58 +08:00
|
|
|
|
2017-02-07 17:56:31 +08:00
|
|
|
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
2017-02-10 00:56:12 +08:00
|
|
|
let removePasscodeAction = UIAlertAction(title: "Remove Passcode", style: .destructive) { [weak self] _ in
|
2017-02-07 20:24:58 +08:00
|
|
|
passcodeRemoveViewController.successCallback = { _ in
|
2017-02-10 00:56:12 +08:00
|
|
|
self?.passcodeTableViewCell.detailTextLabel?.text = "Off"
|
|
|
|
|
self?.touchIDSwitch.isEnabled = false
|
2017-02-08 16:29:03 +08:00
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
|
|
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
|
2017-02-07 20:24:58 +08:00
|
|
|
}
|
2017-02-10 00:56:12 +08:00
|
|
|
self?.present(passcodeRemoveViewController, animated: true, completion: nil)
|
2017-02-07 20:24:58 +08:00
|
|
|
}
|
|
|
|
|
|
2017-02-10 00:56:12 +08:00
|
|
|
let changePasscodeAction = UIAlertAction(title: "Change Passcode", style: .default) { [weak self] _ in
|
|
|
|
|
self?.present(passcodeChangeViewController, animated: true, completion: nil)
|
2017-02-07 20:24:58 +08:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 17:56:31 +08:00
|
|
|
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
|
|
|
|
optionMenu.addAction(removePasscodeAction)
|
|
|
|
|
optionMenu.addAction(changePasscodeAction)
|
|
|
|
|
optionMenu.addAction(cancelAction)
|
2017-02-22 18:18:59 +08:00
|
|
|
optionMenu.popoverPresentationController?.sourceView = passcodeTableViewCell
|
|
|
|
|
optionMenu.popoverPresentationController?.sourceRect = passcodeTableViewCell.bounds
|
2017-02-07 17:56:31 +08:00
|
|
|
self.present(optionMenu, animated: true, completion: nil)
|
|
|
|
|
}
|
2017-02-07 20:24:58 +08:00
|
|
|
|
|
|
|
|
func setPasscodeLock() {
|
2017-02-08 10:15:38 +08:00
|
|
|
let passcodeSetViewController = PasscodeLockViewController(state: .set, configuration: Globals.passcodeConfiguration)
|
2017-02-07 20:24:58 +08:00
|
|
|
passcodeSetViewController.successCallback = { _ in
|
|
|
|
|
self.passcodeTableViewCell.detailTextLabel?.text = "On"
|
2017-02-07 20:57:06 +08:00
|
|
|
self.touchIDSwitch.isEnabled = true
|
2017-02-07 20:24:58 +08:00
|
|
|
}
|
|
|
|
|
present(passcodeSetViewController, animated: true, completion: nil)
|
|
|
|
|
}
|
2017-01-19 21:15:47 +08:00
|
|
|
}
|