From e4e4c6daffea313389871193175998b08ae993e0 Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Wed, 26 Jun 2019 21:49:29 +0200 Subject: [PATCH] Implement migration of existing PGP keys into Keychain --- passKit/Models/PasswordStore.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index 3e7f91d..7dc901e 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -126,6 +126,7 @@ public class PasswordStore { // File migration to group migrateIfNeeded() backwardCompatibility() + importExistingKeysIntoKeychain() do { if fm.fileExists(atPath: storeURL.path) { @@ -182,6 +183,15 @@ public class PasswordStore { SharedDefaults[.isRememberPGPPassphraseOn] = true } } + + private func importExistingKeysIntoKeychain() { + if let publicKey = fm.contents(atPath: Globals.pgpPublicKeyPath) { + Utils.addDataToKeychain(key: PGPKeyType.PUBLIC.rawValue, data: publicKey) + } + if let privateKey = fm.contents(atPath: Globals.pgpPrivateKeyPath) { + Utils.addDataToKeychain(key: PGPKeyType.PRIVATE.rawValue, data: privateKey) + } + } enum SSHKeyType { case `public`, secret