diff --git a/pass/de.lproj/Localizable.strings b/pass/de.lproj/Localizable.strings index c62563f..8d9ffdf 100644 --- a/pass/de.lproj/Localizable.strings +++ b/pass/de.lproj/Localizable.strings @@ -60,6 +60,7 @@ "FailureToSaveContext" = "Fehler beim Speichern des Kontexts: %@"; "RepositoryRemoteMasterNotFoundError." = "Remote-Branch origin/master wurde nicht gefunden."; "KeyImportError." = "Schlüssel kann nicht importiert werden."; +"FileNotFoundError." = "Die Datei '%@' kann nicht gelesen werden."; "PasswordDuplicatedError." = "Passwort kann nicht hinzugefügt werden; es existiert bereits."; "GitResetError." = "Der zuletzt synchronisierte Commit kann nicht identifiziert werden."; "PGPPublicKeyNotExistError." = "Der öffentliche PGP-Schlüssen existiert nicht"; diff --git a/pass/en.lproj/Localizable.strings b/pass/en.lproj/Localizable.strings index 2dbf5af..4d5b802 100644 --- a/pass/en.lproj/Localizable.strings +++ b/pass/en.lproj/Localizable.strings @@ -61,6 +61,7 @@ "RepositoryRemoteBranchNotFoundError." = "Cannot find remote branch %@."; "RepositoryBranchNotFoundError." = "Branch %@ not found in repository."; "KeyImportError." = "Cannot import the key."; +"FileNotFoundError." = "File '%@' cannot be read."; "PasswordDuplicatedError." = "Cannot add the password; password is duplicated."; "GitResetError." = "Cannot identify the latest synced commit."; "PgpPublicKeyNotExistError." = "PGP public key doesn't exist."; diff --git a/passKit/Helpers/AppError.swift b/passKit/Helpers/AppError.swift index 0bfd694..cb3854a 100644 --- a/passKit/Helpers/AppError.swift +++ b/passKit/Helpers/AppError.swift @@ -11,6 +11,7 @@ public enum AppError: Error { case RepositoryRemoteBranchNotFound(_: String) case RepositoryBranchNotFound(_: String) case KeyImport + case ReadingFile(_: String) case PasswordDuplicated case GitReset case GitCommit @@ -26,7 +27,7 @@ extension AppError: LocalizedError { public var errorDescription: String? { let localizationKey = "\(String(describing: self).prefix(while: { $0 != "(" }))Error." switch self { - case let .RepositoryRemoteBranchNotFound(name), let .RepositoryBranchNotFound(name): + case let .RepositoryRemoteBranchNotFound(name), let .RepositoryBranchNotFound(name), let .ReadingFile(name): return localizationKey.localize(name) default: return localizationKey.localize() diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index 5ef5aaa..b51b77b 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -883,16 +883,16 @@ public class PasswordStore { } public func pgpKeyImportFromFileSharing() throws { - let publicKeyFileUrl = URL(fileURLWithPath: Globals.iTunesFileSharingPGPPublic) - let privateKeyFileUrl = URL(fileURLWithPath: Globals.iTunesFileSharingPGPPrivate) - - let publicKeyFileContent = try Data(contentsOf: publicKeyFileUrl) - let privateKeyFileContent = try Data(contentsOf: privateKeyFileUrl) - + guard let publicKeyFileContent = fm.contents(atPath: Globals.iTunesFileSharingPGPPublic) else { + throw AppError.ReadingFile(Globals.iTunesFileSharingPGPPublic) + } AppKeychain.add(data: publicKeyFileContent, for: PGPKeyType.PUBLIC.rawValue) - AppKeychain.add(data: privateKeyFileContent, for: PGPKeyType.PRIVATE.rawValue) + try fm.removeItem(atPath: Globals.iTunesFileSharingPGPPublic) - try fm.removeItem(at: publicKeyFileUrl) - try fm.removeItem(at: privateKeyFileUrl) + guard let privateKeyFileContent = fm.contents(atPath: Globals.iTunesFileSharingPGPPrivate) else { + throw AppError.ReadingFile(Globals.iTunesFileSharingPGPPrivate) + } + AppKeychain.add(data: privateKeyFileContent, for: PGPKeyType.PRIVATE.rawValue) + try fm.removeItem(atPath: Globals.iTunesFileSharingPGPPrivate) } }