From f0003227d53efb4128b4f867f582ba0f3defab80 Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Wed, 26 Jun 2019 22:57:06 +0200 Subject: [PATCH] Delete key files after migrating them to Keychain --- passKit/Models/PasswordStore.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index 010c072..5ef5aaa 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -191,11 +191,18 @@ public class PasswordStore { } private func importExistingKeysIntoKeychain() { - if let publicKey = fm.contents(atPath: Globals.pgpPublicKeyPath) { - AppKeychain.add(data: publicKey, for: PGPKeyType.PUBLIC.rawValue) - } - if let privateKey = fm.contents(atPath: Globals.pgpPrivateKeyPath) { - AppKeychain.add(data: privateKey, for: PGPKeyType.PRIVATE.rawValue) + do { + if let publicKey = fm.contents(atPath: Globals.pgpPublicKeyPath) { + AppKeychain.add(data: publicKey, for: PGPKeyType.PUBLIC.rawValue) + try fm.removeItem(atPath: Globals.pgpPublicKeyPath) + } + if let privateKey = fm.contents(atPath: Globals.pgpPrivateKeyPath) { + AppKeychain.add(data: privateKey, for: PGPKeyType.PRIVATE.rawValue) + try fm.removeItem(atPath: Globals.pgpPrivateKeyPath) + } + SharedDefaults[.pgpKeySource] = "file" + } catch { + print("MigrationError".localize(error)) } }