Keep global constants for armor keys and clean them up during migration and user initiated key removal

This commit is contained in:
Danny Moesch 2019-07-02 19:34:12 +02:00 committed by Mingshen Sun
parent 7bee780b46
commit 5f19c348c8
2 changed files with 8 additions and 0 deletions

View file

@ -16,6 +16,10 @@ public extension DefaultsKeys {
static let pgpPublicKeyURL = DefaultsKey<URL?>("pgpPublicKeyURL")
static let pgpPrivateKeyURL = DefaultsKey<URL?>("pgpPrivateKeyURL")
// Keep them for legacy reasons.
static let pgpPublicKeyArmor = DefaultsKey<String?>("pgpPublicKeyArmor")
static let pgpPrivateKeyArmor = DefaultsKey<String?>("pgpPrivateKeyArmor")
static let gitURL = DefaultsKey<URL?>("gitURL")
static let gitAuthenticationMethod = DefaultsKey<String?>("gitAuthenticationMethod")
static let gitUsername = DefaultsKey<String?>("gitUsername")

View file

@ -190,6 +190,8 @@ public class PasswordStore {
do {
try KeyFileManager(keyType: PgpKeyType.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyAndDeleteFile()
try KeyFileManager(keyType: PgpKeyType.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyAndDeleteFile()
SharedDefaults.remove(.pgpPublicKeyArmor)
SharedDefaults.remove(.pgpPrivateKeyArmor)
SharedDefaults[.pgpKeySource] = "file"
} catch {
print("MigrationError".localize(error))
@ -838,6 +840,8 @@ public class PasswordStore {
SharedDefaults.remove(.pgpKeySource)
SharedDefaults.remove(.pgpPrivateKeyURL)
SharedDefaults.remove(.pgpPublicKeyURL)
SharedDefaults.remove(.pgpPublicKeyArmor)
SharedDefaults.remove(.pgpPrivateKeyArmor)
AppKeychain.removeContent(for: "pgpKeyPassphrase")
AppKeychain.removeContent(for: PgpKeyType.PUBLIC.getKeychainKey())
AppKeychain.removeContent(for: PgpKeyType.PRIVATE.getKeychainKey())