Check cloned repository for .gpg-id file (#523)
* Extract method * Separate deletion of store data from general data erasure * Check cloned repository for .gpg-id file
This commit is contained in:
parent
08ce198334
commit
b62c5fa2e5
4 changed files with 55 additions and 32 deletions
|
|
@ -193,31 +193,23 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
|
||||||
checkoutProgressBlock: checkoutProgressBlock
|
checkoutProgressBlock: checkoutProgressBlock
|
||||||
)
|
)
|
||||||
|
|
||||||
SVProgressHUD.dismiss {
|
let gpgIdFile = self.passwordStore.storeURL.appendingPathComponent(".gpg-id").path
|
||||||
let savePassphraseAlert: UIAlertController = {
|
guard FileManager.default.fileExists(atPath: gpgIdFile) else {
|
||||||
let alert = UIAlertController(title: "Done".localize(), message: "WantToSaveGitCredential?".localize(), preferredStyle: .alert)
|
self.passwordStore.eraseStoreData()
|
||||||
alert.addAction(
|
SVProgressHUD.dismiss {
|
||||||
UIAlertAction(title: "No".localize(), style: .default) { _ in
|
DispatchQueue.main.async {
|
||||||
Defaults.isRememberGitCredentialPassphraseOn = false
|
Utils.alert(title: "Error".localize(), message: "NoProperPassRepo.".localize(), controller: self)
|
||||||
self.passwordStore.gitPassword = nil
|
}
|
||||||
self.passwordStore.gitSSHPrivateKeyPassphrase = nil
|
|
||||||
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
alert.addAction(
|
|
||||||
UIAlertAction(title: "Yes".localize(), style: .destructive) { _ in
|
|
||||||
Defaults.isRememberGitCredentialPassphraseOn = true
|
|
||||||
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return alert
|
|
||||||
}()
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.present(savePassphraseAlert, animated: true)
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
SVProgressHUD.dismiss {
|
||||||
|
self.savePassphraseAndSegue()
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
SVProgressHUD.dismiss {
|
SVProgressHUD.dismiss {
|
||||||
|
self.passwordStore.eraseStoreData()
|
||||||
let error = error as NSError
|
let error = error as NSError
|
||||||
var message = error.localizedDescription
|
var message = error.localizedDescription
|
||||||
if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError {
|
if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError {
|
||||||
|
|
@ -231,6 +223,31 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func savePassphraseAndSegue() {
|
||||||
|
let savePassphraseAlert = UIAlertController(
|
||||||
|
title: "Done".localize(),
|
||||||
|
message: "WantToSaveGitCredential?".localize(),
|
||||||
|
preferredStyle: .alert
|
||||||
|
)
|
||||||
|
savePassphraseAlert.addAction(
|
||||||
|
UIAlertAction(title: "No".localize(), style: .default) { _ in
|
||||||
|
Defaults.isRememberGitCredentialPassphraseOn = false
|
||||||
|
self.passwordStore.gitPassword = nil
|
||||||
|
self.passwordStore.gitSSHPrivateKeyPassphrase = nil
|
||||||
|
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
savePassphraseAlert.addAction(
|
||||||
|
UIAlertAction(title: "Yes".localize(), style: .destructive) { _ in
|
||||||
|
Defaults.isRememberGitCredentialPassphraseOn = true
|
||||||
|
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.present(savePassphraseAlert, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@IBAction
|
@IBAction
|
||||||
private func importSSHKey(segue: UIStoryboardSegue) {
|
private func importSSHKey(segue: UIStoryboardSegue) {
|
||||||
guard let sourceController = segue.source as? KeyImporter, sourceController.isReadyToUse() else {
|
guard let sourceController = segue.source as? KeyImporter, sourceController.isReadyToUse() else {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@
|
||||||
"MakeSurePgpAndGitProperlySet." = "Stelle bitte sicher, dass die Einstellungen für GPG-Schlüssel und Git-Server richtig sind.";
|
"MakeSurePgpAndGitProperlySet." = "Stelle bitte sicher, dass die Einstellungen für GPG-Schlüssel und Git-Server richtig sind.";
|
||||||
"RecoverySuggestion." = "Das falsche Passwort wurde entfernt. Bitte probiere es erneut.";
|
"RecoverySuggestion." = "Das falsche Passwort wurde entfernt. Bitte probiere es erneut.";
|
||||||
"NSURLFileAllocatedSizeKeyShouldAlwaysReturnValue." = "Huh? NSURLFileAllocatedSizeKey sollte immer einen Wert liefern.";
|
"NSURLFileAllocatedSizeKeyShouldAlwaysReturnValue." = "Huh? NSURLFileAllocatedSizeKey sollte immer einen Wert liefern.";
|
||||||
|
"NoProperPassRepo." = "Das Repository enthält keine .gpg-id Datei. Es muss erst noch mit 'pass init' korrekt initialisiert werden, bevor es in die App geladen werden kann.";
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
"PasswordGeneratorFlavor" = "Art";
|
"PasswordGeneratorFlavor" = "Art";
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@
|
||||||
"MakeSurePgpAndGitProperlySet." = "Please make sure PGP key and Git server are properly set.";
|
"MakeSurePgpAndGitProperlySet." = "Please make sure PGP key and Git server are properly set.";
|
||||||
"RecoverySuggestion." = "Recovery suggestion: Wrong credential password/passphrase has been removed, please try again.";
|
"RecoverySuggestion." = "Recovery suggestion: Wrong credential password/passphrase has been removed, please try again.";
|
||||||
"NSURLFileAllocatedSizeKeyShouldAlwaysReturnValue." = "Huh? NSURLFileAllocatedSizeKey should always return a value.";
|
"NSURLFileAllocatedSizeKeyShouldAlwaysReturnValue." = "Huh? NSURLFileAllocatedSizeKey should always return a value.";
|
||||||
|
"NoProperPassRepo." = "The repository does not contain a .gpg-id file. Please set it up properly by performing 'pass init'. Then try again to load it into the app.";
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
"PasswordGeneratorFlavor" = "Style";
|
"PasswordGeneratorFlavor" = "Style";
|
||||||
|
|
|
||||||
|
|
@ -618,32 +618,36 @@ public class PasswordStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func erase() {
|
public func eraseStoreData() {
|
||||||
// Delete files.
|
// Delete files.
|
||||||
try? fileManager.removeItem(at: storeURL)
|
try? fileManager.removeItem(at: storeURL)
|
||||||
try? fileManager.removeItem(at: tempStoreURL)
|
try? fileManager.removeItem(at: tempStoreURL)
|
||||||
|
|
||||||
// Delete PGP key, SSH key and other secrets from the keychain.
|
|
||||||
AppKeychain.shared.removeAllContent()
|
|
||||||
|
|
||||||
// Delete core data.
|
// Delete core data.
|
||||||
deleteCoreData(entityName: "PasswordEntity")
|
deleteCoreData(entityName: "PasswordEntity")
|
||||||
|
|
||||||
// Delete default settings.
|
|
||||||
Defaults.removeAll()
|
|
||||||
|
|
||||||
// Clean up variables inside PasswordStore.
|
// Clean up variables inside PasswordStore.
|
||||||
storeRepository = nil
|
storeRepository = nil
|
||||||
|
|
||||||
// Delete cache explicitly.
|
|
||||||
PasscodeLock.shared.delete()
|
|
||||||
PGPAgent.shared.uninitKeys()
|
|
||||||
|
|
||||||
// Broadcast.
|
// Broadcast.
|
||||||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||||
NotificationCenter.default.post(name: .passwordStoreErased, object: nil)
|
NotificationCenter.default.post(name: .passwordStoreErased, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func erase() {
|
||||||
|
eraseStoreData()
|
||||||
|
|
||||||
|
// Delete PGP key, SSH key and other secrets from the keychain.
|
||||||
|
AppKeychain.shared.removeAllContent()
|
||||||
|
|
||||||
|
// Delete default settings.
|
||||||
|
Defaults.removeAll()
|
||||||
|
|
||||||
|
// Delete cache explicitly.
|
||||||
|
PasscodeLock.shared.delete()
|
||||||
|
PGPAgent.shared.uninitKeys()
|
||||||
|
}
|
||||||
|
|
||||||
// return the number of discarded commits
|
// return the number of discarded commits
|
||||||
public func reset() throws -> Int {
|
public func reset() throws -> Int {
|
||||||
guard let storeRepository = storeRepository else {
|
guard let storeRepository = storeRepository else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue