From 1ec26a0eea5a05e5c117d865f7e3d5258d6c874b Mon Sep 17 00:00:00 2001 From: Yishi Lin Date: Fri, 19 Jul 2019 01:46:56 +0800 Subject: [PATCH] Clean up very old migration codes --- passKit/Helpers/Globals.swift | 10 ------- passKit/Models/PasswordStore.swift | 47 ++---------------------------- 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/passKit/Helpers/Globals.swift b/passKit/Helpers/Globals.swift index 483b052..0a824c7 100644 --- a/passKit/Helpers/Globals.swift +++ b/passKit/Helpers/Globals.swift @@ -10,16 +10,6 @@ import Foundation import UIKit public class Globals { - - // Legacy paths (not shared) - public static let documentPathLegacy = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]; - public static let libraryPathLegacy = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]; - public static let pgpPublicKeyPathLegacy = "\(documentPathLegacy)/gpg_key.pub" - public static let pgpPrivateKeyPathLegacy = "\(documentPathLegacy)/gpg_key" - public static let gitSSHPrivateKeyPathLegacy = "\(documentPathLegacy)/ssh_key" - public static let gitSSHPrivateKeyURLLegacy = URL(fileURLWithPath: gitSSHPrivateKeyPathLegacy) - public static let repositoryPathLegacy = "\(libraryPathLegacy)/password-store" - public static let bundleIdentifier = "me.mssun.passforios" public static let groupIdentifier = "group." + bundleIdentifier public static let passKitBundleIdentifier = bundleIdentifier + ".passKit" diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index a3a2887..79504fb 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -106,9 +106,7 @@ public class PasswordStore { private init() { self.pgpAgent = PGPAgent() - // File migration to group - migrateIfNeeded() - backwardCompatibility() + // Migration importExistingKeysIntoKeychain() do { @@ -120,50 +118,9 @@ public class PasswordStore { print(error) } } - - private func migrateIfNeeded() { - // migrate happens only if the repository was cloned and pgp keys were set up using earlier versions - let needMigration = !pgpKeyExists() && !fm.fileExists(atPath: Globals.gitSSHPrivateKeyPath) && !fm.fileExists(atPath: Globals.repositoryPath) && fm.fileExists(atPath: Globals.repositoryPathLegacy) - guard needMigration == true else { - return - } - - do { - // migrate Defaults - let userDefaults = UserDefaults() - for key in Defaults.dictionaryRepresentation().keys { - if SharedDefaults.value(forKey: key) == nil { - SharedDefaults.setValue(userDefaults.value(forKey: key), forKey: key) - } - } - - // migrate files - try fm.createDirectory(atPath: Globals.documentPath, withIntermediateDirectories: true, attributes: nil) - try fm.createDirectory(atPath: Globals.libraryPath, withIntermediateDirectories: true, attributes: nil) - if fm.fileExists(atPath: Globals.pgpPublicKeyPathLegacy) { - try fm.moveItem(atPath: Globals.pgpPublicKeyPathLegacy, toPath: Globals.pgpPublicKeyPath) - } - if fm.fileExists(atPath: Globals.pgpPrivateKeyPathLegacy) { - try fm.moveItem(atPath: Globals.pgpPrivateKeyPathLegacy, toPath: Globals.pgpPrivateKeyPath) - } - if fm.fileExists(atPath: Globals.gitSSHPrivateKeyPathLegacy) { - try fm.moveItem(atPath: Globals.gitSSHPrivateKeyPathLegacy, toPath: Globals.gitSSHPrivateKeyPath) - } - try fm.moveItem(atPath: Globals.repositoryPathLegacy, toPath: Globals.repositoryPath) - } catch { - print("MigrationError".localize(error)) - } - updatePasswordEntityCoreData() - } - - private func backwardCompatibility() { - // For the newly-introduced isRememberGitCredentialPassphraseOn (20171008) - if (self.gitPassword != nil || self.gitSSHPrivateKeyPassphrase != nil) && SharedDefaults[.isRememberGitCredentialPassphraseOn] == false { - SharedDefaults[.isRememberGitCredentialPassphraseOn] = true - } - } private func importExistingKeysIntoKeychain() { + // App Store update: v0.5.1 -> v0.6.0 try? KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyAndDeleteFile() try? KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyAndDeleteFile() try? KeyFileManager(keyType: SshKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyAndDeleteFile()