Cleanup and fix the erase logic

Explicitly uninit PGP agent during erasing all data.
This commit is contained in:
Yishi Lin 2019-10-01 00:40:33 +08:00
parent 230b421a90
commit e0c32003e3
2 changed files with 15 additions and 8 deletions

View file

@ -21,6 +21,7 @@ public class PGPAgent {
public func initKeys() throws {
guard let publicKey: String = keyStore.get(for: PgpKey.PUBLIC.getKeychainKey()),
let privateKey: String = keyStore.get(for: PgpKey.PRIVATE.getKeychainKey()) else {
pgpInterface = nil
throw AppError.KeyImport
}
do {

View file

@ -630,22 +630,28 @@ public class PasswordStore {
}
}
public func erase() {try? fm.removeItem(at: storeURL)
public func erase() {
// Delete files.
try? fm.removeItem(at: storeURL)
try? fm.removeItem(at: tempStoreURL)
try? fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath)
AppKeychain.shared.removeContent(for: PgpKey.PUBLIC.getKeychainKey())
AppKeychain.shared.removeContent(for: PgpKey.PRIVATE.getKeychainKey())
// Delete PGP key, SSH key and other secrets from the keychain.
AppKeychain.shared.removeAllContent()
// Delete core data.
deleteCoreData(entityName: "PasswordEntity")
// Delete default settings.
SharedDefaults.removeAll()
storeRepository = nil
PasscodeLock.shared.delete() // delete the passcode cache
// Clean up variables inside PasswordStore.
storeRepository = nil
// Delete cache explicitly.
PasscodeLock.shared.delete()
PGPAgent.shared.uninitKeys()
// Broadcast.
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
NotificationCenter.default.post(name: .passwordStoreErased, object: nil)
}