Encrypt tagged entries on save; whole-file encryption !489
35 files changed, +3857 −103
Changed files (35)
- Sources/OrgApp/ClockModel.swift +14 −4
- Sources/OrgApp/CryptPassphrases.swift +161 −17
- Sources/OrgApp/CryptSheet.swift +87 −11
- Sources/OrgApp/DocumentSession.swift +323 −13
- Sources/OrgApp/Handoff.swift +2
- Sources/OrgApp/LinkFollow.swift +1 −1
- Sources/OrgApp/OrgPreferences.swift +4
- Sources/OrgApp/SubtreeShare.swift +50 −3
- Sources/OrgApp/UserConfig.swift +2
- Sources/OrgCore/Commands/Archive.swift +6 −1
- Sources/OrgCore/Commands/ClockHistory.swift +19 −2
- Sources/OrgCore/Crypto/OpenPGP.swift +93 −13
- Sources/OrgCore/Crypto/OrgCrypt.swift +108 −1
- Sources/OrgDocument/Crypt.swift added +328
- Sources/OrgDocument/Saving.swift +30 −5
- Sources/Orgstar/ContentView.swift +25 −10
- Sources/Orgstar/CryptHoldBar.swift added +45
- Sources/Orgstar/EditorWindowView.swift +1
- Sources/Orgstar/OrgstarApp.swift +62 −5
- Sources/OrgstarMobile/EditorScreen.swift +39 −6
- Sources/OrgstarMobile/ExportMenu.swift +10 −5
- Sources/OrgstarMobile/FoldersScreen.swift +1 −1
- Sources/OrgstarMobile/MobileModel.swift +2
- Sources/OrgstarMobile/OrgstarMobileApp.swift +8 −1
- Sources/OrgstarMobile/ReaderScreen.swift +23
- Sources/OrgstarMobile/UnsavedHeldFiles.swift added +23
- Tests/OrgAppTests/CryptReviewTests.swift added +382
- Tests/OrgAppTests/CryptSaveTests.swift added +346
- Tests/OrgCoreTests/CryptFileTests.swift added +163
- Tests/OrgDocumentTests/CryptSaverTests.swift added +63
- docs/manual/guide/04-outlines.org +34 −1
- docs/manual/guide/13-configuration.org +2 −1
- docs/manual/guide/14-ios.org +3 −1
- docs/manual/guide/15-alongside-emacs.org +2 −1
- l10n/Localizable.xcstrings +1395
Sources/OrgApp/ClockModel.swift +14 −4 · view
| @@ -100,7 +100,7 @@ public final class ClockModel { | ||
| 100 | 100 | let interrupted = runningTask(session) |
| 101 | 101 | let message = clockOut(session, now: now) |
| 102 | 102 | if self.running != nil { return message } |
| 103 | interruptedTask = interrupted | |
| 103 | interruptedTask = interrupted.map { Self.shareable($0, session) } | |
| 104 | 104 | // Clocking out may have moved the entry. |
| 105 | 105 | let target = ClockTask(path: path, title: entry.title, ordinal: index, id: entry.id) |
| 106 | 106 | guard let moved = Self.text(path, session).flatMap(target.locate) else { return "Can't find \(entry.title) after clocking out." } |
| @@ -114,7 +114,7 @@ public final class ClockModel { | ||
| 114 | 114 | guard let updated = Self.text(path, session), let start = ClockIn.runningStart(in: updated, near: heading) else { |
| 115 | 115 | return "The clock line wasn't found after clocking in." |
| 116 | 116 | } |
| 117 | running = Running(path: path, start: start, heading: entry.title, startedAt: now) | |
| 117 | running = Running(path: path, start: start, heading: session.shareableTitle(entry.title, path: path, heading: heading), startedAt: now) | |
| 118 | 118 | if let task = ClockTask.at(heading, in: updated, path: path) { push(task, session) } |
| 119 | 119 | save() |
| 120 | 120 | watched = clockedHeading(path, session) |
| @@ -307,7 +307,16 @@ public final class ClockModel { | ||
| 307 | 307 | // MARK: - History |
| 308 | 308 | |
| 309 | 309 | private func push(_ task: ClockTask, _ session: DocumentSession) { |
| 310 | // The history is kept in the clock's file and shown by the widgets. | |
| 310 | 311 | history = ClockHistory.push(task, onto: history, length: OrgPreferences.clockHistoryLength(defaults)) { Self.text($0, session) } |
| 312 | .map { Self.shareable($0, session) } | |
| 313 | } | |
| 314 | ||
| 315 | /// `task` with a placeholder title when its heading is encrypted on disk. | |
| 316 | static func shareable(_ task: ClockTask, _ session: DocumentSession) -> ClockTask { | |
| 317 | guard task.titleHash == nil, let heading = text(task.path, session).flatMap(task.locate) else { return task } | |
| 318 | let shown = session.shareableTitle(task.title, path: task.path, heading: heading) | |
| 319 | return shown == task.title ? task : task.hiding(shown) | |
| 311 | 320 | } |
| 312 | 321 | |
| 313 | 322 | /// Where a remembered entry's heading is now. |
| @@ -325,7 +334,7 @@ public final class ClockModel { | ||
| 325 | 334 | public func markDefault(_ session: DocumentSession, path: String, at offset: Int) -> String { |
| 326 | 335 | guard let text = Self.text(path, session) else { return "Can't read \(path)" } |
| 327 | 336 | guard let task = ClockTask.at(offset, in: text, path: path) else { return "Before first headline" } |
| 328 | defaultTask = task | |
| 337 | defaultTask = Self.shareable(task, session) | |
| 329 | 338 | return "Default clock task: \(task.title)" |
| 330 | 339 | } |
| 331 | 340 | |
| @@ -527,7 +536,8 @@ public final class ClockModel { | ||
| 527 | 536 | let headings = DocumentModel(tree: OrgParser.parse(text)).headings |
| 528 | 537 | for clock in open { |
| 529 | 538 | guard let startedAt = ClockResolution.date(of: clock.start) else { continue } |
| 530 | let heading = headings.last { $0.headingRange.lowerBound <= clock.offset }?.title ?? "" | |
| 539 | let entry = headings.last { $0.headingRange.lowerBound <= clock.offset } | |
| 540 | let heading = entry.map { session.shareableTitle($0.title, path: path, heading: $0.headingRange.lowerBound) } ?? "" | |
| 531 | 541 | clocks.append(OpenClock(path: path, start: clock.start, startedAt: startedAt, heading: heading)) |
| 532 | 542 | } |
| 533 | 543 | } |
Sources/OrgApp/CryptPassphrases.swift +161 −17 · view
| @@ -1,44 +1,188 @@ | ||
| 1 | 1 | import Foundation |
| 2 | 2 | import LocalAuthentication |
| 3 | import OrgDocument | |
| 3 | 4 | import Security |
| 4 | 5 | |
| 5 | /// Passphrases for encrypted entries, kept in the Keychain by file when asked, and given back | |
| 6 | /// only after Touch ID, Face ID or the device's password. | |
| 6 | /// Passphrases for encrypted entries and files, kept in the Keychain by file path when asked. | |
| 7 | /// Items are readable only on this device while it's unlocked, and only after Touch ID, Face | |
| 8 | /// ID or the device's password (`.userPresence`), asked once per file while it's open. Items | |
| 9 | /// earlier versions stored without that move over at their first read. A build without a | |
| 10 | /// Keychain entitlement (the Developer ID Mac app) can't make such items and keeps the old kind. | |
| 11 | @MainActor | |
| 7 | 12 | public enum CryptPassphrases { |
| 8 | static let service = "sh.krz.orgstar.crypt" | |
| 13 | nonisolated static let service = "sh.krz.orgstar.crypt.v2" | |
| 14 | /// Where earlier versions kept passphrases, readable without authentication. | |
| 15 | nonisolated static let legacyService = "sh.krz.orgstar.crypt" | |
| 16 | /// Whether this build can keep passphrases limited to this device: the Developer ID Mac app | |
| 17 | /// has no Keychain entitlement and keeps them in the login keychain. | |
| 18 | public static var protectsItems: Bool { | |
| 19 | #if os(macOS) && !APPSTORE | |
| 20 | false | |
| 21 | #else | |
| 22 | true | |
| 23 | #endif | |
| 24 | } | |
| 25 | ||
| 26 | /// Said beside Remember in the Keychain where `protectsItems` is false. | |
| 27 | public static var caveat: String { | |
| 28 | String(localized: "This version of orgstar keeps remembered passphrases in your login keychain without limiting them to this Mac; Touch ID or your password is still asked before one is used.") | |
| 29 | } | |
| 30 | ||
| 31 | /// A Keychain query handed to the thread that waits on it; nothing else uses it meanwhile. | |
| 32 | struct Request: @unchecked Sendable { | |
| 33 | let query: [String: Any] | |
| 34 | } | |
| 35 | ||
| 36 | /// One authentication per file while it's open; `endSession` ends it. | |
| 37 | private static var contexts: [String: LAContext] = [:] | |
| 38 | ||
| 39 | static func context(for path: String) -> LAContext { | |
| 40 | if let context = contexts[path] { return context } | |
| 41 | let context = LAContext() | |
| 42 | contexts[path] = context | |
| 43 | return context | |
| 44 | } | |
| 45 | ||
| 46 | /// The file closed: its authentication no longer reads its passphrase. | |
| 47 | public static func endSession(for path: String) { | |
| 48 | contexts.removeValue(forKey: path)?.invalidate() | |
| 49 | } | |
| 9 | 50 | |
| 10 | static func query(_ path: String) -> [String: Any] { | |
| 11 | [kSecClass as String: kSecClassGenericPassword, kSecAttrService as String: service, kSecAttrAccount as String: path] | |
| 51 | nonisolated static func query(_ path: String, service: String = service) -> [String: Any] { | |
| 52 | var query: [String: Any] = [kSecClass as String: kSecClassGenericPassword, kSecAttrService as String: service, kSecAttrAccount as String: path] | |
| 53 | if service == Self.service { query[kSecUseDataProtectionKeychain as String] = true } | |
| 54 | return query | |
| 12 | 55 | } |
| 13 | 56 | |
| 14 | public static func store(_ passphrase: String, for path: String) { | |
| 15 | forget(path) | |
| 57 | /// The new item for `passphrase`: this device only, unlocked, after user presence. | |
| 58 | nonisolated static func newItem(_ passphrase: String, for path: String) -> [String: Any]? { | |
| 59 | guard let access = SecAccessControlCreateWithFlags(nil, kSecAttrAccessibleWhenUnlockedThisDeviceOnly, .userPresence, nil) else { return nil } | |
| 16 | 60 | var item = query(path) |
| 17 | 61 | item[kSecValueData as String] = Data(passphrase.utf8) |
| 18 | item[kSecAttrLabel as String] = "orgstar: encrypted entries in " + (path as NSString).lastPathComponent | |
| 19 | SecItemAdd(item as CFDictionary, nil) | |
| 62 | item[kSecAttrAccessControl as String] = access | |
| 63 | item[kSecAttrLabel as String] = "orgstar: passphrase for " + (path as NSString).lastPathComponent | |
| 64 | return item | |
| 65 | } | |
| 66 | ||
| 67 | /// Adds `item`, in place of one there already. | |
| 68 | nonisolated static func add(_ item: [String: Any], replacing query: [String: Any]) -> OSStatus { | |
| 69 | var status = SecItemAdd(item as CFDictionary, nil) | |
| 70 | if status == errSecDuplicateItem { | |
| 71 | SecItemDelete(query as CFDictionary) | |
| 72 | status = SecItemAdd(item as CFDictionary, nil) | |
| 73 | } | |
| 74 | return status | |
| 75 | } | |
| 76 | ||
| 77 | /// Remembers `passphrase` for `path`. A message to show when it wasn't kept; nil otherwise. | |
| 78 | @discardableResult | |
| 79 | public static func store(_ passphrase: String, for path: String) -> String? { | |
| 80 | guard let item = newItem(passphrase, for: path) else { return String(localized: "The passphrase wasn't remembered: the Keychain refused it.") } | |
| 81 | let status = add(item, replacing: query(path)) | |
| 82 | if status == errSecSuccess { | |
| 83 | SecItemDelete(query(path, service: legacyService) as CFDictionary) | |
| 84 | return nil | |
| 85 | } | |
| 86 | guard status == errSecMissingEntitlement else { return String(localized: "The passphrase wasn't remembered: the Keychain refused it.") } | |
| 87 | var legacy = query(path, service: legacyService) | |
| 88 | legacy[kSecValueData as String] = Data(passphrase.utf8) | |
| 89 | legacy[kSecAttrLabel as String] = item[kSecAttrLabel as String] | |
| 90 | guard add(legacy, replacing: query(path, service: legacyService)) == errSecSuccess else { | |
| 91 | return String(localized: "The passphrase wasn't remembered: the Keychain refused it.") | |
| 92 | } | |
| 93 | SecItemDelete(query(path) as CFDictionary) | |
| 94 | return nil | |
| 20 | 95 | } |
| 21 | 96 | |
| 22 | 97 | public static func forget(_ path: String) { |
| 98 | endSession(for: path) | |
| 23 | 99 | SecItemDelete(query(path) as CFDictionary) |
| 100 | SecItemDelete(query(path, service: legacyService) as CFDictionary) | |
| 24 | 101 | } |
| 25 | 102 | |
| 26 | public static func hasStored(_ path: String) -> Bool { | |
| 27 | var q = query(path) | |
| 103 | /// Whether an item exists, without asking for authentication. | |
| 104 | nonisolated static func exists(_ query: [String: Any]) -> Bool { | |
| 105 | var q = query | |
| 106 | let quiet = LAContext() | |
| 107 | quiet.interactionNotAllowed = true | |
| 108 | q[kSecUseAuthenticationContext as String] = quiet | |
| 28 | 109 | q[kSecReturnAttributes as String] = true |
| 29 | return SecItemCopyMatching(q as CFDictionary, nil) == errSecSuccess | |
| 110 | let status = SecItemCopyMatching(q as CFDictionary, nil) | |
| 111 | return status == errSecSuccess || status == errSecInteractionNotAllowed | |
| 112 | } | |
| 113 | ||
| 114 | public static func hasStored(_ path: String) -> Bool { | |
| 115 | exists(query(path)) || exists(query(path, service: legacyService)) | |
| 30 | 116 | } |
| 31 | 117 | |
| 32 | 118 | /// The stored passphrase, once the person has proved who they are; nil otherwise. |
| 33 | 119 | public static func stored(for path: String) async -> String? { |
| 34 | guard hasStored(path) else { return nil } | |
| 35 | let context = LAContext() | |
| 36 | let reason = "unlock the passphrase for encrypted entries in " + (path as NSString).lastPathComponent | |
| 120 | let reason = "unlock the passphrase for " + (path as NSString).lastPathComponent | |
| 121 | let context = context(for: path) | |
| 122 | if exists(query(path)) { | |
| 123 | var q = query(path) | |
| 124 | q[kSecReturnData as String] = true | |
| 125 | context.localizedReason = reason | |
| 126 | q[kSecUseAuthenticationContext as String] = context | |
| 127 | let request = Request(query: q) | |
| 128 | // The read waits for Touch ID or the password, off the main thread. | |
| 129 | return await Task.detached { () -> String? in | |
| 130 | var result: AnyObject? | |
| 131 | guard SecItemCopyMatching(request.query as CFDictionary, &result) == errSecSuccess, let data = result as? Data else { return nil } | |
| 132 | return String(decoding: data, as: UTF8.self) | |
| 133 | }.value | |
| 134 | } | |
| 135 | guard exists(query(path, service: legacyService)) else { return nil } | |
| 37 | 136 | guard (try? await context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason)) == true else { return nil } |
| 38 | var q = query(path) | |
| 137 | var q = query(path, service: legacyService) | |
| 39 | 138 | q[kSecReturnData as String] = true |
| 40 | 139 | var result: AnyObject? |
| 41 | 140 | guard SecItemCopyMatching(q as CFDictionary, &result) == errSecSuccess, let data = result as? Data else { return nil } |
| 42 | return String(decoding: data, as: UTF8.self) | |
| 141 | let passphrase = String(decoding: data, as: UTF8.self) | |
| 142 | // Moved to the protected kind of item; kept as it was where that can't be made. | |
| 143 | if let item = newItem(passphrase, for: path), add(item, replacing: query(path)) == errSecSuccess { | |
| 144 | SecItemDelete(query(path, service: legacyService) as CFDictionary) | |
| 145 | } | |
| 146 | return passphrase | |
| 147 | } | |
| 148 | } | |
| 149 | ||
| 150 | extension CryptHold { | |
| 151 | /// Whether giving the passphrase lets the file be saved. | |
| 152 | public var takesPassphrase: Bool { | |
| 153 | if case .blocked = self { return false } | |
| 154 | return true | |
| 155 | } | |
| 156 | ||
| 157 | /// What the held file's notice says. | |
| 158 | public func notice(for path: String) -> String { | |
| 159 | let name = (path as NSString).lastPathComponent | |
| 160 | return switch self { | |
| 161 | case .entries(1): String(localized: "1 tagged entry isn't encrypted. Changes to \(name) aren't saved until it is.") | |
| 162 | case .entries(let count): String(localized: "\(count) tagged entries aren't encrypted. Changes to \(name) aren't saved until they are.") | |
| 163 | case .file: String(localized: "\(name) isn't saved until it has a passphrase.") | |
| 164 | case .blocked(let reason): reason + ". " + String(localized: "Changes to \(name) aren't saved until that's fixed.") | |
| 165 | } | |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | extension CryptHold: LocalizedError { | |
| 170 | public var errorDescription: String? { | |
| 171 | switch self { | |
| 172 | case .entries(1): String(localized: "1 tagged entry isn't encrypted") | |
| 173 | case .entries(let count): String(localized: "\(count) tagged entries aren't encrypted") | |
| 174 | case .file: String(localized: "The file has no passphrase yet") | |
| 175 | case .blocked(let reason): reason | |
| 176 | } | |
| 177 | } | |
| 178 | } | |
| 179 | ||
| 180 | extension CryptReadError: LocalizedError { | |
| 181 | public var errorDescription: String? { | |
| 182 | switch self { | |
| 183 | case .locked: String(localized: "The file is encrypted, and its passphrase isn't known") | |
| 184 | case .wrongPassphrase: String(localized: "Wrong passphrase") | |
| 185 | case .failed(let reason): reason | |
| 186 | } | |
| 43 | 187 | } |
| 44 | 188 | } |
Sources/OrgApp/CryptSheet.swift +87 −11 · view
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import Foundation |
| 2 | 2 | import OrgCore |
| 3 | import OrgDocument | |
| 3 | 4 | import SwiftUI |
| 4 | 5 | |
| 5 | 6 | /// What an org-crypt command does with the entry at `offset` in the file at `path`. |
| @@ -13,6 +14,12 @@ public struct CryptRequest: Identifiable, Sendable { | ||
| 13 | 14 | case open |
| 14 | 15 | /// `org-decrypt-entry`: the decrypted text in the file. |
| 15 | 16 | case decryptInPlace |
| 17 | /// The passphrase a held save needs, to encrypt the tagged entries as the file is saved. | |
| 18 | case encryptOnSave | |
| 19 | /// The passphrase of an encrypted file (`.org.gpg`), to open it. | |
| 20 | case openFile | |
| 21 | /// The passphrase a new encrypted file is saved with. | |
| 22 | case newFile | |
| 16 | 23 | } |
| 17 | 24 | |
| 18 | 25 | public let id = UUID() |
| @@ -28,30 +35,48 @@ public struct CryptRequest: Identifiable, Sendable { | ||
| 28 | 35 | |
| 29 | 36 | var encrypting: Bool { |
| 30 | 37 | switch mode { |
| 31 | case .encrypt, .encryptAll: true | |
| 38 | case .encrypt, .encryptAll, .encryptOnSave, .newFile: true | |
| 32 | 39 | default: false |
| 33 | 40 | } |
| 34 | 41 | } |
| 42 | ||
| 43 | /// The passphrase goes to the session, which checks it and saves or opens the file. | |
| 44 | var unlocks: Bool { | |
| 45 | switch mode { | |
| 46 | case .encryptOnSave, .openFile, .newFile: true | |
| 47 | default: false | |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | /// The request for what keeps `path` from being saved. | |
| 52 | public static func save(_ path: String, hold: CryptHold) -> CryptRequest { | |
| 53 | CryptRequest(mode: hold == .file ? .newFile : .encryptOnSave, path: path, offset: 0) | |
| 54 | } | |
| 35 | 55 | } |
| 36 | 56 | |
| 37 | 57 | /// The passphrase for an org-crypt command, from the Keychain when it was remembered, then for |
| 38 | 58 | /// `open` the decrypted entry to edit. `text` is the file's text now; `apply` puts a new text |
| 39 | /// in its place; `done` closes the sheet with a message. | |
| 59 | /// in its place; `done` closes the sheet with a message. `session` learns the passphrase, so | |
| 60 | /// saves encrypt with it without asking again. | |
| 40 | 61 | public struct CryptSheet: View { |
| 41 | 62 | let request: CryptRequest |
| 63 | let session: DocumentSession? | |
| 42 | 64 | let text: () -> String |
| 43 | 65 | let apply: (String) -> Void |
| 44 | 66 | let done: (String?) -> Void |
| 45 | 67 | @State private var passphrase = "" |
| 46 | 68 | @State private var repeated = "" |
| 47 | 69 | @State private var remember = false |
| 70 | /// What the Keychain said when the passphrase was remembered, shown with the result. | |
| 71 | @State private var keychainNote: String? | |
| 48 | 72 | @State private var problem: String? |
| 49 | 73 | /// The decrypted entry being edited, and the passphrase it came with. |
| 50 | 74 | @State private var editing: (original: String, passphrase: String)? |
| 51 | 75 | @State private var plaintext = "" |
| 52 | 76 | |
| 53 | public init(request: CryptRequest, text: @escaping () -> String, apply: @escaping (String) -> Void, done: @escaping (String?) -> Void) { | |
| 77 | public init(request: CryptRequest, session: DocumentSession? = nil, text: @escaping () -> String, apply: @escaping (String) -> Void, done: @escaping (String?) -> Void) { | |
| 54 | 78 | self.request = request |
| 79 | self.session = session | |
| 55 | 80 | self.text = text |
| 56 | 81 | self.apply = apply |
| 57 | 82 | self.done = done |
| @@ -73,13 +98,17 @@ public struct CryptSheet: View { | ||
| 73 | 98 | } |
| 74 | 99 | } else { |
| 75 | 100 | Text(title).font(.headline) |
| 101 | if let explanation { Text(explanation).font(.callout).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true) } | |
| 76 | 102 | SecureField("Passphrase", text: $passphrase).onSubmit(submit) |
| 77 | if request.encrypting { SecureField("Repeat passphrase", text: $repeated).onSubmit(submit) } | |
| 103 | if asksTwice { SecureField("Repeat passphrase", text: $repeated).onSubmit(submit) } | |
| 78 | 104 | Toggle("Remember in the Keychain", isOn: $remember) |
| 105 | if !CryptPassphrases.protectsItems { | |
| 106 | Text(CryptPassphrases.caveat).font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true) | |
| 107 | } | |
| 79 | 108 | if let problem { Text(problem).foregroundStyle(.red).font(.callout) } |
| 80 | 109 | HStack { |
| 81 | 110 | Spacer() |
| 82 | Button("Cancel", role: .cancel) { done(nil) }.keyboardShortcut(.cancelAction) | |
| 111 | Button("Cancel", role: .cancel) { cancel() }.keyboardShortcut(.cancelAction) | |
| 83 | 112 | Button(request.encrypting ? "Encrypt" : "Decrypt") { submit() } |
| 84 | 113 | .keyboardShortcut(.defaultAction) |
| 85 | 114 | .disabled(passphrase.isEmpty) |
| @@ -102,16 +131,52 @@ public struct CryptSheet: View { | ||
| 102 | 131 | case .encrypt: "Encrypt Entry" |
| 103 | 132 | case .encryptAll: "Encrypt Tagged Entries" |
| 104 | 133 | case .open, .decryptInPlace: "Decrypt Entry" |
| 134 | case .encryptOnSave: String(localized: "Encrypt Tagged Entries") | |
| 135 | case .openFile: String(localized: "Decrypt File") | |
| 136 | case .newFile: String(localized: "Set Passphrase") | |
| 137 | } | |
| 138 | } | |
| 139 | ||
| 140 | private var name: String { (request.path as NSString).lastPathComponent } | |
| 141 | ||
| 142 | private var explanation: String? { | |
| 143 | switch request.mode { | |
| 144 | case .encryptOnSave: String(localized: "\(name) is saved with its tagged entries encrypted.") | |
| 145 | case .openFile: String(localized: "\(name) is encrypted.") | |
| 146 | case .newFile: String(localized: "\(name) is saved encrypted with this passphrase.") | |
| 147 | default: nil | |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 151 | /// A new passphrase is typed twice; one that must open what's encrypted already, once. | |
| 152 | private var asksTwice: Bool { | |
| 153 | switch request.mode { | |
| 154 | case .encryptOnSave: OrgCrypt.firstMessage(text()) == nil | |
| 155 | case .openFile: false | |
| 156 | default: request.encrypting | |
| 105 | 157 | } |
| 106 | 158 | } |
| 107 | 159 | |
| 108 | 160 | private func submit() { |
| 109 | 161 | guard !passphrase.isEmpty else { return } |
| 110 | if request.encrypting, passphrase != repeated { return problem = "The passphrases differ" } | |
| 162 | if asksTwice, passphrase != repeated { return problem = "The passphrases differ" } | |
| 111 | 163 | run(passphrase, remembered: false) |
| 112 | 164 | } |
| 113 | 165 | |
| 166 | private func cancel() { | |
| 167 | if case .openFile = request.mode { session?.cancelUnlock() } | |
| 168 | done(nil) | |
| 169 | } | |
| 170 | ||
| 114 | 171 | private func run(_ passphrase: String, remembered: Bool) { |
| 172 | if request.unlocks { | |
| 173 | if let failure = session?.unlock(passphrase, for: request.path) { return problem = failure } | |
| 174 | switch request.mode { | |
| 175 | case .encryptOnSave: return finish(String(localized: "Tagged entries encrypted and saved"), passphrase: passphrase, remembered: remembered) | |
| 176 | case .newFile: return finish(String(localized: "Saved encrypted"), passphrase: passphrase, remembered: remembered) | |
| 177 | default: return finish(nil, passphrase: passphrase, remembered: remembered) | |
| 178 | } | |
| 179 | } | |
| 115 | 180 | let current = text() |
| 116 | 181 | do { |
| 117 | 182 | switch request.mode { |
| @@ -127,22 +192,33 @@ public struct CryptSheet: View { | ||
| 127 | 192 | finish("Encrypted \(count) \(count == 1 ? "entry" : "entries")", passphrase: passphrase, remembered: remembered) |
| 128 | 193 | case .open: |
| 129 | 194 | let plain = try OrgCrypt.decrypt(current, at: request.offset, passphrase: passphrase).plaintext |
| 130 | if remember, !remembered { CryptPassphrases.store(passphrase, for: request.path) } | |
| 195 | if remember, !remembered { keychainNote = CryptPassphrases.store(passphrase, for: request.path) } | |
| 196 | session?.cryptUsed(passphrase, for: request.path) | |
| 131 | 197 | plaintext = plain |
| 132 | 198 | editing = (plain, passphrase) |
| 133 | 199 | problem = nil |
| 134 | 200 | case .decryptInPlace: |
| 135 | apply(try OrgCrypt.decryptInPlace(current, at: request.offset, passphrase: passphrase)) | |
| 201 | let message = OrgCrypt.encryptedRange(current, at: request.offset).map { (current as NSString).substring(with: NSRange($0)) } | |
| 202 | let decrypted = try OrgCrypt.decryptInPlace(current, at: request.offset, passphrase: passphrase) | |
| 203 | // Saved unchanged with org-crypt-use-before-save-magic, the entry gets its message back. | |
| 204 | if let message, let body = OrgCrypt.bodyRange(decrypted, at: request.offset) { | |
| 205 | session?.cryptDecrypted(message: message, plaintext: (decrypted as NSString).substring(with: NSRange(body)), for: request.path) | |
| 206 | } | |
| 207 | apply(decrypted) | |
| 136 | 208 | finish("Entry decrypted", passphrase: passphrase, remembered: remembered) |
| 209 | case .encryptOnSave, .openFile, .newFile: | |
| 210 | break | |
| 137 | 211 | } |
| 138 | 212 | } catch { |
| 139 | 213 | problem = "\(error)" |
| 140 | 214 | } |
| 141 | 215 | } |
| 142 | 216 | |
| 143 | private func finish(_ message: String, passphrase: String, remembered: Bool) { | |
| 144 | if remember, !remembered { CryptPassphrases.store(passphrase, for: request.path) } | |
| 145 | done(message) | |
| 217 | private func finish(_ message: String?, passphrase: String, remembered: Bool) { | |
| 218 | if remember, !remembered { keychainNote = CryptPassphrases.store(passphrase, for: request.path) } | |
| 219 | if !request.unlocks { session?.cryptUsed(passphrase, for: request.path) } | |
| 220 | let text = [message, keychainNote].compactMap { $0 }.joined(separator: " ") | |
| 221 | done(text.isEmpty ? nil : text) | |
| 146 | 222 | } |
| 147 | 223 | |
| 148 | 224 | /// The edited text encrypted again in the message's place; nothing changes if it wasn't edited. |
Sources/OrgApp/DocumentSession.swift +323 −13 · view
| @@ -137,8 +137,13 @@ public final class DocumentSession { | ||
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | /// Files and recovery through `crypt`, and as they are on disk. | |
| 140 | 141 | private let fileSystem: FileSystem |
| 141 | 142 | private let recovery: RecoveryStore |
| 143 | private let diskFileSystem: FileSystem | |
| 144 | private let diskRecovery: RecoveryStore | |
| 145 | /// Passphrases and encrypted entries of the open files. | |
| 146 | @ObservationIgnored public let crypt = CryptVault() | |
| 142 | 147 | @ObservationIgnored private var entries: [Entry] = [] |
| 143 | 148 | /// The focused pane's buffer. |
| 144 | 149 | private var current: Entry? { focused.path.flatMap(entry) } |
| @@ -151,13 +156,152 @@ public final class DocumentSession { | ||
| 151 | 156 | fileSystem: FileSystem = CoordinatedFileSystem(), |
| 152 | 157 | recovery: RecoveryStore = FileRecoveryStore(directory: WorkspaceModel.defaultDirectory.appendingPathComponent("Recovery")) |
| 153 | 158 | ) { |
| 154 | self.fileSystem = fileSystem | |
| 155 | self.recovery = recovery | |
| 159 | diskFileSystem = fileSystem | |
| 160 | diskRecovery = recovery | |
| 161 | self.fileSystem = CryptFileSystem(base: fileSystem, vault: crypt) | |
| 162 | self.recovery = CryptRecoveryStore(base: recovery, vault: crypt) | |
| 156 | 163 | let pane = EditorPane() |
| 157 | 164 | panes = [pane] |
| 158 | 165 | focused = pane |
| 159 | 166 | } |
| 160 | 167 | |
| 168 | // MARK: - Encryption | |
| 169 | ||
| 170 | /// `org-crypt-use-before-save-magic`: entries with `cryptTag` are encrypted on every save. | |
| 171 | public var encryptsTaggedEntries: Bool { | |
| 172 | get { crypt.encryptsTaggedEntries } | |
| 173 | set { crypt.encryptsTaggedEntries = newValue } | |
| 174 | } | |
| 175 | ||
| 176 | /// `org-crypt-tag-matcher`. | |
| 177 | public var cryptTag: String { | |
| 178 | get { crypt.tag } | |
| 179 | set { crypt.tag = newValue } | |
| 180 | } | |
| 181 | ||
| 182 | /// Open files that aren't saved until a passphrase is given: tagged entries that would be | |
| 183 | /// written unencrypted, or an encrypted file without one. Other edits to them wait too. | |
| 184 | public private(set) var held: [String: CryptHold] = [:] | |
| 185 | /// Holds from saves that failed: a version on disk with tagged entries that can't be kept | |
| 186 | /// encrypted, or an entry the passphrase can't encrypt. Kept until a save succeeds. | |
| 187 | @ObservationIgnored private var failedHolds: [String: CryptHold] = [:] | |
| 188 | ||
| 189 | /// An encrypted file waiting for its passphrase to open, and the pane to show it in. | |
| 190 | public private(set) var unlockRequest: String? | |
| 191 | @ObservationIgnored private var unlockPane: EditorPane? | |
| 192 | ||
| 193 | /// The passphrase remembered in the Keychain, after Touch ID, Face ID or the device's | |
| 194 | /// password; nil when there's none or it wasn't given. | |
| 195 | @ObservationIgnored public var storedPassphrase: (String) async -> String? = { await CryptPassphrases.stored(for: $0) } | |
| 196 | @ObservationIgnored public var hasStoredPassphrase: (String) -> Bool = { CryptPassphrases.hasStored($0) } | |
| 197 | /// Files whose remembered passphrase is being asked for, and those where it was refused: | |
| 198 | /// the Keychain is asked once per file until the file closes or Encrypt is chosen. | |
| 199 | @ObservationIgnored private var askingKeychain: Set<String> = [] | |
| 200 | @ObservationIgnored private var refusedKeychain: Set<String> = [] | |
| 201 | ||
| 202 | public static func isEncryptedFile(_ path: String) -> Bool { CryptVault.isEncryptedFile(path) } | |
| 203 | ||
| 204 | /// An encrypted org file, which lists with the org files. | |
| 205 | public static func isEncryptedOrgFile(_ path: String) -> Bool { path.hasSuffix(".org.gpg") } | |
| 206 | ||
| 207 | /// Gives `passphrase` for `path`: an encrypted file opens with it, and a held file is saved. | |
| 208 | /// It must open the file, or the file's encrypted entries if it has any. A message when it | |
| 209 | /// doesn't. | |
| 210 | public func unlock(_ passphrase: String, for path: String) -> String? { | |
| 211 | if let entry = entry(path) { | |
| 212 | if let message = OrgCrypt.firstMessage(entry.buffer.document.text), !OrgCrypt.opens(message, passphrase: passphrase) { | |
| 213 | return String(localized: "Wrong passphrase") | |
| 214 | } | |
| 215 | // An encrypted file on disk keeps its passphrase: a passphrase given after Forget | |
| 216 | // must open it. | |
| 217 | if Self.isEncryptedFile(entry.path), let disk = try? diskFileSystem.read(URL(fileURLWithPath: entry.path)), | |
| 218 | !CryptVault.opens(disk, passphrase: passphrase) { | |
| 219 | return String(localized: "Wrong passphrase") | |
| 220 | } | |
| 221 | crypt.unlock(passphrase, for: entry.path) | |
| 222 | refusedKeychain.remove(entry.path) | |
| 223 | save(entry) | |
| 224 | return nil | |
| 225 | } | |
| 226 | guard Self.isEncryptedFile(path) else { return nil } | |
| 227 | let bytes: [UInt8] | |
| 228 | do { | |
| 229 | guard let read = try diskFileSystem.read(URL(fileURLWithPath: path)) else { return "\((path as NSString).lastPathComponent) no longer exists." } | |
| 230 | bytes = read | |
| 231 | } catch { | |
| 232 | return error.localizedDescription | |
| 233 | } | |
| 234 | guard CryptVault.opens(bytes, passphrase: passphrase) else { return String(localized: "Wrong passphrase") } | |
| 235 | crypt.unlock(passphrase, for: path) | |
| 236 | let pane = unlockPane.flatMap { pane in panes.contains { $0 === pane } ? pane : nil } ?? focused | |
| 237 | unlockRequest = nil | |
| 238 | unlockPane = nil | |
| 239 | open(path, in: pane) | |
| 240 | return nil | |
| 241 | } | |
| 242 | ||
| 243 | /// The encrypted file waiting for its passphrase stays closed. | |
| 244 | public func cancelUnlock() { | |
| 245 | if let unlockRequest { CryptPassphrases.endSession(for: unlockRequest) } | |
| 246 | unlockRequest = nil | |
| 247 | unlockPane = nil | |
| 248 | } | |
| 249 | ||
| 250 | /// A crypt command used `passphrase` for `path`: saves use it from now on, without asking. | |
| 251 | public func cryptUsed(_ passphrase: String, for path: String) { | |
| 252 | crypt.unlock(passphrase, for: path) | |
| 253 | refusedKeychain.remove(path) | |
| 254 | } | |
| 255 | ||
| 256 | /// The entry holding `plaintext` in `path`'s buffer was decrypted from `message`. | |
| 257 | public func cryptDecrypted(message: String, plaintext: String, for path: String) { | |
| 258 | crypt.remember(message: message, plaintext: plaintext, for: path) | |
| 259 | } | |
| 260 | ||
| 261 | /// Forget Encryption Passphrase: the passphrase leaves the Keychain and the session. | |
| 262 | public func forgetPassphrase(for path: String) { | |
| 263 | CryptPassphrases.forget(path) | |
| 264 | crypt.forgetPassphrase(for: path) | |
| 265 | } | |
| 266 | ||
| 267 | /// `title`, of the heading at `heading` in `path`, as it may be shown and kept outside | |
| 268 | /// the editor (the clock's file, widgets, the Live Activity, the menu bar): a placeholder | |
| 269 | /// for a heading of an encrypted file or one inside an entry that's encrypted on disk. | |
| 270 | public func shareableTitle(_ title: String, path: String, heading: Int) -> String { | |
| 271 | let hidden = Self.isEncryptedFile(path) | |
| 272 | || (crypt.sealsEntries(for: path) && document(of: path).map { OrgCrypt.isInTaggedText($0.text, at: heading, tag: cryptTag) } == true) | |
| 273 | return hidden ? String(localized: "Encrypted entry") : title | |
| 274 | } | |
| 275 | ||
| 276 | /// Why a copy of the buffer can't be kept, with what to do; the buffer's notice shows. | |
| 277 | private func keepFailure(_ hold: CryptHold) -> String { | |
| 278 | if let current { _ = updateHold(current) } | |
| 279 | return hold.localizedDescription + ". " + String(localized: "Give the passphrase with Encrypt… first, so that a copy of your edits can be kept encrypted.") | |
| 280 | } | |
| 281 | ||
| 282 | /// Whether `path`'s buffer is held back from disk now. | |
| 283 | private func updateHold(_ entry: Entry) -> CryptHold? { | |
| 284 | let dirty = entry.buffer.document.isDirty | |
| 285 | let hold = dirty ? crypt.hold(entry.buffer.document.text, for: entry.path) ?? failedHolds[entry.path] : nil | |
| 286 | if held[entry.path] != hold { held[entry.path] = hold } | |
| 287 | return hold | |
| 288 | } | |
| 289 | ||
| 290 | /// Asks the Keychain for `entry`'s passphrase, once, and saves with it. | |
| 291 | private func askKeychain(_ entry: Entry) { | |
| 292 | let path = entry.path | |
| 293 | guard !askingKeychain.contains(path), !refusedKeychain.contains(path), hasStoredPassphrase(path) else { return } | |
| 294 | askingKeychain.insert(path) | |
| 295 | Task { [weak self, weak entry] in | |
| 296 | guard let self else { return } | |
| 297 | let passphrase = await self.storedPassphrase(path) | |
| 298 | self.askingKeychain.remove(path) | |
| 299 | guard let entry, self.entries.contains(where: { $0 === entry }) else { return } | |
| 300 | if let passphrase, self.unlock(passphrase, for: path) == nil { return } | |
| 301 | self.refusedKeychain.insert(path) | |
| 302 | } | |
| 303 | } | |
| 304 | ||
| 161 | 305 | // MARK: - Panes |
| 162 | 306 | |
| 163 | 307 | /// A new, empty pane. |
| @@ -187,7 +331,7 @@ public final class DocumentSession { | ||
| 187 | 331 | public var isOrg: Bool { path.map(Self.isOrgPath) ?? false } |
| 188 | 332 | |
| 189 | 333 | public static func isOrgPath(_ path: String) -> Bool { |
| 190 | path.hasSuffix(".org") || path.hasSuffix(".org_archive") | |
| 334 | path.hasSuffix(".org") || path.hasSuffix(".org_archive") || path.hasSuffix(".org.gpg") | |
| 191 | 335 | } |
| 192 | 336 | |
| 193 | 337 | /// The caret in the open file. |
| @@ -248,9 +392,40 @@ public final class DocumentSession { | ||
| 248 | 392 | entries.map { ($0.path, $0.buffer.document) } |
| 249 | 393 | } |
| 250 | 394 | |
| 251 | /// The text of every open file by path, for the agenda. | |
| 395 | /// The text of every open file by path, for the agenda and what it writes (widgets, the | |
| 396 | /// watch, reminders). Encrypted files, and files with entries decrypted that saving | |
| 397 | /// encrypts, are left out: those views read them from disk. | |
| 252 | 398 | public var openTexts: [String: String] { |
| 253 | Dictionary(entries.map { ($0.path, $0.buffer.document.text) }, uniquingKeysWith: { a, _ in a }) | |
| 399 | let shown = entries.filter { !crypt.isPrivate($0.buffer.document.text, for: $0.path) } | |
| 400 | return Dictionary(shown.map { ($0.path, $0.buffer.document.text) }, uniquingKeysWith: { a, _ in a }) | |
| 401 | } | |
| 402 | ||
| 403 | /// The text of `path` for an export that writes files (iCalendar, publishing): an open | |
| 404 | /// buffer's, unless it holds what's encrypted on disk, then what's on disk; nil for an | |
| 405 | /// encrypted file. | |
| 406 | public func exportText(of path: String) -> String? { | |
| 407 | if Self.isEncryptedFile(path) { return nil } | |
| 408 | if let entry = entry(path), !crypt.isPrivate(entry.buffer.document.text, for: entry.path) { return entry.buffer.document.text } | |
| 409 | return (try? diskFileSystem.read(URL(fileURLWithPath: path))).flatMap { $0 }.flatMap { String(bytes: $0, encoding: .utf8) } | |
| 410 | } | |
| 411 | ||
| 412 | /// Whether `exportText` leaves `path` out or reads it from disk for what's encrypted. | |
| 413 | public func exportLeavesOut(_ path: String) -> Bool { | |
| 414 | Self.isEncryptedFile(path) || entry(path).map { crypt.isPrivate($0.buffer.document.text, for: $0.path) } == true | |
| 415 | } | |
| 416 | ||
| 417 | /// Why the buffer of `path` isn't copied to a temporary file for Emacs (recalculating, | |
| 418 | /// exporting, `elisp:` links): it's an encrypted file, or holds entries encrypted on disk. | |
| 419 | public func refusesEmacsCopy(_ path: String) -> String? { | |
| 420 | let name = (path as NSString).lastPathComponent | |
| 421 | if Self.isEncryptedFile(path) { return String(localized: "\(name) is encrypted, so Emacs isn't given a copy of it.") } | |
| 422 | guard let entry = entry(path), crypt.isPrivate(entry.buffer.document.text, for: entry.path) else { return nil } | |
| 423 | return String(localized: "\(name) has decrypted entries that are encrypted on disk, so Emacs isn't given a copy of it.") | |
| 424 | } | |
| 425 | ||
| 426 | /// Said after an export that left out encrypted files or read decrypted entries from disk. | |
| 427 | public static var exportNote: String { | |
| 428 | String(localized: "Encrypted files were left out, and encrypted entries were exported as they are on disk.") | |
| 254 | 429 | } |
| 255 | 430 | |
| 256 | 431 | /// Open buffers, most recently shown first. |
| @@ -269,12 +444,19 @@ public final class DocumentSession { | ||
| 269 | 444 | show(existing, in: pane) |
| 270 | 445 | return |
| 271 | 446 | } |
| 447 | if Self.isEncryptedFile(path), crypt.passphrase(for: path) == nil, | |
| 448 | (try? diskFileSystem.read(URL(fileURLWithPath: path)))??.isEmpty == false { | |
| 449 | unlockRequest = path | |
| 450 | unlockPane = pane | |
| 451 | return | |
| 452 | } | |
| 272 | 453 | do { |
| 273 | 454 | guard let bytes = try fileSystem.read(URL(fileURLWithPath: path)) else { |
| 274 | 455 | showError(String(localized: "Couldn't Open File", comment: "Error alert title"), "\((path as NSString).lastPathComponent) no longer exists.") |
| 275 | 456 | return |
| 276 | 457 | } |
| 277 | 458 | let entry = Entry(path: path, buffer: StateBuffer(loaded(bytes, path: path))) |
| 459 | crypt.opened(path) | |
| 278 | 460 | let index = pane.path.flatMap(self.entry).flatMap { c in entries.firstIndex { $0 === c } }.map { $0 + 1 } ?? entries.count |
| 279 | 461 | entries.insert(entry, at: index) |
| 280 | 462 | show(entry, in: pane) |
| @@ -312,6 +494,11 @@ public final class DocumentSession { | ||
| 312 | 494 | guard let entry = entry(path) else { return } |
| 313 | 495 | entry.autosave?.cancel() |
| 314 | 496 | entries.removeAll { $0 === entry } |
| 497 | crypt.close(entry.path) | |
| 498 | CryptPassphrases.endSession(for: entry.path) | |
| 499 | held[entry.path] = nil | |
| 500 | failedHolds[entry.path] = nil | |
| 501 | refusedKeychain.remove(entry.path) | |
| 315 | 502 | history.removeAll { $0 == path } |
| 316 | 503 | outlineUpdates[path]?.cancel() |
| 317 | 504 | outlineUpdates[path] = nil |
| @@ -426,6 +613,8 @@ public final class DocumentSession { | ||
| 426 | 613 | |
| 427 | 614 | private func scheduleAutosave(_ entry: Entry) { |
| 428 | 615 | entry.autosave?.cancel() |
| 616 | // A held file whose edits were undone, or whose tagged entries went, isn't held. | |
| 617 | if held[entry.path] != nil, updateHold(entry) == nil { refresh(entry) } | |
| 429 | 618 | guard saveMode == .automatic, entry.buffer.document.isDirty, entry.conflict == nil else { return } |
| 430 | 619 | entry.autosave = Task { [weak self, weak entry, autosaveDelay] in |
| 431 | 620 | try? await Task.sleep(for: autosaveDelay) |
| @@ -460,20 +649,37 @@ public final class DocumentSession { | ||
| 460 | 649 | defer { interval.end((entry.path as NSString).lastPathComponent) } |
| 461 | 650 | entry.autosave?.cancel() |
| 462 | 651 | let name = (entry.path as NSString).lastPathComponent |
| 652 | // A failed save is tried again: what failed may be fixed by now. | |
| 653 | guard updateHold(entry) == nil || held[entry.path] == failedHolds[entry.path] else { | |
| 654 | askKeychain(entry) | |
| 655 | refresh(entry) | |
| 656 | return false | |
| 657 | } | |
| 463 | 658 | guard entry.buffer.document.isDirty else { return true } |
| 464 | 659 | guard entry.conflict == nil else { return false } |
| 660 | defer { _ = updateHold(entry) } | |
| 465 | 661 | do { |
| 466 | 662 | let outcome = try entry.buffer.update { try saver.save(&$0, to: URL(fileURLWithPath: entry.path)) } |
| 663 | failedHolds[entry.path] = nil | |
| 467 | 664 | switch outcome { |
| 468 | 665 | case .saved, .mergedAndSaved: |
| 469 | 666 | break |
| 470 | 667 | case .conflict: |
| 471 | 668 | entry.conflict = "\(name) changed on disk, and the changes conflict with yours." |
| 472 | 669 | case .overwroteExternalChange(let change), .changedAfterWrite(let change): |
| 473 | if case .conflict = change { | |
| 474 | entry.conflict = "\(name) changed on disk while saving, and the changes conflict with yours." | |
| 670 | if case .conflict(let conflicts) = change { | |
| 671 | // No conflicts listed: both versions went into the buffer between markers. | |
| 672 | entry.conflict = conflicts.isEmpty | |
| 673 | ? String(localized: "\(name) changed on disk while saving, and the changes conflict with yours; both are in the editor between conflict markers.") | |
| 674 | : "\(name) changed on disk while saving, and the changes conflict with yours." | |
| 475 | 675 | } |
| 476 | 676 | } |
| 677 | } catch let hold as CryptHold { | |
| 678 | // A version on disk with tagged entries in plaintext can be kept only encrypted. | |
| 679 | failedHolds[entry.path] = hold | |
| 680 | askKeychain(entry) | |
| 681 | } catch let failure as OrgCrypt.Failure { | |
| 682 | failedHolds[entry.path] = .blocked(failure.description) | |
| 477 | 683 | } catch { |
| 478 | 684 | showError(String(localized: "Couldn't Save File", comment: "Error alert title"), "Can't save \(name): \(error.localizedDescription)") |
| 479 | 685 | } |
| @@ -484,9 +690,17 @@ public final class DocumentSession { | ||
| 484 | 690 | /// Resolves a conflict by writing the buffer over the disk version, which goes to recovery. |
| 485 | 691 | public func keepMine() { |
| 486 | 692 | guard let buffer, let url else { return } |
| 693 | if let current, updateHold(current) != nil { return refresh() } | |
| 487 | 694 | do { |
| 488 | 695 | try buffer.update { try saver.overwrite(&$0, to: url) } |
| 489 | 696 | current?.conflict = nil |
| 697 | } catch let hold as CryptHold { | |
| 698 | // The version on disk can be kept only encrypted: the passphrase first. | |
| 699 | if let current { | |
| 700 | failedHolds[current.path] = hold | |
| 701 | _ = updateHold(current) | |
| 702 | askKeychain(current) | |
| 703 | } | |
| 490 | 704 | } catch { |
| 491 | 705 | showError(String(localized: "Couldn't Save File", comment: "Error alert title"), "Can't save \(name): \(error.localizedDescription)") |
| 492 | 706 | } |
| @@ -502,6 +716,8 @@ public final class DocumentSession { | ||
| 502 | 716 | let path = url.path |
| 503 | 717 | buffer.update { $0 = loaded(bytes, path: path) } |
| 504 | 718 | current?.conflict = nil |
| 719 | } catch let hold as CryptHold { | |
| 720 | showError(String(localized: "Couldn't Keep a Copy", comment: "Error alert title"), keepFailure(hold)) | |
| 505 | 721 | } catch { |
| 506 | 722 | showError(String(localized: "Couldn't Read File", comment: "Error alert title"), "Can't read \(name): \(error.localizedDescription)") |
| 507 | 723 | } |
| @@ -529,6 +745,8 @@ public final class DocumentSession { | ||
| 529 | 745 | try state.apply(lineEdits(from: versions.disk, to: merged), baseRevision: state.revision) |
| 530 | 746 | } |
| 531 | 747 | current?.conflict = nil |
| 748 | } catch let hold as CryptHold { | |
| 749 | showError(String(localized: "Couldn't Keep a Copy", comment: "Error alert title"), keepFailure(hold)) | |
| 532 | 750 | } catch { |
| 533 | 751 | showError(String(localized: "Couldn't Merge", comment: "Error alert title"), "Can't merge \(name): \(error.localizedDescription)") |
| 534 | 752 | } |
| @@ -553,7 +771,7 @@ public final class DocumentSession { | ||
| 553 | 771 | public func resolve(copy: URL, _ resolution: CopyResolution) -> String? { |
| 554 | 772 | guard let buffer, let url else { return "No file is open" } |
| 555 | 773 | do { |
| 556 | guard let bytes = try fileSystem.read(copy) else { return "\(copy.lastPathComponent) is gone" } | |
| 774 | guard let bytes = try diskFileSystem.read(copy).map({ try crypt.plain($0, for: url.path) }) else { return "\(copy.lastPathComponent) is gone" } | |
| 557 | 775 | let copyText = SourceText(bytes: bytes).text |
| 558 | 776 | let mine = buffer.document.text |
| 559 | 777 | let new: String? = switch resolution { |
| @@ -577,7 +795,7 @@ public final class DocumentSession { | ||
| 577 | 795 | /// Versions of the open file kept in recovery, newest first, with when and why each was |
| 578 | 796 | /// kept. |
| 579 | 797 | public func recoveryVersions() -> [(url: URL, date: Date, label: String)] { |
| 580 | guard let url, let store = recovery as? FileRecoveryStore, let versions = try? store.versions(for: url) else { return [] } | |
| 798 | guard let url, let store = diskRecovery as? FileRecoveryStore, let versions = try? store.versions(for: url) else { return [] } | |
| 581 | 799 | // `STAMP-LABEL-UUID8-NAME`, as `FileRecoveryStore.keep` names them. |
| 582 | 800 | return versions.reversed().map { version in |
| 583 | 801 | let m = version.lastPathComponent.firstMatch(of: /^([0-9]+)-(.+?)-([0-9A-Fa-f]{8})-/) |
| @@ -588,7 +806,9 @@ public final class DocumentSession { | ||
| 588 | 806 | |
| 589 | 807 | /// The text of a kept version. |
| 590 | 808 | public func recoveryText(_ version: URL) -> String? { |
| 591 | (try? fileSystem.read(version)).flatMap { $0 }.map { SourceText(bytes: $0).text } | |
| 809 | guard let bytes = (try? diskFileSystem.read(version)).flatMap({ $0 }) else { return nil } | |
| 810 | // Kept as the open file is: encrypted with its passphrase, its entries' messages known. | |
| 811 | return (try? path.map { try crypt.plain(bytes, for: $0) } ?? bytes).map { SourceText(bytes: $0).text } | |
| 592 | 812 | } |
| 593 | 813 | |
| 594 | 814 | /// Puts a kept version's text in the buffer, as an edit that can be undone; the buffer as it |
| @@ -604,6 +824,8 @@ public final class DocumentSession { | ||
| 604 | 824 | guard let buffer, let url else { return "Can't read that version" } |
| 605 | 825 | do { |
| 606 | 826 | try recovery.keep(try buffer.document.encodedText(), for: url, label: "local") |
| 827 | } catch let hold as CryptHold { | |
| 828 | return keepFailure(hold) | |
| 607 | 829 | } catch { |
| 608 | 830 | return "Can't keep the current version: \(error.localizedDescription)" |
| 609 | 831 | } |
| @@ -653,7 +875,16 @@ public final class DocumentSession { | ||
| 653 | 875 | /// path; the subtree leaves its file only once it has. Returns a message for the echo area. |
| 654 | 876 | @discardableResult |
| 655 | 877 | public func refile(to target: RefileTarget, from: (path: String, offset: Int)? = nil, keep: Bool = false, now: Date = Date()) -> String? { |
| 656 | guard let (path, context) = source(from, now: now) else { return from == nil ? nil : "Can't read the entry's file." } | |
| 878 | guard var (path, context) = source(from, now: now) else { return from == nil ? nil : "Can't read the entry's file." } | |
| 879 | if target.path != path { | |
| 880 | switch prepareMove(path, context: context, to: target.path) { | |
| 881 | case .refused(let message): return message | |
| 882 | case .sealed(let heading): | |
| 883 | guard let again = source((path, heading), now: now) else { return "Can't read the entry's file." } | |
| 884 | context = again.context | |
| 885 | case .ready: break | |
| 886 | } | |
| 887 | } | |
| 657 | 888 | let done = (keep ? "Copied to " : "Refiled to ") + target.label |
| 658 | 889 | if target.path == path { |
| 659 | 890 | let answers = ["refile": target.start.map(String.init) ?? ""] |
| @@ -773,6 +1004,73 @@ public final class DocumentSession { | ||
| 773 | 1004 | return (TextEdit(range: at..<at, replacement: insertion), newStart, level) |
| 774 | 1005 | } |
| 775 | 1006 | |
| 1007 | private enum MovePreparation { | |
| 1008 | case ready | |
| 1009 | /// Tagged entries in the subtree were encrypted in its file; its heading starts here. | |
| 1010 | case sealed(Int) | |
| 1011 | case refused(String) | |
| 1012 | } | |
| 1013 | ||
| 1014 | /// Before the subtree at the caret of `context`, in `path`, moves to the file `target`: an | |
| 1015 | /// encrypted file's entries go only to another encrypted file, which takes the same | |
| 1016 | /// passphrase; tagged entries with text in the subtree are encrypted where they are first, | |
| 1017 | /// since the tag they inherit doesn't go with them. | |
| 1018 | private func prepareMove(_ path: String, context: EditContext, to target: String) -> MovePreparation { | |
| 1019 | // The target's passphrase, lent by the source for the move, isn't kept after it. | |
| 1020 | if Self.isEncryptedFile(target), !isOpen(target) { | |
| 1021 | DispatchQueue.main.async { [weak self] in | |
| 1022 | guard let self, !self.isOpen(target) else { return } | |
| 1023 | self.crypt.close(target) | |
| 1024 | } | |
| 1025 | } | |
| 1026 | let from = (path as NSString).lastPathComponent, to = (target as NSString).lastPathComponent | |
| 1027 | if Self.isEncryptedFile(path) { | |
| 1028 | guard Self.isEncryptedFile(target) else { | |
| 1029 | return .refused(String(localized: "\(from) is encrypted, and \(to) isn't; the entry wasn't moved.")) | |
| 1030 | } | |
| 1031 | if crypt.passphrase(for: target) == nil, let passphrase = crypt.passphrase(for: path) { | |
| 1032 | let disk = (try? diskFileSystem.read(URL(fileURLWithPath: target))).flatMap { $0 } ?? [] | |
| 1033 | guard CryptVault.opens(disk, passphrase: passphrase) else { | |
| 1034 | return .refused(String(localized: "\(to) has another passphrase; open it first.")) | |
| 1035 | } | |
| 1036 | crypt.unlock(passphrase, for: target) | |
| 1037 | } | |
| 1038 | } | |
| 1039 | guard crypt.sealsEntries(for: path), let heading = OrgCrypt.heading(context.text, at: context.selection.first?.lowerBound ?? 0) else { return .ready } | |
| 1040 | // A heading inside an encrypted entry is in that entry's message on disk; moved on its | |
| 1041 | // own, its title would be in plaintext. | |
| 1042 | if OrgCrypt.isInTaggedText(context.text, at: heading, tag: cryptTag) { | |
| 1043 | return .refused(String(localized: "This heading is inside an encrypted entry, so it isn't moved on its own; move the encrypted entry.")) | |
| 1044 | } | |
| 1045 | let end = OrgCrypt.bodyRange(context.text, at: heading)?.upperBound ?? heading | |
| 1046 | let subtree = heading..<max(heading + 1, end) | |
| 1047 | guard !OrgCrypt.unencrypted(context.text, tag: cryptTag, within: subtree).isEmpty else { return .ready } | |
| 1048 | guard let passphrase = crypt.passphrase(for: path) else { | |
| 1049 | return .refused(String(localized: "Tagged entries in the subtree aren't encrypted; give the passphrase with Encrypt… first.")) | |
| 1050 | } | |
| 1051 | let sealed: String | |
| 1052 | do { | |
| 1053 | sealed = try OrgCrypt.seal(context.text, passphrase: passphrase, tag: cryptTag, within: subtree).text | |
| 1054 | } catch { | |
| 1055 | return .refused("\(error)") | |
| 1056 | } | |
| 1057 | let edit = EditResult(baseRevision: context.revision, edits: lineEdits(from: context.text, to: sealed)) | |
| 1058 | if let open = entry(path) { | |
| 1059 | if case .failed(let message) = open.buffer.perform(PrecomputedEdit(edit), now: Date(), answers: [:]) { return .refused(message) } | |
| 1060 | changed(open) | |
| 1061 | } else { | |
| 1062 | do { | |
| 1063 | guard let bytes = try fileSystem.read(URL(fileURLWithPath: path)) else { return .refused("\(from) no longer exists.") } | |
| 1064 | var state = loaded(bytes, path: path) | |
| 1065 | try state.apply(edit.edits, baseRevision: state.revision) | |
| 1066 | if case .conflict = try saver.save(&state, to: URL(fileURLWithPath: path)) { return .refused("\(from) changed on disk; nothing was moved.") } | |
| 1067 | } catch { | |
| 1068 | return .refused("Can't encrypt the entry: \(error.localizedDescription)") | |
| 1069 | } | |
| 1070 | } | |
| 1071 | return .sealed(heading) | |
| 1072 | } | |
| 1073 | ||
| 776 | 1074 | /// The file `archive(from:now:)` moves the entry to, or nil when it can't tell. |
| 777 | 1075 | public func archiveFile(from: (path: String, offset: Int)? = nil, now: Date = Date()) -> String? { |
| 778 | 1076 | guard let (path, context) = source(from, now: now), case .success(let destination) = Archive.destination(context, sourcePath: path) else { return nil } |
| @@ -783,12 +1081,21 @@ public final class DocumentSession { | ||
| 783 | 1081 | /// Returns a message. |
| 784 | 1082 | @discardableResult |
| 785 | 1083 | public func archive(from: (path: String, offset: Int)? = nil, now: Date = Date()) -> String? { |
| 786 | guard let (path, context) = source(from, now: now) else { return from == nil ? nil : "Can't read the entry's file." } | |
| 1084 | guard var (path, context) = source(from, now: now) else { return from == nil ? nil : "Can't read the entry's file." } | |
| 787 | 1085 | let destination: Archive.Destination |
| 788 | 1086 | switch Archive.destination(context, sourcePath: path) { |
| 789 | 1087 | case .success(let value): destination = value |
| 790 | 1088 | case .failure(.message(let message)): return message |
| 791 | 1089 | } |
| 1090 | if !destination.isSameFile { | |
| 1091 | switch prepareMove(path, context: context, to: destination.path) { | |
| 1092 | case .refused(let message): return message | |
| 1093 | case .sealed(let heading): | |
| 1094 | guard let again = source((path, heading), now: now) else { return "Can't read the entry's file." } | |
| 1095 | context = again.context | |
| 1096 | case .ready: break | |
| 1097 | } | |
| 1098 | } | |
| 792 | 1099 | // An archive file open in a buffer takes the subtree there. |
| 793 | 1100 | if !destination.isSameFile, let open = entry(destination.path) { |
| 794 | 1101 | let state = open.buffer.document |
| @@ -913,7 +1220,9 @@ public final class DocumentSession { | ||
| 913 | 1220 | guard state.isEditable else { return "\(name) isn't UTF-8, so it can't be changed." } |
| 914 | 1221 | guard state.text == expected else { return stale } |
| 915 | 1222 | if entry.buffer is StateBuffer { |
| 916 | do { try recovery.keep(try state.encodedText(), for: url, label: "replace") } catch { | |
| 1223 | // A buffer held for its passphrase keeps no copy: it can't be kept encrypted, | |
| 1224 | // and the replacement can be undone in the buffer. | |
| 1225 | do { try recovery.keep(try state.encodedText(), for: url, label: "replace") } catch is CryptHold {} catch { | |
| 917 | 1226 | return "Can't keep a copy of \(name): \(error.localizedDescription)" |
| 918 | 1227 | } |
| 919 | 1228 | } |
| @@ -952,6 +1261,7 @@ public final class DocumentSession { | ||
| 952 | 1261 | } |
| 953 | 1262 | guard let entry = current else { return "No file is open." } |
| 954 | 1263 | let path = entry.path |
| 1264 | if let refusal = refusesEmacsCopy(path) { return refusal } | |
| 955 | 1265 | let snapshot = entry.buffer.document.text as NSString |
| 956 | 1266 | guard table.upperBound <= snapshot.length else { return "The table moved; try again." } |
| 957 | 1267 | let old = snapshot.substring(with: NSRange(table)) |
Sources/OrgApp/Handoff.swift +2 · view
| @@ -246,6 +246,8 @@ extension DocumentSession { | ||
| 246 | 246 | /// in none of `roots` or an encrypted one. |
| 247 | 247 | public func handoffPlace(_ path: String? = nil, roots: [String]) -> HandoffPlace? { |
| 248 | 248 | guard let path = path ?? self.path, let text = document(of: path)?.text else { return nil } |
| 249 | // The outline and ID could name decrypted headings. | |
| 250 | guard !crypt.isPrivate(text, for: path) else { return nil } | |
| 249 | 251 | return HandoffPlace.make(path: path, text: text, caret: caret(of: path) ?? 0, roots: roots, settings: defaults) |
| 250 | 252 | } |
| 251 | 253 | } |
Sources/OrgApp/LinkFollow.swift +1 −1 · view
| @@ -82,7 +82,7 @@ extension DocumentSession { | ||
| 82 | 82 | /// Evaluates an `elisp:` link's form as `org-link--open-elisp` does: in Emacs, in a copy of |
| 83 | 83 | /// the open file, when `programs` has it, otherwise in `Elisp`. Returns the message to show. |
| 84 | 84 | public func evaluateLink(_ form: String) async -> String { |
| 85 | if let programs = Self.runner, let path, let text = document?.text { | |
| 85 | if let programs = Self.runner, let path, let text = document?.text, refusesEmacsCopy(path) == nil { | |
| 86 | 86 | let directory = URL(fileURLWithPath: path).deletingLastPathComponent() |
| 87 | 87 | do { |
| 88 | 88 | if let value = try await programs.evaluateLisp(form, text: text, point: caret(of: path) ?? 0, directory: directory) { |
Sources/OrgApp/OrgPreferences.swift +4 · view
| @@ -236,6 +236,10 @@ public enum OrgPreferences { | ||
| 236 | 236 | let tag = string("cryptTagMatcher", defaults).trimmingCharacters(in: .whitespaces) |
| 237 | 237 | return tag.isEmpty ? "crypt" : tag |
| 238 | 238 | } |
| 239 | /// `org-crypt-use-before-save-magic`. | |
| 240 | public static func cryptBeforeSave(_ defaults: UserDefaults = .standard) -> Bool { | |
| 241 | bool("cryptBeforeSave", defaults) | |
| 242 | } | |
| 239 | 243 | /// `org-icalendar-combined-agenda-file`, `~` expanded. |
| 240 | 244 | public static func icalendarCombinedFile(_ defaults: UserDefaults = .standard) -> String { |
| 241 | 245 | OrgPaths.expandingTilde(string("icalendarCombinedAgendaFile", defaults)) |
Sources/OrgApp/SubtreeShare.swift +50 −3 · view
| @@ -62,9 +62,56 @@ public struct SubtreeShare: Sendable, Identifiable { | ||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | extension DocumentSession { |
| 65 | /// Share Subtree… for the entry at `offset` in the open file at `path`. | |
| 65 | /// Share Subtree… for the entry at `offset` in the open file at `path`, as it is on disk: | |
| 66 | /// its tagged entries encrypted; a heading inside an encrypted entry as an entry of its own, | |
| 67 | /// "Encrypted entry" with the tag, whose one message holds the whole subtree. Nil when | |
| 68 | /// there's no entry there, or `refusesSubtreeShare`. | |
| 66 | 69 | public func subtreeShare(_ path: String, at offset: Int) -> SubtreeShare? { |
| 67 | guard let text = document(of: path)?.text else { return nil } | |
| 68 | return SubtreeShare(text: text, at: offset, path: path, settings: defaults) | |
| 70 | guard case .success(let source) = shareSource(path, at: offset) else { return nil } | |
| 71 | return SubtreeShare(text: source.text, at: source.offset, path: path, settings: defaults) | |
| 72 | } | |
| 73 | ||
| 74 | /// Why the entry at `offset` in `path` isn't shared: its file is encrypted, or what's | |
| 75 | /// encrypted on disk can't be encrypted in the copy (no passphrase, or one that fails). | |
| 76 | public func refusesSubtreeShare(_ path: String, at offset: Int) -> String? { | |
| 77 | if case .failure(let refusal) = shareSource(path, at: offset) { return refusal.message } | |
| 78 | return nil | |
| 79 | } | |
| 80 | ||
| 81 | struct ShareRefusal: Error { | |
| 82 | let message: String | |
| 83 | } | |
| 84 | ||
| 85 | /// The text to share the entry at `offset` from, and where in it. | |
| 86 | private func shareSource(_ path: String, at offset: Int) -> Result<(text: String, offset: Int), ShareRefusal> { | |
| 87 | let name = (path as NSString).lastPathComponent | |
| 88 | if Self.isEncryptedFile(path) { return .failure(ShareRefusal(message: String(localized: "\(name) is encrypted; its entries aren't shared."))) } | |
| 89 | guard let text = document(of: path)?.text else { return .success((text: "", offset: offset)) } | |
| 90 | guard crypt.sealsEntries(for: path), let heading = OrgCrypt.heading(text, at: offset), let range = subtreeRange(text, at: offset) else { | |
| 91 | return .success((text, offset)) | |
| 92 | } | |
| 93 | let needsPassphrase = ShareRefusal(message: String(localized: "Tagged entries in the subtree aren't encrypted; give the passphrase with Encrypt… first.")) | |
| 94 | if OrgCrypt.isInTaggedText(text, at: heading, tag: cryptTag) { | |
| 95 | guard let passphrase = crypt.passphrase(for: path) else { return .failure(needsPassphrase) } | |
| 96 | let subtree = (text as NSString).substring(with: NSRange(range)) | |
| 97 | do { | |
| 98 | let message = try OpenPGP.encrypt(Data((subtree.hasSuffix("\n") ? subtree : subtree + "\n").utf8), passphrase: passphrase) | |
| 99 | return .success(("* " + String(localized: "Encrypted entry") + " :" + cryptTag + ":\n" + message, 0)) | |
| 100 | } catch { | |
| 101 | return .failure(ShareRefusal(message: error.localizedDescription)) | |
| 102 | } | |
| 103 | } | |
| 104 | guard !OrgCrypt.unencrypted(text, tag: cryptTag, within: range).isEmpty else { return .success((text, offset)) } | |
| 105 | guard let passphrase = crypt.passphrase(for: path) else { return .failure(needsPassphrase) } | |
| 106 | do { | |
| 107 | return .success((try OrgCrypt.seal(text, passphrase: passphrase, tag: cryptTag, within: range).text, heading)) | |
| 108 | } catch { | |
| 109 | return .failure(ShareRefusal(message: error.localizedDescription)) | |
| 110 | } | |
| 111 | } | |
| 112 | ||
| 113 | private func subtreeRange(_ text: String, at offset: Int) -> Range<Int>? { | |
| 114 | guard let heading = OrgCrypt.heading(text, at: offset) else { return nil } | |
| 115 | return heading..<max(heading + 1, OrgCrypt.bodyRange(text, at: heading)?.upperBound ?? heading) | |
| 69 | 116 | } |
| 70 | 117 | } |
Sources/OrgApp/UserConfig.swift +2 · view
| @@ -222,6 +222,8 @@ public enum UserConfig { | ||
| 222 | 222 | comment: "files dropped on the editor: ask, attach, open or file-link", legacy: ""), |
| 223 | 223 | Setting(section: "", key: "org-crypt-tag-matcher", defaultsKey: "cryptTagMatcher", kind: .string, fallback: .string("crypt"), |
| 224 | 224 | comment: "the tag of entries Encrypt Tagged Entries encrypts", legacy: ""), |
| 225 | Setting(section: "", key: "org-crypt-use-before-save-magic", defaultsKey: "cryptBeforeSave", kind: .bool, fallback: .bool(false), | |
| 226 | comment: "encrypt entries with org-crypt-tag-matcher's tag on every save; without their passphrase the file isn't saved", legacy: ""), | |
| 225 | 227 | Setting(section: "", key: "org-display-remote-inline-images", defaultsKey: "remoteInlineImages", |
| 226 | 228 | kind: .choice([("skip", "skip"), ("download", "download"), ("cache", "cache")]), fallback: .string("skip"), |
| 227 | 229 | comment: "images at http(s) links: skip, download (each run) or cache (kept on disk)", legacy: ""), |
Sources/OrgCore/Commands/Archive.swift +6 −1 · view
| @@ -195,7 +195,7 @@ public enum Archive { | ||
| 195 | 195 | let name = (sourcePath as NSString).lastPathComponent |
| 196 | 196 | let fileFormat = String(spec[..<separator.lowerBound]) |
| 197 | 197 | let headingFormat = String(spec[separator.upperBound...]) |
| 198 | let path: String | |
| 198 | var path: String | |
| 199 | 199 | if fileFormat.contains(where: { !$0.isWhitespace }) { |
| 200 | 200 | let file = fileFormat.replacingOccurrences(of: "%s", with: name) |
| 201 | 201 | let directory = (sourcePath as NSString).deletingLastPathComponent |
| @@ -203,6 +203,11 @@ public enum Archive { | ||
| 203 | 203 | } else { |
| 204 | 204 | path = sourcePath |
| 205 | 205 | } |
| 206 | // An encrypted file archives to an encrypted file: `diary.org.gpg` to | |
| 207 | // `diary_archive.org.gpg`, not Org's `diary.org.gpg_archive`. | |
| 208 | if sourcePath.hasSuffix(".gpg"), !path.hasSuffix(".gpg") { | |
| 209 | path = path.hasSuffix(".org.gpg_archive") ? String(path.dropLast(".org.gpg_archive".count)) + "_archive.org.gpg" : path + ".gpg" | |
| 210 | } | |
| 206 | 211 | let heading = headingFormat.replacingOccurrences(of: "%s", with: name) |
| 207 | 212 | return .success(Destination(path: (path as NSString).standardizingPath, heading: heading.isEmpty ? nil : heading, isSameFile: path == sourcePath)) |
| 208 | 213 | } |
Sources/OrgCore/Commands/ClockHistory.swift +19 −2 · view
| @@ -12,12 +12,16 @@ public struct ClockTask: Codable, Equatable, Hashable, Sendable { | ||
| 12 | 12 | /// The heading's index among the file's headings. |
| 13 | 13 | public let ordinal: Int |
| 14 | 14 | public let id: String? |
| 15 | /// For a task whose title is a placeholder for one that isn't kept (an encrypted | |
| 16 | /// heading's): a checksum of the real title, which finds it with its ID or position. | |
| 17 | public let titleHash: String? | |
| 15 | 18 | |
| 16 | public init(path: String, title: String, ordinal: Int, id: String?) { | |
| 19 | public init(path: String, title: String, ordinal: Int, id: String?, titleHash: String? = nil) { | |
| 17 | 20 | self.path = path |
| 18 | 21 | self.title = title |
| 19 | 22 | self.ordinal = ordinal |
| 20 | 23 | self.id = id |
| 24 | self.titleHash = titleHash | |
| 21 | 25 | } |
| 22 | 26 | |
| 23 | 27 | /// The entry containing `offset`; nil before the first heading. |
| @@ -28,9 +32,15 @@ public struct ClockTask: Codable, Equatable, Hashable, Sendable { | ||
| 28 | 32 | return ClockTask(path: path, title: heading.title, ordinal: index, id: heading.id) |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | /// The heading's index in `model`, or nil when the entry is gone. | |
| 35 | /// The heading's index in `model`, or nil when the entry is gone: by ID, then by position | |
| 36 | /// and title, or by title; a task kept without its title by position alone. | |
| 32 | 37 | public func index(in model: DocumentModel) -> Int? { |
| 33 | 38 | if let id, let index = model.headings.firstIndex(where: { $0.id == id }) { return index } |
| 39 | if let titleHash { | |
| 40 | func matches(_ index: Int) -> Bool { OrgCrypt.checksum(model.headings[index].title) == titleHash } | |
| 41 | if ordinal < model.headings.count, matches(ordinal) { return ordinal } | |
| 42 | return model.headings.indices.first(where: matches) | |
| 43 | } | |
| 34 | 44 | if ordinal < model.headings.count, model.headings[ordinal].title == title { return ordinal } |
| 35 | 45 | return model.headings.firstIndex { $0.title == title } |
| 36 | 46 | } |
| @@ -46,6 +56,13 @@ public struct ClockTask: Codable, Equatable, Hashable, Sendable { | ||
| 46 | 56 | let model = DocumentModel(tree: OrgParser.parse(text)) |
| 47 | 57 | guard let index = index(in: model) else { return nil } |
| 48 | 58 | return ClockTask(path: path, title: model.headings[index].title, ordinal: index, id: model.headings[index].id) |
| 59 | .hiding(titleHash == nil ? nil : title) | |
| 60 | } | |
| 61 | ||
| 62 | /// The task with `placeholder` for its title, or as it is with nil. | |
| 63 | public func hiding(_ placeholder: String?) -> ClockTask { | |
| 64 | guard let placeholder else { return self } | |
| 65 | return ClockTask(path: path, title: placeholder, ordinal: ordinal, id: id, titleHash: titleHash ?? OrgCrypt.checksum(title)) | |
| 49 | 66 | } |
| 50 | 67 | } |
| 51 | 68 | |
Sources/OrgCore/Crypto/OpenPGP.swift +93 −13 · view
| @@ -194,27 +194,81 @@ public enum OpenPGP { | ||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /// RFC 4880 3.7.1: as many hashes as the key needs, each preloaded with one more zero. |
| 197 | /// The iterated input is hashed as it's made, a block at a time. | |
| 197 | 198 | func key(_ passphrase: String, size: Int) throws -> Data { |
| 198 | 199 | let material = salt + Data(passphrase.utf8) |
| 199 | 200 | var key = Data() |
| 200 | 201 | var round = 0 |
| 201 | 202 | while key.count < size { |
| 202 | var input = Data(repeating: 0, count: round) | |
| 203 | var hasher = try Hasher(hash) | |
| 204 | hasher.update(Data(repeating: 0, count: round)) | |
| 203 | 205 | if type == 3 { |
| 204 | 206 | let total = max(count, material.count) |
| 205 | var stream = Data(capacity: total) | |
| 206 | while stream.count < total { stream.append(material.prefix(total - stream.count)) } | |
| 207 | input.append(stream) | |
| 207 | // Whole copies of the material, about 64 KB of them, then what's left. | |
| 208 | var block = Data() | |
| 209 | let copies = max(1, 65_536 / max(1, material.count)) | |
| 210 | for _ in 0..<copies { block.append(material) } | |
| 211 | var left = total | |
| 212 | while left >= block.count { | |
| 213 | hasher.update(block) | |
| 214 | left -= block.count | |
| 215 | } | |
| 216 | if left > 0 { hasher.update(block.prefix(left)) } | |
| 208 | 217 | } else { |
| 209 | input.append(material) | |
| 218 | hasher.update(material) | |
| 210 | 219 | } |
| 211 | key.append(try OpenPGP.hash(hash, input)) | |
| 220 | key.append(hasher.finish()) | |
| 212 | 221 | round += 1 |
| 213 | 222 | } |
| 214 | 223 | return key.prefix(size) |
| 215 | 224 | } |
| 216 | 225 | } |
| 217 | 226 | |
| 227 | /// One of the hashes `hash` supports, fed in parts. | |
| 228 | struct Hasher { | |
| 229 | private var md5: Insecure.MD5? | |
| 230 | private var sha1: Insecure.SHA1? | |
| 231 | private var sha256: SHA256? | |
| 232 | private var sha384: SHA384? | |
| 233 | private var sha512: SHA512? | |
| 234 | private var sha224: CC_SHA256_CTX? | |
| 235 | ||
| 236 | init(_ algorithm: Int) throws { | |
| 237 | switch algorithm { | |
| 238 | case 1: md5 = Insecure.MD5() | |
| 239 | case 2: sha1 = Insecure.SHA1() | |
| 240 | case 8: sha256 = SHA256() | |
| 241 | case 9: sha384 = SHA384() | |
| 242 | case 10: sha512 = SHA512() | |
| 243 | case 11: | |
| 244 | var context = CC_SHA256_CTX() | |
| 245 | CC_SHA224_Init(&context) | |
| 246 | sha224 = context | |
| 247 | default: throw Failure("Hash algorithm \(algorithm) isn't supported") | |
| 248 | } | |
| 249 | } | |
| 250 | ||
| 251 | mutating func update(_ data: Data) { | |
| 252 | if md5 != nil { md5!.update(data: data) } | |
| 253 | if sha1 != nil { sha1!.update(data: data) } | |
| 254 | if sha256 != nil { sha256!.update(data: data) } | |
| 255 | if sha384 != nil { sha384!.update(data: data) } | |
| 256 | if sha512 != nil { sha512!.update(data: data) } | |
| 257 | if sha224 != nil { data.withUnsafeBytes { _ = CC_SHA224_Update(&sha224!, $0.baseAddress, CC_LONG(data.count)) } } | |
| 258 | } | |
| 259 | ||
| 260 | mutating func finish() -> Data { | |
| 261 | if let md5 { return Data(md5.finalize()) } | |
| 262 | if let sha1 { return Data(sha1.finalize()) } | |
| 263 | if let sha256 { return Data(sha256.finalize()) } | |
| 264 | if let sha384 { return Data(sha384.finalize()) } | |
| 265 | if let sha512 { return Data(sha512.finalize()) } | |
| 266 | var digest = [UInt8](repeating: 0, count: Int(CC_SHA224_DIGEST_LENGTH)) | |
| 267 | _ = CC_SHA224_Final(&digest, &sha224!) | |
| 268 | return Data(digest) | |
| 269 | } | |
| 270 | } | |
| 271 | ||
| 218 | 272 | // MARK: - AES in CFB |
| 219 | 273 | |
| 220 | 274 | static func cfb(_ data: Data, key: Data, iv: Data = Data(repeating: 0, count: 16), encrypt: Bool) throws -> Data { |
| @@ -234,12 +288,21 @@ public enum OpenPGP { | ||
| 234 | 288 | return Data(out.prefix(moved)) |
| 235 | 289 | } |
| 236 | 290 | |
| 237 | static func random(_ count: Int) -> Data { | |
| 291 | static func random(_ count: Int) throws -> Data { | |
| 238 | 292 | var bytes = [UInt8](repeating: 0, count: count) |
| 239 | _ = SecRandomCopyBytes(kSecRandomDefault, count, &bytes) | |
| 293 | guard SecRandomCopyBytes(kSecRandomDefault, count, &bytes) == errSecSuccess else { throw Failure("No random bytes for the salt") } | |
| 240 | 294 | return Data(bytes) |
| 241 | 295 | } |
| 242 | 296 | |
| 297 | /// The coded iteration count new messages use: 65,011,712 bytes hashed, GnuPG's most. | |
| 298 | static let codedCount: UInt8 = 0xFF | |
| 299 | ||
| 300 | /// Whether `message` (packets) is encrypted with a passphrase: its first packet is a | |
| 301 | /// symmetric-key session packet, not one for a public key. | |
| 302 | public static func isSymmetric(_ message: Data) -> Bool { | |
| 303 | (try? packets(message))?.first?.tag == 3 | |
| 304 | } | |
| 305 | ||
| 243 | 306 | // MARK: - Messages |
| 244 | 307 | |
| 245 | 308 | public static let wrongPassphrase = Failure("Bad session key") |
| @@ -329,17 +392,34 @@ public enum OpenPGP { | ||
| 329 | 392 | /// `gpg --symmetric --armor`: AES-256, an iterated and salted SHA-256 key, integrity |
| 330 | 393 | /// protection, binary literal data without a name. |
| 331 | 394 | public static func encrypt(_ data: Data, passphrase: String, now: Date = Date()) throws -> String { |
| 332 | let salt = random(8) | |
| 333 | let s2k = S2K(type: 3, hash: 8, salt: salt, count: (16 + (96 & 15)) << ((96 >> 4) + 6)) | |
| 395 | armor(try encryptedMessage(data, passphrase: passphrase, now: now)) | |
| 396 | } | |
| 397 | ||
| 398 | /// Whether `data` is an armored message rather than packets. | |
| 399 | public static func isArmored(_ data: Data) -> Bool { | |
| 400 | let head = String(decoding: data.prefix(64), as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines) | |
| 401 | return head.hasPrefix("-----BEGIN PGP MESSAGE") | |
| 402 | } | |
| 403 | ||
| 404 | /// The literal data of a passphrase-encrypted file, armored or not, as `gpg --decrypt` reads it. | |
| 405 | public static func decryptFile(_ data: Data, passphrase: String) throws -> Data { | |
| 406 | try decrypt(isArmored(data) ? dearmor(String(decoding: data, as: UTF8.self)) : data, passphrase: passphrase) | |
| 407 | } | |
| 408 | ||
| 409 | /// `gpg --symmetric` without `--armor`: the packets of `encrypt`. | |
| 410 | public static func encryptedMessage(_ data: Data, passphrase: String, now: Date = Date()) throws -> Data { | |
| 411 | let salt = try random(8) | |
| 412 | let c = Int(codedCount) | |
| 413 | let s2k = S2K(type: 3, hash: 8, salt: salt, count: (16 + (c & 15)) << ((c >> 4) + 6)) | |
| 334 | 414 | let key = try s2k.key(passphrase, size: 32) |
| 335 | let skesk = packet(3, Data([4, 9, 3, 8]) + salt + Data([96])) | |
| 415 | let skesk = packet(3, Data([4, 9, 3, 8]) + salt + Data([codedCount])) | |
| 336 | 416 | let date = UInt32(max(0, now.timeIntervalSince1970)) |
| 337 | 417 | let literal = packet(11, Data([0x62, 0]) + Data((0..<4).reversed().map { UInt8((date >> ($0 * 8)) & 0xff) }) + data) |
| 338 | var prefix = random(16) | |
| 418 | var prefix = try random(16) | |
| 339 | 419 | prefix.append(prefix.suffix(2)) |
| 340 | 420 | var plain = prefix + literal + Data([0xD3, 0x14]) |
| 341 | 421 | plain.append(Data(Insecure.SHA1.hash(data: plain))) |
| 342 | 422 | let seipd = packet(18, Data([1]) + (try cfb(plain, key: key, encrypt: true))) |
| 343 | return armor(skesk + seipd) | |
| 423 | return skesk + seipd | |
| 344 | 424 | } |
| 345 | 425 | } |
Sources/OrgCore/Crypto/OrgCrypt.swift +108 −1 · view
| @@ -1,12 +1,14 @@ | ||
| 1 | import CryptoKit | |
| 1 | 2 | import Foundation |
| 2 | 3 | |
| 3 | 4 | /// org-crypt (org-crypt.el, Org 9.8.7) with symmetric encryption, as with `org-crypt-key` |
| 4 | 5 | /// nil: an entry's text after its planning, properties and logbook, through the end of its |
| 5 | 6 | /// subtree, replaced by an armored OpenPGP message under the heading. |
| 6 | 7 | public enum OrgCrypt { |
| 7 | public struct Failure: Error, Equatable, CustomStringConvertible { | |
| 8 | public struct Failure: Error, Equatable, CustomStringConvertible, LocalizedError { | |
| 8 | 9 | public let description: String |
| 9 | 10 | public init(_ description: String) { self.description = description } |
| 11 | public var errorDescription: String? { description } | |
| 10 | 12 | } |
| 11 | 13 | |
| 12 | 14 | /// `org-end-of-meta-data 'standard`: past planning, the property drawer, clock lines, |
| @@ -134,4 +136,109 @@ public enum OrgCrypt { | ||
| 134 | 136 | } |
| 135 | 137 | return (text, count) |
| 136 | 138 | } |
| 139 | ||
| 140 | /// What saving does with the tagged entry at `heading`: nil when nothing (its text is a | |
| 141 | /// message, or it has no text), else its text's range, the message at its start if any, | |
| 142 | /// and whether it has text that isn't blank outside a message. | |
| 143 | static func pending(_ text: String, at heading: Int) -> (body: Range<Int>, message: Range<Int>?, hasText: Bool)? { | |
| 144 | guard let body = bodyRange(text, at: heading) else { return nil } | |
| 145 | let ns = text as NSString | |
| 146 | func blank(_ range: Range<Int>) -> Bool { | |
| 147 | range.isEmpty || ns.substring(with: NSRange(range)).trimmingCharacters(in: .whitespacesAndNewlines).isEmpty | |
| 148 | } | |
| 149 | if let message = encryptedRange(text, at: heading) { | |
| 150 | // Text typed below the message isn't encrypted. | |
| 151 | let tail = min(message.upperBound, body.upperBound)..<max(message.upperBound, body.upperBound) | |
| 152 | return blank(tail) ? nil : (body, message, true) | |
| 153 | } | |
| 154 | return (body, nil, !blank(body)) | |
| 155 | } | |
| 156 | ||
| 157 | /// The tagged entries `seal` encrypts whose text isn't blank: those a save can't write | |
| 158 | /// without the passphrase, text below a message included. Their headings' offsets. | |
| 159 | public static func unencrypted(_ text: String, tag: String = "crypt", settings: OrgSettings = .default, within: Range<Int>? = nil) -> [Int] { | |
| 160 | guard text.contains(tag) else { return [] } | |
| 161 | var found: [Int] = [] | |
| 162 | var covered = 0 | |
| 163 | for heading in taggedHeadings(text, tag: tag, settings: settings) where heading >= covered && within?.contains(heading) ?? true { | |
| 164 | guard let entry = pending(text, at: heading) else { continue } | |
| 165 | // Tagged children go inside this entry's message. | |
| 166 | covered = entry.body.upperBound | |
| 167 | if entry.hasText { found.append(heading) } | |
| 168 | } | |
| 169 | return found | |
| 170 | } | |
| 171 | ||
| 172 | /// `org-encrypt-entries` as `org-crypt-use-before-save-magic` runs it before a save. An | |
| 173 | /// entry whose text `reuse` knows by its `checksum` gets that message again, as org-crypt | |
| 174 | /// keeps an entry decrypted and left unchanged byte for byte. Text below an entry's message | |
| 175 | /// goes into one message with what the old one held. The text, and each message with the | |
| 176 | /// text the entry had. | |
| 177 | public static func seal( | |
| 178 | _ text: String, passphrase: String, tag: String = "crypt", settings: OrgSettings = .default, | |
| 179 | reuse: (String) -> String? = { _ in nil }, within: Range<Int>? = nil, now: Date = Date() | |
| 180 | ) throws -> (text: String, messages: [(message: String, plaintext: String)]) { | |
| 181 | guard text.contains(tag) else { return (text, []) } | |
| 182 | var result = text as NSString | |
| 183 | var messages: [(String, String)] = [] | |
| 184 | var shift = 0 | |
| 185 | var covered = 0 | |
| 186 | for heading in taggedHeadings(text, tag: tag, settings: settings) where heading >= covered && within?.contains(heading) ?? true { | |
| 187 | let current = result as String | |
| 188 | guard let entry = pending(current, at: heading + shift) else { continue } | |
| 189 | let range = entry.body | |
| 190 | covered = range.upperBound - shift | |
| 191 | let contents = result.substring(with: NSRange(range)) | |
| 192 | var plaintext = contents | |
| 193 | if let old = entry.message { | |
| 194 | let opened: String | |
| 195 | do { | |
| 196 | opened = try decrypt(current, at: heading + shift, passphrase: passphrase).plaintext | |
| 197 | } catch { | |
| 198 | throw Failure("An entry has text below a message that this passphrase doesn't open; entries encrypted to a public key aren't supported") | |
| 199 | } | |
| 200 | plaintext = opened + result.substring(with: NSRange(old.upperBound..<range.upperBound)) | |
| 201 | } | |
| 202 | let message = try reuse(checksum(contents)) ?? OpenPGP.encrypt(Data(plaintext.utf8), passphrase: passphrase, now: now) | |
| 203 | result = result.replacingCharacters(in: NSRange(range), with: message) as NSString | |
| 204 | shift += (message as NSString).length - range.count | |
| 205 | messages.append((message, contents)) | |
| 206 | } | |
| 207 | return (result as String, messages) | |
| 208 | } | |
| 209 | ||
| 210 | /// Whether `offset` is in the text of an entry with `tag`, which a message holds on disk. | |
| 211 | public static func isInTaggedText(_ text: String, at offset: Int, tag: String = "crypt", settings: OrgSettings = .default) -> Bool { | |
| 212 | guard text.contains(tag) else { return false } | |
| 213 | return taggedHeadings(text, tag: tag, settings: settings).contains { heading in | |
| 214 | heading < offset && (bodyRange(text, at: heading)?.contains(offset) ?? false) | |
| 215 | } | |
| 216 | } | |
| 217 | ||
| 218 | /// What an entry's text is known by, as `org-crypt-checksum` is. | |
| 219 | public static func checksum(_ contents: String) -> String { | |
| 220 | SHA256.hash(data: Data(contents.utf8)).map { String(format: "%02x", $0) }.joined() | |
| 221 | } | |
| 222 | ||
| 223 | /// The first entry's message in `text` encrypted with a passphrase; entries encrypted to a | |
| 224 | /// public key are passed over. | |
| 225 | public static func firstMessage(_ text: String) -> String? { | |
| 226 | let ns = text as NSString | |
| 227 | var search = NSRange(location: 0, length: ns.length) | |
| 228 | while true { | |
| 229 | let begin = ns.range(of: "-----BEGIN PGP MESSAGE-----", options: [], range: search) | |
| 230 | guard begin.location != NSNotFound else { return nil } | |
| 231 | let lineStart = ns.lineRange(for: NSRange(location: begin.location, length: 0)).location | |
| 232 | if let range = encryptedRange(text, at: lineStart), range.lowerBound == lineStart { | |
| 233 | let message = ns.substring(with: NSRange(range)) | |
| 234 | if let data = try? OpenPGP.dearmor(message), OpenPGP.isSymmetric(data) { return message } | |
| 235 | } | |
| 236 | search = NSRange(location: NSMaxRange(begin), length: ns.length - NSMaxRange(begin)) | |
| 237 | } | |
| 238 | } | |
| 239 | ||
| 240 | /// Whether `passphrase` opens `message`. | |
| 241 | public static func opens(_ message: String, passphrase: String) -> Bool { | |
| 242 | (try? OpenPGP.decrypt(OpenPGP.dearmor(message), passphrase: passphrase)) != nil | |
| 243 | } | |
| 137 | 244 | } |
Sources/OrgDocument/Crypt.swift added +328 · view
| @@ -0,0 +1,328 @@ | ||
| 1 | import Foundation | |
| 2 | import OrgCore | |
| 3 | ||
| 4 | /// Why a file can't be written: what it would put on disk unencrypted. | |
| 5 | public enum CryptHold: Error, Equatable, Sendable { | |
| 6 | /// This many crypt-tagged entries with text aren't encrypted, and their passphrase isn't known. | |
| 7 | case entries(Int) | |
| 8 | /// An encrypted file (`.org.gpg`) whose passphrase isn't known. | |
| 9 | case file | |
| 10 | /// Saving failed for a reason a passphrase can't fix, said here: an entry with text below | |
| 11 | /// a message that the file's passphrase doesn't open. | |
| 12 | case blocked(String) | |
| 13 | } | |
| 14 | ||
| 15 | /// Why an encrypted file can't be read. | |
| 16 | public enum CryptReadError: Error, Equatable, Sendable { | |
| 17 | /// Its passphrase isn't known. | |
| 18 | case locked | |
| 19 | case wrongPassphrase | |
| 20 | case failed(String) | |
| 21 | } | |
| 22 | ||
| 23 | /// What the session knows about encrypted text, by file: the passphrases unlocked while the | |
| 24 | /// file is open, and for entries org-crypt encrypts on save (`org-crypt-use-before-save-magic`) | |
| 25 | /// the messages and the text each holds. Through `CryptFileSystem`, buffers keep the | |
| 26 | /// decrypted text while the file holds messages. | |
| 27 | public final class CryptVault: @unchecked Sendable { | |
| 28 | private let lock = NSLock() | |
| 29 | private var entries = false | |
| 30 | private var entryTag = "crypt" | |
| 31 | private var passphrases: [String: String] = [:] | |
| 32 | /// By file: messages for entry texts by checksum, to give an unchanged entry its message again. | |
| 33 | private var reuse: [String: [String: String]] = [:] | |
| 34 | /// By file: the text of each message this session wrote, to read the file back as the buffer has it. | |
| 35 | private var revealed: [String: [String: String]] = [:] | |
| 36 | /// By file: whether the encrypted file was armored when read. | |
| 37 | private var armored: [String: Bool] = [:] | |
| 38 | /// Files that seal tagged entries until they close, whatever the setting says now: those | |
| 39 | /// it was on for, so that turning it off never writes what was encrypted in plaintext. | |
| 40 | private var sealing: Set<String> = [] | |
| 41 | /// Files open in a buffer. Only they keep what the vault knows past a write. | |
| 42 | private var open: Set<String> = [] | |
| 43 | /// By encrypted file: its bytes on disk and their text, last read or written. | |
| 44 | private var lastFile: [String: (encrypted: [UInt8], plain: [UInt8])] = [:] | |
| 45 | ||
| 46 | public init() {} | |
| 47 | ||
| 48 | private func locked<T>(_ body: () throws -> T) rethrows -> T { | |
| 49 | lock.lock() | |
| 50 | defer { lock.unlock() } | |
| 51 | return try body() | |
| 52 | } | |
| 53 | ||
| 54 | private static func key(_ path: String) -> String { URL(fileURLWithPath: path).standardizedFileURL.path } | |
| 55 | ||
| 56 | /// Whether `path` is a whole encrypted file, as EasyPG's `epa-file` opens `.gpg` files. | |
| 57 | public static func isEncryptedFile(_ path: String) -> Bool { path.hasSuffix(".gpg") } | |
| 58 | ||
| 59 | /// `org-crypt-use-before-save-magic`. | |
| 60 | public var encryptsTaggedEntries: Bool { | |
| 61 | get { locked { entries } } | |
| 62 | set { locked { entries = newValue } } | |
| 63 | } | |
| 64 | ||
| 65 | /// `org-crypt-tag-matcher`. | |
| 66 | public var tag: String { | |
| 67 | get { locked { entryTag } } | |
| 68 | set { locked { entryTag = newValue } } | |
| 69 | } | |
| 70 | ||
| 71 | public func passphrase(for path: String) -> String? { | |
| 72 | locked { passphrases[Self.key(path)] } | |
| 73 | } | |
| 74 | ||
| 75 | /// Whether saving `key` seals its tagged entries: the setting is on, or was while the | |
| 76 | /// file was open. Call with the lock held. | |
| 77 | private func seals(_ key: String) -> Bool { | |
| 78 | if entries, open.contains(key) { sealing.insert(key) } | |
| 79 | return entries || sealing.contains(key) || !(revealed[key]?.isEmpty ?? true) | |
| 80 | } | |
| 81 | ||
| 82 | /// Whether saving `path` encrypts its tagged entries. | |
| 83 | public func sealsEntries(for path: String) -> Bool { | |
| 84 | let key = Self.key(path) | |
| 85 | return locked { seals(key) } | |
| 86 | } | |
| 87 | ||
| 88 | /// `passphrase` encrypts and decrypts `path` until it's forgotten. Messages kept for reuse | |
| 89 | /// under another passphrase are dropped. | |
| 90 | public func unlock(_ passphrase: String, for path: String) { | |
| 91 | let key = Self.key(path) | |
| 92 | locked { | |
| 93 | if passphrases[key] != passphrase { | |
| 94 | reuse[key] = nil | |
| 95 | lastFile[key] = nil | |
| 96 | } | |
| 97 | passphrases[key] = passphrase | |
| 98 | _ = seals(key) | |
| 99 | } | |
| 100 | } | |
| 101 | ||
| 102 | /// Drops the passphrase of `path`; the next save that needs it is held. | |
| 103 | public func forgetPassphrase(for path: String) { | |
| 104 | let key = Self.key(path) | |
| 105 | locked { | |
| 106 | passphrases[key] = nil | |
| 107 | reuse[key] = nil | |
| 108 | } | |
| 109 | } | |
| 110 | ||
| 111 | private func dropIfClosed(_ key: String) { | |
| 112 | locked { | |
| 113 | guard !open.contains(key) else { return } | |
| 114 | passphrases[key] = nil | |
| 115 | reuse[key] = nil | |
| 116 | revealed[key] = nil | |
| 117 | armored[key] = nil | |
| 118 | lastFile[key] = nil | |
| 119 | sealing.remove(key) | |
| 120 | } | |
| 121 | } | |
| 122 | ||
| 123 | /// Whether the vault keeps anything for `path`. | |
| 124 | public func keepsAnything(for path: String) -> Bool { | |
| 125 | let key = Self.key(path) | |
| 126 | return locked { passphrases[key] != nil || !(revealed[key]?.isEmpty ?? true) || !(reuse[key]?.isEmpty ?? true) || lastFile[key] != nil || sealing.contains(key) } | |
| 127 | } | |
| 128 | ||
| 129 | /// `path` is open in a buffer. | |
| 130 | public func opened(_ path: String) { | |
| 131 | let key = Self.key(path) | |
| 132 | locked { _ = open.insert(key) } | |
| 133 | } | |
| 134 | ||
| 135 | /// Drops everything kept for `path`, as when its buffer closes. | |
| 136 | public func close(_ path: String) { | |
| 137 | let key = Self.key(path) | |
| 138 | locked { | |
| 139 | open.remove(key) | |
| 140 | passphrases[key] = nil | |
| 141 | reuse[key] = nil | |
| 142 | revealed[key] = nil | |
| 143 | armored[key] = nil | |
| 144 | sealing.remove(key) | |
| 145 | lastFile[key] = nil | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 149 | /// The entry of `path` holding `plaintext` was decrypted from `message`: while it stays | |
| 150 | /// so, saving writes `message` back unchanged. | |
| 151 | public func remember(message: String, plaintext: String, for path: String) { | |
| 152 | let key = Self.key(path) | |
| 153 | locked { | |
| 154 | reuse[key, default: [:]][OrgCrypt.checksum(plaintext)] = message | |
| 155 | _ = seals(key) | |
| 156 | } | |
| 157 | } | |
| 158 | ||
| 159 | /// What keeps `text`, the buffer of `path`, from being written: tagged entries without a | |
| 160 | /// known passphrase, or an encrypted file without one. Nil when it can be written. | |
| 161 | public func hold(_ text: String, for path: String) -> CryptHold? { | |
| 162 | let key = Self.key(path) | |
| 163 | let (passphrase, entries, tag) = locked { (passphrases[key], seals(key), entryTag) } | |
| 164 | guard passphrase == nil else { return nil } | |
| 165 | if Self.isEncryptedFile(path) { return .file } | |
| 166 | guard entries else { return nil } | |
| 167 | let count = OrgCrypt.unencrypted(text, tag: tag).count | |
| 168 | return count > 0 ? .entries(count) : nil | |
| 169 | } | |
| 170 | ||
| 171 | /// Whether `text`, the buffer of `path`, holds anything that isn't on disk as it shows: | |
| 172 | /// an encrypted file, or entries decrypted that saving encrypts. Such a buffer is left out | |
| 173 | /// of what other views read and keep (`DocumentSession.openTexts`). | |
| 174 | public func isPrivate(_ text: String, for path: String) -> Bool { | |
| 175 | if Self.isEncryptedFile(path) { return true } | |
| 176 | let key = Self.key(path) | |
| 177 | let (entries, tag, revealing) = locked { (seals(key), entryTag, !(revealed[key]?.isEmpty ?? true)) } | |
| 178 | return revealing || (entries && !OrgCrypt.unencrypted(text, tag: tag).isEmpty) | |
| 179 | } | |
| 180 | ||
| 181 | // MARK: - Reading and writing | |
| 182 | ||
| 183 | /// The text of messages this session wrote for `path`. | |
| 184 | public func revealedMessages(for path: String) -> [String: String] { | |
| 185 | locked { revealed[Self.key(path)] ?? [:] } | |
| 186 | } | |
| 187 | ||
| 188 | /// `bytes` from disk as the buffer of `path` has them: the file decrypted, and the | |
| 189 | /// messages this session wrote (`messages`, by default those known now) back to their text. | |
| 190 | public func plain(_ bytes: [UInt8], for path: String, messages: [String: String]? = nil) throws -> [UInt8] { | |
| 191 | var bytes = bytes | |
| 192 | if Self.isEncryptedFile(path) { bytes = try decryptFile(bytes, for: path) } | |
| 193 | let known = messages ?? revealedMessages(for: path) | |
| 194 | guard !known.isEmpty, var text = Self.text(bytes), text.contains("-----BEGIN PGP MESSAGE-----") else { return bytes } | |
| 195 | for (message, plaintext) in known where text.contains(message) { | |
| 196 | text = text.replacingOccurrences(of: message, with: plaintext) | |
| 197 | } | |
| 198 | return Array(text.utf8) | |
| 199 | } | |
| 200 | ||
| 201 | /// `bytes`, the buffer of `path`, as the file holds them: tagged entries encrypted, then | |
| 202 | /// the file encrypted, and the messages written for entries. Throws `CryptHold` when a | |
| 203 | /// passphrase is needed and not known. | |
| 204 | public func cipher(_ bytes: [UInt8], for path: String) throws -> (bytes: [UInt8], messages: [(message: String, plaintext: String)], plain: [UInt8]?) { | |
| 205 | let key = Self.key(path) | |
| 206 | let (passphrase, entries, tag, known) = locked { (passphrases[key], seals(key), entryTag, reuse[key] ?? [:]) } | |
| 207 | var bytes = bytes | |
| 208 | var messages: [(String, String)] = [] | |
| 209 | if entries, let text = Self.text(bytes), text.contains(tag) { | |
| 210 | if let passphrase { | |
| 211 | let sealed = try OrgCrypt.seal(text, passphrase: passphrase, tag: tag, reuse: { known[$0] }) | |
| 212 | bytes = Array(sealed.text.utf8) | |
| 213 | messages = sealed.messages | |
| 214 | } else { | |
| 215 | let count = OrgCrypt.unencrypted(text, tag: tag).count | |
| 216 | if count > 0 { throw CryptHold.entries(count) } | |
| 217 | } | |
| 218 | } | |
| 219 | if Self.isEncryptedFile(path) { | |
| 220 | guard let passphrase else { throw CryptHold.file } | |
| 221 | let plain = bytes | |
| 222 | // The text the file holds already (a snapshot of it) is its bytes on disk, without | |
| 223 | // another key's 65 MB of hashing. | |
| 224 | if let last = locked({ lastFile[key] }), last.plain == plain { return (last.encrypted, messages, plain) } | |
| 225 | let message = try OpenPGP.encryptedMessage(Data(bytes), passphrase: passphrase) | |
| 226 | bytes = locked { armored[key] ?? false } ? Array(OpenPGP.armor(message).utf8) : [UInt8](message) | |
| 227 | return (bytes, messages, plain) | |
| 228 | } | |
| 229 | return (bytes, messages, nil) | |
| 230 | } | |
| 231 | ||
| 232 | /// `cipher`'s result was written to `path`: reading it back gives the messages' text, and | |
| 233 | /// an unchanged entry keeps its message at the next save. Messages no longer in the file | |
| 234 | /// are forgotten. | |
| 235 | public func didWrite(_ written: (bytes: [UInt8], messages: [(message: String, plaintext: String)], plain: [UInt8]?), to path: String) { | |
| 236 | let key = Self.key(path) | |
| 237 | locked { | |
| 238 | // A file that isn't open keeps nothing (passphrase, messages, text) once the | |
| 239 | // write's own reads are done. | |
| 240 | if !open.contains(key) { | |
| 241 | DispatchQueue.main.async { [weak self] in self?.dropIfClosed(key) } | |
| 242 | } | |
| 243 | revealed[key] = Dictionary(written.messages.map { ($0.message, $0.plaintext) }, uniquingKeysWith: { a, _ in a }) | |
| 244 | reuse[key] = Dictionary(written.messages.map { (OrgCrypt.checksum($0.plaintext), $0.message) }, uniquingKeysWith: { a, _ in a }) | |
| 245 | if let plain = written.plain { lastFile[key] = (written.bytes, plain) } | |
| 246 | } | |
| 247 | } | |
| 248 | ||
| 249 | /// Whether `passphrase` opens the encrypted file `bytes`; an empty file takes any. | |
| 250 | public static func opens(_ bytes: [UInt8], passphrase: String) -> Bool { | |
| 251 | bytes.isEmpty || (try? OpenPGP.decryptFile(Data(bytes), passphrase: passphrase)) != nil | |
| 252 | } | |
| 253 | ||
| 254 | private func decryptFile(_ bytes: [UInt8], for path: String) throws -> [UInt8] { | |
| 255 | // New File makes an empty file: it has no passphrase until it's first saved. | |
| 256 | guard !bytes.isEmpty else { return [] } | |
| 257 | let key = Self.key(path) | |
| 258 | guard let passphrase = locked({ passphrases[key] }) else { throw CryptReadError.locked } | |
| 259 | // Saving reads the file two or three times; each key costs 65 MB of hashing. | |
| 260 | if let last = locked({ lastFile[key] }), last.encrypted == bytes { return last.plain } | |
| 261 | let data = Data(bytes) | |
| 262 | do { | |
| 263 | let plain = [UInt8](try OpenPGP.decryptFile(data, passphrase: passphrase)) | |
| 264 | locked { | |
| 265 | armored[key] = OpenPGP.isArmored(data) | |
| 266 | lastFile[key] = (bytes, plain) | |
| 267 | } | |
| 268 | return plain | |
| 269 | } catch let failure as OpenPGP.Failure { | |
| 270 | throw failure == OpenPGP.wrongPassphrase ? CryptReadError.wrongPassphrase : CryptReadError.failed(failure.description) | |
| 271 | } | |
| 272 | } | |
| 273 | ||
| 274 | /// `bytes` as text when they are UTF-8 exactly, a BOM included. | |
| 275 | private static func text(_ bytes: [UInt8]) -> String? { | |
| 276 | let text = String(decoding: bytes, as: UTF8.self) | |
| 277 | return text.utf8.elementsEqual(bytes) ? text : nil | |
| 278 | } | |
| 279 | } | |
| 280 | ||
| 281 | /// Files read and written through a `CryptVault`: what the buffer holds decrypted goes to | |
| 282 | /// disk encrypted, and comes back as the buffer has it. | |
| 283 | public struct CryptFileSystem: FileSystem { | |
| 284 | public let base: FileSystem | |
| 285 | public let vault: CryptVault | |
| 286 | ||
| 287 | public init(base: FileSystem, vault: CryptVault) { | |
| 288 | self.base = base | |
| 289 | self.vault = vault | |
| 290 | } | |
| 291 | ||
| 292 | public func read(_ url: URL) throws -> [UInt8]? { | |
| 293 | try base.read(url).map { try vault.plain($0, for: url.path) } | |
| 294 | } | |
| 295 | ||
| 296 | public func replace(_ url: URL, with bytes: [UInt8]) throws -> [UInt8]? { | |
| 297 | let known = vault.revealedMessages(for: url.path) | |
| 298 | let written = try vault.cipher(bytes, for: url.path) | |
| 299 | let replaced = try base.replace(url, with: written.bytes) | |
| 300 | // The version replaced, as it read before this write's messages were known (and while | |
| 301 | // the encrypted file's last bytes still decrypt from memory). | |
| 302 | let previous = replaced.map { (try? vault.plain($0, for: url.path, messages: known)) ?? $0 } | |
| 303 | vault.didWrite(written, to: url.path) | |
| 304 | return previous | |
| 305 | } | |
| 306 | } | |
| 307 | ||
| 308 | /// Recovery versions and snapshots through a `CryptVault`: kept encrypted as the file is. When | |
| 309 | /// that needs a passphrase that isn't known, `keep` throws `CryptHold`, so a caller that | |
| 310 | /// promises a copy stops; a snapshot is skipped. | |
| 311 | public struct CryptRecoveryStore: RecoveryStore { | |
| 312 | public let base: RecoveryStore | |
| 313 | public let vault: CryptVault | |
| 314 | ||
| 315 | public init(base: RecoveryStore, vault: CryptVault) { | |
| 316 | self.base = base | |
| 317 | self.vault = vault | |
| 318 | } | |
| 319 | ||
| 320 | public func keep(_ bytes: [UInt8], for url: URL, label: String) throws { | |
| 321 | try base.keep(try vault.cipher(bytes, for: url.path).bytes, for: url, label: label) | |
| 322 | } | |
| 323 | ||
| 324 | public func keepSnapshot(_ bytes: [UInt8], for url: URL) throws { | |
| 325 | guard let encrypted = try? vault.cipher(bytes, for: url.path).bytes else { return } | |
| 326 | try base.keepSnapshot(encrypted, for: url) | |
| 327 | } | |
| 328 | } | |
Sources/OrgDocument/Saving.swift +30 −5 · view
| @@ -74,12 +74,12 @@ public struct Saver: Sendable { | ||
| 74 | 74 | let replaced = try fileSystem.replace(url, with: bytes) |
| 75 | 75 | state.didWrite(bytes) |
| 76 | 76 | if replaced != disk, let replaced { |
| 77 | try recovery.keep(replaced, for: url, label: "external") | |
| 78 | return .overwroteExternalChange(state.mergeOverwritten(replaced, base: disk ?? [])) | |
| 77 | return .overwroteExternalChange(keepOverwritten(replaced, base: disk ?? [], in: &state, url: url)) | |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | if let after = try fileSystem.read(url), after != bytes { |
| 82 | try recovery.keep(bytes, for: url, label: "local") | |
| 81 | // Ours is in the buffer whether or not a copy can be kept. | |
| 82 | try? recovery.keep(bytes, for: url, label: "local") | |
| 83 | 83 | return .changedAfterWrite(state.diskChanged(to: after)) |
| 84 | 84 | } |
| 85 | 85 | return merged.map { .mergedAndSaved($0) } ?? .saved |
| @@ -91,9 +91,34 @@ public struct Saver: Sendable { | ||
| 91 | 91 | /// one. The replaced version goes to recovery unless it is the merge base. |
| 92 | 92 | public func overwrite(_ state: inout DocumentState, to url: URL) throws { |
| 93 | 93 | let bytes = try state.encodedText() |
| 94 | if let replaced = try fileSystem.replace(url, with: bytes), replaced != state.mergeBase { | |
| 94 | // The version Keep Mine replaces goes to recovery first; when it can't, nothing is written. | |
| 95 | let disk = try fileSystem.read(url) | |
| 96 | if let disk, disk != state.mergeBase { try recovery.keep(disk, for: url, label: "external") } | |
| 97 | let base = state.mergeBase | |
| 98 | let replaced = try fileSystem.replace(url, with: bytes) | |
| 99 | state.didWrite(bytes) | |
| 100 | if let replaced, replaced != disk, replaced != base { | |
| 101 | _ = keepOverwritten(replaced, base: base, in: &state, url: url, merge: false) | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | /// `replaced`, a version another writer put on disk just before ours replaced it, kept: in | |
| 106 | /// recovery and, when `merge`, merged into the buffer. When recovery can't keep it (it holds | |
| 107 | /// text that can only be kept encrypted, without a passphrase) and it isn't merged, it goes | |
| 108 | /// into the buffer beside ours between conflict markers, so it's never lost. | |
| 109 | func keepOverwritten(_ replaced: [UInt8], base: [UInt8], in state: inout DocumentState, url: URL, merge: Bool = true) -> DocumentState.ExternalChange { | |
| 110 | let change: DocumentState.ExternalChange = merge ? state.mergeOverwritten(replaced, base: base) : .conflict([]) | |
| 111 | do { | |
| 95 | 112 | try recovery.keep(replaced, for: url, label: "external") |
| 113 | return merge ? change : .unchanged | |
| 114 | } catch { | |
| 115 | if case .merged = change { return change } | |
| 116 | let theirs = SourceText(bytes: replaced).text | |
| 117 | let both = mergeWithMarkers(base: SourceText(bytes: base).text, ours: state.text, theirs: theirs, oursLabel: "yours", theirsLabel: "disk") | |
| 118 | let edits = lineEdits(from: state.text, to: both) | |
| 119 | guard (try? state.apply(edits, baseRevision: state.revision)) != nil else { return change } | |
| 120 | // A conflict with none listed: both versions are in the buffer between markers. | |
| 121 | return .conflict([]) | |
| 96 | 122 | } |
| 97 | state.didWrite(bytes) | |
| 98 | 123 | } |
| 99 | 124 | } |
Sources/Orgstar/ContentView.swift +25 −10 · view
| @@ -35,6 +35,8 @@ struct ContentView: View { | ||
| 35 | 35 | @State private var menuToday: [AgendaSnapshot.Row] = [] |
| 36 | 36 | @State private var hour = 0 |
| 37 | 37 | @AppStorage("saveMode") private var saveMode = SaveMode.automatic |
| 38 | @AppStorage("cryptBeforeSave") private var cryptBeforeSave = false | |
| 39 | @AppStorage("cryptTagMatcher") private var cryptTagMatcher = "crypt" | |
| 38 | 40 | @AppStorage("keymap") private var preset = KeymapPreset.emacs |
| 39 | 41 | @AppStorage("optionAsMeta") private var optionAsMeta = OptionAsMeta.left.rawValue |
| 40 | 42 | @State private var keymap = KeymapPreset.emacs.keymap |
| @@ -194,6 +196,7 @@ struct ContentView: View { | ||
| 194 | 196 | .frame(height: 190) |
| 195 | 197 | Divider() |
| 196 | 198 | } |
| 199 | CryptHoldBar(session: session) { commands.run("app.crypt.save") } | |
| 197 | 200 | ModeLine(session: session, commands: commands) |
| 198 | 201 | EchoArea(commands: commands) |
| 199 | 202 | } |
| @@ -404,6 +407,9 @@ struct ContentView: View { | ||
| 404 | 407 | commands.editor = nil |
| 405 | 408 | } |
| 406 | 409 | .onChange(of: saveMode, initial: true) { _, mode in session.saveMode = mode } |
| 410 | .modifier(CryptSettings(session: session, cryptBeforeSave: cryptBeforeSave, cryptTagMatcher: cryptTagMatcher) { path in | |
| 411 | panel = .crypt(UUID(), CryptRequest(mode: .openFile, path: path, offset: 0)) | |
| 412 | }) | |
| 407 | 413 | .onChange(of: options, initial: true) { _, options in session.options = options } |
| 408 | 414 | .onAppear { TimerModel.shared.onDone = { [commands] in commands.show($0) } } |
| 409 | 415 | .onReceive(NotificationCenter.default.publisher(for: UserDefaults.didChangeNotification)) { _ in defaultsChanges += 1 } |
| @@ -754,6 +760,7 @@ struct ContentView: View { | ||
| 754 | 760 | #if !APPSTORE |
| 755 | 761 | let functions = ["pdf": "org-latex-export-to-pdf", "latex": "org-latex-export-to-latex", "text": "org-ascii-export-to-ascii"] |
| 756 | 762 | guard let function = functions[format] else { return } |
| 763 | if let refusal = session.refusesEmacsCopy(path) { return commands.show(refusal) } | |
| 757 | 764 | commands.show(String(localized: "Exporting with Emacs…")) |
| 758 | 765 | commands.runInEmacs { |
| 759 | 766 | do { |
| @@ -883,17 +890,18 @@ struct ContentView: View { | ||
| 883 | 890 | let paths = workspace.agendaFilePaths() |
| 884 | 891 | guard reach(paths + (combined ? [OrgPreferences.icalendarCombinedFile()] : [])) else { return } |
| 885 | 892 | let read = { (path: String) -> (text: String, settings: OrgSettings)? in |
| 886 | guard let text = session.openDocuments.first(where: { $0.path == path })?.document.text ?? (try? String(contentsOfFile: path, encoding: .utf8)) else { return nil } | |
| 893 | guard let text = session.exportText(of: path) else { return nil } | |
| 887 | 894 | return (text, Preferences.orgSettings.resolvingSetupFiles(in: text, path: path, read: OrgSettings.readFile)) |
| 888 | 895 | } |
| 896 | let note = paths.contains(where: session.exportLeavesOut) ? " " + DocumentSession.exportNote : "" | |
| 889 | 897 | do { |
| 890 | 898 | let options = OrgPreferences.icalendarOptions() |
| 891 | 899 | if combined { |
| 892 | 900 | let url = try ICalendarFiles.combine(paths, to: OrgPreferences.icalendarCombinedFile(), options: options, read: read) |
| 893 | commands.show(String(localized: "Exported \(paths.count) agenda files to \(url.lastPathComponent)")) | |
| 901 | commands.show(String(localized: "Exported \(paths.count) agenda files to \(url.lastPathComponent)") + note) | |
| 894 | 902 | } else { |
| 895 | 903 | let written = try ICalendarFiles.exportEach(paths, options: options, read: read) |
| 896 | commands.show(String(localized: "Exported \(written.count) agenda files to iCalendar")) | |
| 904 | commands.show(String(localized: "Exported \(written.count) agenda files to iCalendar") + note) | |
| 897 | 905 | } |
| 898 | 906 | } catch { |
| 899 | 907 | commands.show(String(localized: "Can't export: \(error.localizedDescription)")) |
| @@ -902,12 +910,17 @@ struct ContentView: View { | ||
| 902 | 910 | |
| 903 | 911 | /// org-crypt's commands at the caret, through the passphrase sheet. |
| 904 | 912 | private func crypt(_ id: String) { |
| 913 | if id == "app.crypt.save" { | |
| 914 | guard let path = session.path, let hold = session.held[path] else { return } | |
| 915 | panel = .crypt(UUID(), CryptRequest.save(path, hold: hold)) | |
| 916 | return | |
| 917 | } | |
| 905 | 918 | guard let editor = commands.editor, let path = session.path else { return commands.show(String(localized: "No file is open")) } |
| 906 | 919 | let caret = editor.context().caret |
| 907 | 920 | let text = editor.context().text |
| 908 | 921 | switch id { |
| 909 | 922 | case "app.crypt.forget-passphrase": |
| 910 | CryptPassphrases.forget(path) | |
| 923 | session.forgetPassphrase(for: path) | |
| 911 | 924 | commands.show(String(localized: "Passphrase forgotten for \((path as NSString).lastPathComponent)")) |
| 912 | 925 | case "app.crypt.encrypt-entries": |
| 913 | 926 | panel = .crypt(UUID(), CryptRequest(mode: .encryptAll(tag: OrgPreferences.cryptTag()), path: path, offset: caret)) |
| @@ -996,8 +1009,10 @@ struct ContentView: View { | ||
| 996 | 1009 | case .shareSubtree(_, let share): |
| 997 | 1010 | ShareSubtreeSheet(share: share) { commands.show($0) } |
| 998 | 1011 | case .crypt(_, let request): |
| 999 | CryptSheet(request: request, text: { session.document?.text ?? "" }, apply: { applyText($0) }) { message in | |
| 1012 | CryptSheet(request: request, session: session, text: { session.document(of: request.path)?.text ?? "" }, apply: { applyText($0) }) { message in | |
| 1000 | 1013 | self.panel = nil |
| 1014 | // An encrypted file left closed: the sidebar shows the open file again. | |
| 1015 | if case .openFile = request.mode, !session.isOpen(request.path) { selectedFile = session.path } | |
| 1001 | 1016 | if let message { commands.show(message) } |
| 1002 | 1017 | } |
| 1003 | 1018 | case .conflict: |
| @@ -1079,9 +1094,8 @@ struct ContentView: View { | ||
| 1079 | 1094 | let loaded = Publish.projects(fromConfig: config, root: workspace.rootPaths.first) |
| 1080 | 1095 | if let problem = loaded.problems.first { commands.show(problem) } |
| 1081 | 1096 | guard !loaded.projects.isEmpty else { return commands.show(String(localized: "No [[publish]] projects in config.toml")) } |
| 1082 | let read = { (path: String) -> String? in | |
| 1083 | session.openDocuments.first { $0.path == path }?.document.text ?? (try? String(contentsOfFile: path, encoding: .utf8)) | |
| 1084 | } | |
| 1097 | let read = { (path: String) -> String? in session.exportText(of: path) } | |
| 1098 | let note = session.openPaths.contains(where: session.exportLeavesOut) ? " " + DocumentSession.exportNote : "" | |
| 1085 | 1099 | let codeStyle = HTMLCodeStyle(highlighter: PaneView.highlighter, theme: theme) |
| 1086 | 1100 | func run(_ chosen: [PublishProject], only: String? = nil) { |
| 1087 | 1101 | // The chosen projects and their components read and write these folders. |
| @@ -1091,8 +1105,8 @@ struct ContentView: View { | ||
| 1091 | 1105 | let report = try Publish.publish(chosen, all: loaded.projects, only: only, read: read) { function, text, path, bodyOnly in |
| 1092 | 1106 | try Publish.export(function, text: text, path: path, bodyOnly: bodyOnly, settings: Preferences.orgSettings, codeStyle: codeStyle) |
| 1093 | 1107 | } |
| 1094 | commands.show(report.skipped.isEmpty ? String(localized: "Published \(report.published.count) files") | |
| 1095 | : String(localized: "Published \(report.published.count) files, \(report.skipped.count) up to date")) | |
| 1108 | commands.show((report.skipped.isEmpty ? String(localized: "Published \(report.published.count) files") | |
| 1109 | : String(localized: "Published \(report.published.count) files, \(report.skipped.count) up to date")) + note) | |
| 1096 | 1110 | } catch { |
| 1097 | 1111 | commands.show("\(error)") |
| 1098 | 1112 | } |
| @@ -1524,6 +1538,7 @@ struct ContentView: View { | ||
| 1524 | 1538 | copyRichText() |
| 1525 | 1539 | case "app.share-subtree": |
| 1526 | 1540 | guard let path = session.path else { return commands.show(String(localized: "No file is open")) } |
| 1541 | if let refusal = session.refusesSubtreeShare(path, at: session.caret) { return commands.show(refusal) } | |
| 1527 | 1542 | guard let share = session.subtreeShare(path, at: session.caret) else { return commands.show(String(localized: "Not in a subtree")) } |
| 1528 | 1543 | panel = .shareSubtree(UUID(), share) |
| 1529 | 1544 | case "app.export-dialog": |
Sources/Orgstar/CryptHoldBar.swift added +45 · view
| @@ -0,0 +1,45 @@ | ||
| 1 | import OrgApp | |
| 2 | import OrgDocument | |
| 3 | import SwiftUI | |
| 4 | ||
| 5 | /// Above the mode line while the focused file isn't saved because it would put text on disk | |
| 6 | /// unencrypted: why, and the button that asks for the passphrase. Stays while it applies. | |
| 7 | struct CryptHoldBar: View { | |
| 8 | let session: DocumentSession | |
| 9 | let encrypt: () -> Void | |
| 10 | ||
| 11 | var body: some View { | |
| 12 | if let path = session.path, let hold = session.held[path] { | |
| 13 | HStack(spacing: 8) { | |
| 14 | Image(systemName: "lock.trianglebadge.exclamationmark").foregroundStyle(.orange) | |
| 15 | Text(hold.notice(for: path)).lineLimit(3) | |
| 16 | Spacer(minLength: 8) | |
| 17 | if hold.takesPassphrase { Button(hold == .file ? "Set Passphrase…" : "Encrypt…", action: encrypt) } | |
| 18 | } | |
| 19 | .font(.callout) | |
| 20 | .padding(.horizontal, 10) | |
| 21 | .padding(.vertical, 5) | |
| 22 | .frame(maxWidth: .infinity, alignment: .leading) | |
| 23 | .background(Color.orange.opacity(0.12)) | |
| 24 | .accessibilityElement(children: .combine) | |
| 25 | } | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | /// The session follows the org-crypt settings, and asks for the passphrase of an encrypted file | |
| 30 | /// it was asked to open. | |
| 31 | struct CryptSettings: ViewModifier { | |
| 32 | let session: DocumentSession | |
| 33 | let cryptBeforeSave: Bool | |
| 34 | let cryptTagMatcher: String | |
| 35 | let unlock: (String) -> Void | |
| 36 | ||
| 37 | func body(content: Content) -> some View { | |
| 38 | content | |
| 39 | .onChange(of: cryptBeforeSave, initial: true) { _, on in session.encryptsTaggedEntries = on } | |
| 40 | .onChange(of: cryptTagMatcher, initial: true) { session.cryptTag = OrgPreferences.cryptTag() } | |
| 41 | .onChange(of: session.unlockRequest, initial: true) { _, path in | |
| 42 | if let path { unlock(path) } | |
| 43 | } | |
| 44 | } | |
| 45 | } | |
Sources/Orgstar/EditorWindowView.swift +1 · view
| @@ -24,6 +24,7 @@ struct EditorWindowView: View { | ||
| 24 | 24 | } |
| 25 | 25 | .safeAreaInset(edge: .bottom, spacing: 0) { |
| 26 | 26 | VStack(spacing: 0) { |
| 27 | CryptHoldBar(session: session) { run("app.crypt.save") } | |
| 27 | 28 | ModeLine(session: session, commands: commands) |
| 28 | 29 | EchoArea(commands: commands) |
| 29 | 30 | } |
Sources/Orgstar/OrgstarApp.swift +62 −5 · view
| @@ -324,8 +324,8 @@ enum UnsavedChanges { | ||
| 324 | 324 | /// Whether the open file can be left: saved in automatic mode, or as the user chooses in |
| 325 | 325 | /// explicit mode. A save that fails or conflicts keeps the file open. |
| 326 | 326 | static func resolve(_ session: DocumentSession) -> Bool { |
| 327 | guard session.isDirty else { return true } | |
| 328 | if session.saveMode == .automatic { return session.save() } | |
| 327 | guard session.isDirty, let path = session.path else { return true } | |
| 328 | if session.saveMode == .automatic { return save(session, path) } | |
| 329 | 329 | let alert = NSAlert() |
| 330 | 330 | alert.messageText = session.path.map { String(localized: "Save changes to \(($0 as NSString).lastPathComponent)?") } |
| 331 | 331 | ?? String(localized: "Save changes to this file?") |
| @@ -334,7 +334,7 @@ enum UnsavedChanges { | ||
| 334 | 334 | alert.addButton(withTitle: String(localized: "Don't Save")) |
| 335 | 335 | alert.addButton(withTitle: String(localized: "Cancel")) |
| 336 | 336 | switch alert.runModal() { |
| 337 | case .alertFirstButtonReturn: return session.save() | |
| 337 | case .alertFirstButtonReturn: return save(session, path) | |
| 338 | 338 | case .alertSecondButtonReturn: return true |
| 339 | 339 | default: return false |
| 340 | 340 | } |
| @@ -345,7 +345,7 @@ enum UnsavedChanges { | ||
| 345 | 345 | static func resolve(_ session: DocumentSession, paths: [String]) -> Bool { |
| 346 | 346 | let dirty = paths.filter(session.dirtyPaths.contains) |
| 347 | 347 | guard !dirty.isEmpty else { return true } |
| 348 | if session.saveMode == .automatic { return dirty.map(session.save).allSatisfy { $0 } } | |
| 348 | if session.saveMode == .automatic { return dirty.map { save(session, $0) }.allSatisfy { $0 } } | |
| 349 | 349 | if dirty == [session.path] { return resolve(session) } |
| 350 | 350 | let alert = NSAlert() |
| 351 | 351 | alert.messageText = String(localized: "Save changes to \(dirty.count) files?") |
| @@ -354,11 +354,65 @@ enum UnsavedChanges { | ||
| 354 | 354 | alert.addButton(withTitle: String(localized: "Don't Save")) |
| 355 | 355 | alert.addButton(withTitle: String(localized: "Cancel")) |
| 356 | 356 | switch alert.runModal() { |
| 357 | case .alertFirstButtonReturn: return dirty.map(session.save).allSatisfy { $0 } | |
| 357 | case .alertFirstButtonReturn: return dirty.map { save(session, $0) }.allSatisfy { $0 } | |
| 358 | 358 | case .alertSecondButtonReturn: return true |
| 359 | 359 | default: return false |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | ||
| 363 | /// Saves `path`. One held for its passphrase asks for it, or whether to leave without saving. | |
| 364 | static func save(_ session: DocumentSession, _ path: String) -> Bool { | |
| 365 | if session.save(path) { return true } | |
| 366 | let name = (path as NSString).lastPathComponent | |
| 367 | guard let hold = session.held[path], hold.takesPassphrase else { | |
| 368 | // A save that failed otherwise (a conflict, an error, an entry the passphrase can't | |
| 369 | // encrypt) still lets the file be left without saving. | |
| 370 | let alert = NSAlert() | |
| 371 | alert.messageText = String(localized: "Changes to \(name) aren't saved") | |
| 372 | alert.informativeText = session.held[path]?.notice(for: path) ?? session.conflict ?? session.lastError ?? "" | |
| 373 | alert.addButton(withTitle: String(localized: "Cancel")) | |
| 374 | alert.addButton(withTitle: String(localized: "Don't Save")) | |
| 375 | return alert.runModal() == .alertSecondButtonReturn | |
| 376 | } | |
| 377 | // A new passphrase is typed twice; one that must open what's encrypted already, once. | |
| 378 | let twice = hold == .file || OrgCrypt.firstMessage(session.document(of: path)?.text ?? "") == nil | |
| 379 | let fields = (twice ? [String(localized: "Passphrase"), String(localized: "Repeat passphrase")] : [String(localized: "Passphrase")]).map { placeholder in | |
| 380 | let field = NSSecureTextField(frame: NSRect(x: 0, y: 0, width: 260, height: 22)) | |
| 381 | field.placeholderString = placeholder | |
| 382 | return field | |
| 383 | } | |
| 384 | let stack = NSStackView(views: fields) | |
| 385 | stack.orientation = .vertical | |
| 386 | stack.spacing = 6 | |
| 387 | stack.frame = NSRect(x: 0, y: 0, width: 260, height: CGFloat(fields.count) * 28) | |
| 388 | var problem: String? | |
| 389 | while true { | |
| 390 | let alert = NSAlert() | |
| 391 | alert.messageText = String(localized: "Changes to \(name) aren't saved") | |
| 392 | alert.informativeText = (problem.map { $0 + "\n\n" } ?? "") + hold.notice(for: path) + " " | |
| 393 | + String(localized: "Enter the passphrase to encrypt and save them, or leave without saving.") | |
| 394 | alert.accessoryView = stack | |
| 395 | alert.addButton(withTitle: String(localized: "Encrypt and Save")) | |
| 396 | alert.addButton(withTitle: String(localized: "Don't Save")) | |
| 397 | alert.addButton(withTitle: String(localized: "Cancel")) | |
| 398 | alert.window.initialFirstResponder = fields[0] | |
| 399 | switch alert.runModal() { | |
| 400 | case .alertFirstButtonReturn: | |
| 401 | let passphrase = fields[0].stringValue | |
| 402 | if passphrase.isEmpty { | |
| 403 | problem = String(localized: "Enter a passphrase.") | |
| 404 | } else if twice, fields[1].stringValue != passphrase { | |
| 405 | problem = String(localized: "The passphrases differ") | |
| 406 | } else if let failure = session.unlock(passphrase, for: path) { | |
| 407 | problem = failure | |
| 408 | } else { | |
| 409 | return !session.dirtyPaths.contains(path) | |
| 410 | } | |
| 411 | case .alertSecondButtonReturn: return true | |
| 412 | default: return false | |
| 413 | } | |
| 414 | } | |
| 415 | } | |
| 362 | 416 | } |
| 363 | 417 | |
| 364 | 418 | /// The open buffers, their order and carets, kept for the next launch. |
| @@ -425,6 +479,9 @@ struct OrgstarApp: App { | ||
| 425 | 479 | @State private var session: DocumentSession = { |
| 426 | 480 | let session = DocumentSession() |
| 427 | 481 | session.defaults = Preferences.orgSettings |
| 482 | // Before any window: capture and agenda edits can save before the main window opens. | |
| 483 | session.encryptsTaggedEntries = OrgPreferences.cryptBeforeSave() | |
| 484 | session.cryptTag = OrgPreferences.cryptTag() | |
| 428 | 485 | return session |
| 429 | 486 | }() |
| 430 | 487 | |
Sources/OrgstarMobile/EditorScreen.swift +39 −6 · view
| @@ -134,10 +134,34 @@ struct EditorScreen: View { | ||
| 134 | 134 | if let editor, let textView { |
| 135 | 135 | EditorTextView(editor: editor, view: textView, palette: { sheet = .palette }) |
| 136 | 136 | .ignoresSafeArea(.container, edges: .bottom) |
| 137 | } else if DocumentSession.isEncryptedFile(path), !session.isOpen(path) { | |
| 138 | ContentUnavailableView { | |
| 139 | Label("\((path as NSString).lastPathComponent) is encrypted", systemImage: "lock") | |
| 140 | } actions: { | |
| 141 | Button("Decrypt…") { sheet = .crypt(CryptRequest(mode: .openFile, path: path, offset: 0)) } | |
| 142 | } | |
| 137 | 143 | } else { |
| 138 | 144 | ProgressView() |
| 139 | 145 | } |
| 140 | 146 | } |
| 147 | // While the file isn't saved for want of a passphrase, and why; stays while it applies. | |
| 148 | .safeAreaInset(edge: .top, spacing: 0) { | |
| 149 | if let hold = session.held[path] { | |
| 150 | HStack(spacing: 10) { | |
| 151 | Image(systemName: "lock.trianglebadge.exclamationmark").foregroundStyle(.orange) | |
| 152 | Text(hold.notice(for: path)).font(.callout).fixedSize(horizontal: false, vertical: true) | |
| 153 | Spacer(minLength: 4) | |
| 154 | if hold.takesPassphrase { | |
| 155 | Button(hold == .file ? "Set Passphrase…" : "Encrypt…") { sheet = .crypt(CryptRequest.save(path, hold: hold)) } | |
| 156 | .buttonStyle(.borderedProminent) | |
| 157 | } | |
| 158 | } | |
| 159 | .padding(.horizontal, 14).padding(.vertical, 8) | |
| 160 | .glassEffect(.regular, in: .rect(cornerRadius: 18)) | |
| 161 | .padding(8) | |
| 162 | .accessibilityElement(children: .combine) | |
| 163 | } | |
| 164 | } | |
| 141 | 165 | .modifier(EditorTitle(title: session.bufferName(path) + (session.dirtyPaths.contains(path) ? " •" : ""), shown: !inSplit)) |
| 142 | 166 | .toolbar(.hidden, for: .tabBar) |
| 143 | 167 | .toolbar { |
| @@ -190,6 +214,8 @@ struct EditorScreen: View { | ||
| 190 | 214 | } |
| 191 | 215 | } |
| 192 | 216 | .sheet(item: $sheet, onDismiss: { |
| 217 | // An encrypted file opened with its passphrase. | |
| 218 | if editor == nil, session.isOpen(path) { start() } | |
| 193 | 219 | countVersions() |
| 194 | 220 | // After the sheet has gone, so a command's own prompt can show. |
| 195 | 221 | if let id = chosen { |
| @@ -394,6 +420,10 @@ struct EditorScreen: View { | ||
| 394 | 420 | } |
| 395 | 421 | } |
| 396 | 422 | if pane.path != path { session.open(path, in: pane) } |
| 423 | if session.unlockRequest == path { | |
| 424 | sheet = .crypt(CryptRequest(mode: .openFile, path: path, offset: 0)) | |
| 425 | return | |
| 426 | } | |
| 397 | 427 | model.editors.prune(session) |
| 398 | 428 | guard let editor = model.editors.editor(for: path, session: session, make: makeEditor) else { return } |
| 399 | 429 | let view = model.editors.view(for: pane.id, of: editor) |
| @@ -479,7 +509,9 @@ struct EditorScreen: View { | ||
| 479 | 509 | } else if id == EditorScreen.exportSubtreeCommand { |
| 480 | 510 | exportSubtree() |
| 481 | 511 | } else if id == "app.share-subtree" { |
| 482 | if let caret = self.editor?.editContext().caret, let share = session.subtreeShare(path, at: caret) { | |
| 512 | if let caret = self.editor?.editContext().caret, let refusal = session.refusesSubtreeShare(path, at: caret) { | |
| 513 | message = refusal | |
| 514 | } else if let caret = self.editor?.editContext().caret, let share = session.subtreeShare(path, at: caret) { | |
| 483 | 515 | sheet = .shareSubtree(share) |
| 484 | 516 | } else { |
| 485 | 517 | message = String(localized: "Not in a subtree") |
| @@ -730,15 +762,16 @@ extension EditorScreen { | ||
| 730 | 762 | return message = "Can't read \(project.name)'s base-directory, \(OrgPaths.abbreviatingWithTilde(project.baseDirectory))" |
| 731 | 763 | } |
| 732 | 764 | let read = { (file: String) -> String? in |
| 733 | session.openDocuments.first { $0.path == file }?.document.text ?? (try? String(contentsOfFile: file, encoding: .utf8)) | |
| 765 | session.exportText(of: file) | |
| 734 | 766 | } |
| 735 | 767 | let codeStyle = HTMLCodeStyle(highlighter: MobileEditor.highlighter, theme: model.theme) |
| 736 | 768 | // As the Export menu: no author unless the file has #+AUTHOR:. |
| 737 | 769 | let report = try Publish.publish(chosen, all: all, only: only, author: "", read: read) { function, text, file, bodyOnly in |
| 738 | 770 | try Publish.export(function, text: text, path: file, bodyOnly: bodyOnly, settings: OrgPreferences.orgSettings(), codeStyle: codeStyle, author: "") |
| 739 | 771 | } |
| 740 | message = report.skipped.isEmpty ? String(localized: "Published \(report.published.count) files") | |
| 741 | : String(localized: "Published \(report.published.count) files, \(report.skipped.count) up to date") | |
| 772 | let note = session.openPaths.contains(where: session.exportLeavesOut) ? " " + DocumentSession.exportNote : "" | |
| 773 | message = (report.skipped.isEmpty ? String(localized: "Published \(report.published.count) files") | |
| 774 | : String(localized: "Published \(report.published.count) files, \(report.skipped.count) up to date")) + note | |
| 742 | 775 | } catch { |
| 743 | 776 | message = "\(error)" |
| 744 | 777 | } |
| @@ -751,7 +784,7 @@ extension EditorScreen { | ||
| 751 | 784 | let context = editor.editContext() |
| 752 | 785 | switch id { |
| 753 | 786 | case "app.crypt.forget-passphrase": |
| 754 | CryptPassphrases.forget(path) | |
| 787 | session.forgetPassphrase(for: path) | |
| 755 | 788 | message = "Passphrase forgotten for \((path as NSString).lastPathComponent)" |
| 756 | 789 | case "app.crypt.encrypt-entries": |
| 757 | 790 | sheet = .crypt(CryptRequest(mode: .encryptAll(tag: OrgPreferences.cryptTag()), path: path, offset: context.caret)) |
| @@ -1227,7 +1260,7 @@ struct CryptScreen: View { | ||
| 1227 | 1260 | |
| 1228 | 1261 | var body: some View { |
| 1229 | 1262 | NavigationStack { |
| 1230 | CryptSheet(request: request, text: { session.document?.text ?? "" }, apply: apply) { message in | |
| 1263 | CryptSheet(request: request, session: session, text: { session.document(of: request.path)?.text ?? "" }, apply: apply) { message in | |
| 1231 | 1264 | dismiss() |
| 1232 | 1265 | if let message { report(message) } |
| 1233 | 1266 | } |
Sources/OrgstarMobile/ExportMenu.swift +10 −5 · view
| @@ -272,20 +272,25 @@ struct ExportItems: View { | ||
| 272 | 272 | /// (`org-icalendar-combine-agenda-files`), named as `org-icalendar-combined-agenda-file` is. |
| 273 | 273 | struct AgendaCalendars: Transferable { |
| 274 | 274 | let paths: [String] |
| 275 | /// The open files' text, which may not be saved yet. | |
| 276 | let open: [String: String] | |
| 275 | /// The files' text for the export: open buffers', or what's on disk for those holding | |
| 276 | /// what's encrypted there; encrypted files are left out. | |
| 277 | let texts: [String: String] | |
| 278 | /// Said after the export when it left something out. | |
| 279 | let note: String | |
| 277 | 280 | |
| 278 | 281 | /// Nil without agenda files. |
| 279 | 282 | @MainActor init?(model: MobileModel) { |
| 280 | 283 | guard let paths = model.workspace?.agendaFilePaths(), !paths.isEmpty else { return nil } |
| 281 | 284 | self.paths = paths |
| 282 | open = Dictionary(model.session.openDocuments.map { ($0.path, $0.document.text) }, uniquingKeysWith: { first, _ in first }) | |
| 285 | let session = model.session | |
| 286 | texts = Dictionary(paths.compactMap { path in session.exportText(of: path).map { (path, $0) } }, uniquingKeysWith: { first, _ in first }) | |
| 287 | note = paths.contains(where: session.exportLeavesOut) ? " " + DocumentSession.exportNote : "" | |
| 283 | 288 | } |
| 284 | 289 | |
| 285 | 290 | var fileName: String { (OrgPreferences.icalendarCombinedFile() as NSString).lastPathComponent } |
| 286 | 291 | |
| 287 | 292 | private func read(_ path: String) -> (text: String, settings: OrgSettings)? { |
| 288 | guard let text = open[path] ?? (try? String(contentsOfFile: path, encoding: .utf8)) else { return nil } | |
| 293 | guard let text = texts[path] else { return nil } | |
| 289 | 294 | return (text, OrgPreferences.orgSettings().resolvingSetupFiles(in: text, path: path, read: OrgSettings.readFile)) |
| 290 | 295 | } |
| 291 | 296 | |
| @@ -293,7 +298,7 @@ struct AgendaCalendars: Transferable { | ||
| 293 | 298 | func exportEach() -> String { |
| 294 | 299 | do { |
| 295 | 300 | let written = try ICalendarFiles.exportEach(paths, options: OrgPreferences.icalendarOptions(), read: read) |
| 296 | return String(localized: "Exported \(written.count) agenda files to iCalendar") | |
| 301 | return String(localized: "Exported \(written.count) agenda files to iCalendar") + note | |
| 297 | 302 | } catch { |
| 298 | 303 | return "Can't export: \(error.localizedDescription)" |
| 299 | 304 | } |
Sources/OrgstarMobile/FoldersScreen.swift +1 −1 · view
| @@ -332,7 +332,7 @@ private struct FolderContents: View { | ||
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | var body: some View { |
| 335 | let files = workspace.files.filter { $0.root == root && $0.kind == .org && $0.relativePath.hasPrefix(prefix) } | |
| 335 | let files = workspace.files.filter { $0.root == root && ($0.kind == .org || DocumentSession.isEncryptedOrgFile($0.path)) && $0.relativePath.hasPrefix(prefix) } | |
| 336 | 336 | let pending = below(workspace.downloading.filter { $0.hasPrefix(root + "/") }.map { String($0.dropFirst(root.count + 1)) }) |
| 337 | 337 | let empty = Set(emptySubfolders()) |
| 338 | 338 | let subfolders = Set((below(files.map(\.relativePath)) + pending).compactMap { path in |
Sources/OrgstarMobile/MobileModel.swift +2 · view
| @@ -167,6 +167,8 @@ final class MobileModel { | ||
| 167 | 167 | let settings = OrgPreferences.orgSettings() |
| 168 | 168 | session.defaults = settings |
| 169 | 169 | session.options = OrgPreferences.options() |
| 170 | session.encryptsTaggedEntries = OrgPreferences.cryptBeforeSave() | |
| 171 | session.cryptTag = OrgPreferences.cryptTag() | |
| 170 | 172 | session.options.snippets = SnippetLibrary.shared.snippets |
| 171 | 173 | workspace?.settings = .with(todoKeywords: settings) |
| 172 | 174 | if let agenda { |
Sources/OrgstarMobile/OrgstarMobileApp.swift +8 −1 · view
| @@ -26,6 +26,8 @@ struct OrgstarMobileApp: App { | ||
| 26 | 26 | #endif |
| 27 | 27 | LiveClock.install() |
| 28 | 28 | ProStore.shared.start() |
| 29 | // Read before the app becomes active and clears it. | |
| 30 | _ = UnsavedHeldFiles.atLaunch | |
| 29 | 31 | // Early, so that the watch's actions are taken when iOS wakes the app for them. |
| 30 | 32 | WatchLink.shared.activate(MobileModel.shared) |
| 31 | 33 | } |
| @@ -406,6 +408,7 @@ struct RootView: View { | ||
| 406 | 408 | } |
| 407 | 409 | .task { |
| 408 | 410 | TimerModel.shared.onDone = { message = $0 } |
| 411 | if let lost = UnsavedHeldFiles.atLaunch { message = lost } | |
| 409 | 412 | takeShared() |
| 410 | 413 | // Development: `ORGSTAR_ROOT` adds a folder at launch, as on the Mac. |
| 411 | 414 | if let root = ProcessInfo.processInfo.environment["ORGSTAR_ROOT"] { try? await workspace.addRoot(URL(fileURLWithPath: root)) } |
| @@ -430,10 +433,14 @@ struct RootView: View { | ||
| 430 | 433 | if let path = activity.userInfo?[CSSearchableItemActivityIdentifier] as? String { model.openRequest = .file(path) } |
| 431 | 434 | } |
| 432 | 435 | .onChange(of: scenePhase) { _, phase in |
| 433 | // Unsaved edits are written before the app may be stopped. | |
| 436 | // Unsaved edits are written before the app may be stopped. A file held for its | |
| 437 | // passphrase stays in memory; its name is kept so that, if iOS ends the app | |
| 438 | // meanwhile, the next launch says its edits were lost. | |
| 434 | 439 | if phase == .background { |
| 435 | 440 | for path in session.dirtyPaths { _ = session.save(path) } |
| 441 | UnsavedHeldFiles.record(session.held.keys.filter(session.dirtyPaths.contains).sorted()) | |
| 436 | 442 | } |
| 443 | if phase == .active { UnsavedHeldFiles.record([]) } | |
| 437 | 444 | // Files and settings synced while away; not every sync tool tells file presenters. |
| 438 | 445 | guard phase == .active else { return } |
| 439 | 446 | // iOS has no idle time: time away from the app while a clock ran stands in for it. |
Sources/OrgstarMobile/ReaderScreen.swift +23 · view
| @@ -45,6 +45,8 @@ struct ReaderScreen: View { | ||
| 45 | 45 | /// The command chosen in Commands, run once the list is gone. |
| 46 | 46 | @State private var chosenCommand: String? |
| 47 | 47 | @State private var message: String? |
| 48 | /// The passphrase sheet for an encrypted file. | |
| 49 | @State private var unlocking: CryptRequest? | |
| 48 | 50 | /// A file a link opened, shown in Quick Look. |
| 49 | 51 | @State private var previewed: URL? |
| 50 | 52 | /// The pane the reader shows its file in, closed with the reader. |
| @@ -151,6 +153,27 @@ struct ReaderScreen: View { | ||
| 151 | 153 | if let path = shownPath, let tree = document?.tree { ExportScreen(path: path, tree: tree) { message = $0 } } |
| 152 | 154 | } |
| 153 | 155 | .message($message) |
| 156 | .overlay { | |
| 157 | if DocumentSession.isEncryptedFile(path), !session.isOpen(path), unlocking == nil { | |
| 158 | ContentUnavailableView { | |
| 159 | Label("\((path as NSString).lastPathComponent) is encrypted", systemImage: "lock") | |
| 160 | } actions: { | |
| 161 | Button("Decrypt…") { unlocking = CryptRequest(mode: .openFile, path: path, offset: 0) } | |
| 162 | } | |
| 163 | } | |
| 164 | } | |
| 165 | .onChange(of: session.unlockRequest, initial: true) { _, request in | |
| 166 | if request == path { unlocking = CryptRequest(mode: .openFile, path: path, offset: 0) } | |
| 167 | } | |
| 168 | .sheet(item: $unlocking) { request in | |
| 169 | NavigationStack { | |
| 170 | CryptSheet(request: request, session: session, text: { "" }, apply: { _ in }) { text in | |
| 171 | unlocking = nil | |
| 172 | if let text { message = text } | |
| 173 | } | |
| 174 | .navigationBarTitleDisplayMode(.inline) | |
| 175 | } | |
| 176 | } | |
| 154 | 177 | .environment(\.openURL, OpenURLAction { url in follow(url) }) |
| 155 | 178 | .background { FindHost(find: find, request: findRequest) } |
| 156 | 179 | .onAppear(perform: open) |
Sources/OrgstarMobile/UnsavedHeldFiles.swift added +23 · view
| @@ -0,0 +1,23 @@ | ||
| 1 | import Foundation | |
| 2 | ||
| 3 | /// The files held for their passphrase when the app went to the background. iOS may end the | |
| 4 | /// app there without asking, and their edits, kept only in memory, are lost: the next launch | |
| 5 | /// says so. | |
| 6 | enum UnsavedHeldFiles { | |
| 7 | static let key = "heldFilesInBackground" | |
| 8 | ||
| 9 | static func record(_ paths: [String]) { | |
| 10 | if paths.isEmpty { | |
| 11 | UserDefaults.standard.removeObject(forKey: key) | |
| 12 | } else { | |
| 13 | UserDefaults.standard.set(paths.map { ($0 as NSString).lastPathComponent }, forKey: key) | |
| 14 | } | |
| 15 | } | |
| 16 | ||
| 17 | /// The message for files whose edits were lost when the app last ended; read once, at launch. | |
| 18 | static let atLaunch: String? = { | |
| 19 | guard let names = UserDefaults.standard.stringArray(forKey: key), !names.isEmpty else { return nil } | |
| 20 | UserDefaults.standard.removeObject(forKey: key) | |
| 21 | return String(localized: "Edits to \(names.joined(separator: ", ")) weren't saved: they were waiting for a passphrase when orgstar was closed.") | |
| 22 | }() | |
| 23 | } | |
Tests/OrgAppTests/CryptReviewTests.swift added +382 · view
| @@ -0,0 +1,382 @@ | ||
| 1 | import Foundation | |
| 2 | import OrgCore | |
| 3 | import OrgDocument | |
| 4 | import Testing | |
| 5 | @testable import OrgApp | |
| 6 | ||
| 7 | /// What an encrypted entry or file must not leak, nor lose, past the save path. | |
| 8 | @MainActor | |
| 9 | struct CryptReviewTests { | |
| 10 | static let secret = "Account 12345" | |
| 11 | static let file = "* Plain\nOpen text.\n* Bank :crypt:\n\(secret)\n* Last\n" | |
| 12 | ||
| 13 | let notes: Folder | |
| 14 | let file: URL | |
| 15 | let recoveryFolder: URL | |
| 16 | let session: DocumentSession | |
| 17 | ||
| 18 | init() throws { | |
| 19 | notes = try Folder() | |
| 20 | file = try notes.write("a.org", "* Plain\nOpen text.\n* Last\n") | |
| 21 | recoveryFolder = notes.url.appendingPathComponent(".recovery") | |
| 22 | session = DocumentSession(recovery: FileRecoveryStore(directory: recoveryFolder)) | |
| 23 | session.saveMode = .explicit | |
| 24 | session.encryptsTaggedEntries = true | |
| 25 | session.hasStoredPassphrase = { _ in false } | |
| 26 | } | |
| 27 | ||
| 28 | func replace(with text: String) throws { | |
| 29 | let buffer = StateBuffer(session.document!) | |
| 30 | session.attach(buffer) | |
| 31 | try buffer.update { try $0.apply([TextEdit(range: 0..<($0.text as NSString).length, replacement: text)], baseRevision: $0.revision) } | |
| 32 | session.bufferChanged() | |
| 33 | } | |
| 34 | ||
| 35 | func type(_ text: String, at offset: Int) throws { | |
| 36 | let buffer = StateBuffer(session.document!) | |
| 37 | session.attach(buffer) | |
| 38 | try buffer.update { try $0.apply([TextEdit(range: offset..<offset, replacement: text)], baseRevision: $0.revision) } | |
| 39 | session.bufferChanged() | |
| 40 | } | |
| 41 | ||
| 42 | func read(_ url: URL) -> String { (try? String(contentsOf: url, encoding: .utf8)) ?? "" } | |
| 43 | var disk: String { read(file) } | |
| 44 | ||
| 45 | var recoveryFiles: [String] { | |
| 46 | let files = FileManager.default.enumerator(at: recoveryFolder, includingPropertiesForKeys: nil)?.compactMap { $0 as? URL } ?? [] | |
| 47 | return files.compactMap { try? Data(contentsOf: $0) }.map { String(decoding: $0, as: UTF8.self) } | |
| 48 | } | |
| 49 | ||
| 50 | func offset(of needle: String) -> Int { (session.document!.text as NSString).range(of: needle).location } | |
| 51 | ||
| 52 | // 1 | |
| 53 | @Test func turningTheSettingOffKeepsSealingOpenFiles() throws { | |
| 54 | session.open(file.path) | |
| 55 | session.cryptUsed("pw", for: file.path) | |
| 56 | try replace(with: Self.file) | |
| 57 | #expect(session.save()) | |
| 58 | #expect(!disk.contains(Self.secret)) | |
| 59 | session.encryptsTaggedEntries = false | |
| 60 | try type("x", at: 0) | |
| 61 | #expect(session.save()) | |
| 62 | #expect(!disk.contains(Self.secret)) | |
| 63 | #expect(session.openTexts[file.path] == nil) | |
| 64 | // A file opened after it was turned off is as before. | |
| 65 | let other = try notes.write("b.org", Self.file) | |
| 66 | session.open(other.path) | |
| 67 | try type("y", at: 0) | |
| 68 | #expect(session.save()) | |
| 69 | #expect(read(other).contains(Self.secret)) | |
| 70 | } | |
| 71 | ||
| 72 | // 2 | |
| 73 | @Test func useDiskVersionOnAHeldFileKeepsTheEdits() throws { | |
| 74 | session.open(file.path) | |
| 75 | try replace(with: Self.file) | |
| 76 | #expect(!session.save()) | |
| 77 | session.useDiskVersion() | |
| 78 | #expect(session.document?.text == Self.file) | |
| 79 | #expect(session.lastError?.contains("Encrypt…") == true) | |
| 80 | #expect(session.restore(text: "* Plain\n")?.contains("Encrypt…") == true) | |
| 81 | #expect(session.document?.text == Self.file) | |
| 82 | #expect(recoveryFiles.isEmpty && disk == "* Plain\nOpen text.\n* Last\n") | |
| 83 | } | |
| 84 | ||
| 85 | // 3a | |
| 86 | @Test func archivingAChildOfATaggedEntryEncryptsItFirst() throws { | |
| 87 | let text = "* Parent :crypt:\nparent text\n** SECRETTITLE child\nchild secret\n* Other :crypt:\nother secret\n* Last\n" | |
| 88 | try notes.write("a.org", text) | |
| 89 | session.open(file.path) | |
| 90 | let child = (text as NSString).range(of: "** SECRETTITLE").location | |
| 91 | let archive = notes.url.appendingPathComponent("a.org_archive") | |
| 92 | // A heading inside an encrypted entry isn't moved on its own, passphrase or not. | |
| 93 | #expect(session.archive(from: (file.path, child))?.contains("inside an encrypted entry") == true) | |
| 94 | session.cryptUsed("pw", for: file.path) | |
| 95 | #expect(session.archive(from: (file.path, child))?.contains("inside an encrypted entry") == true) | |
| 96 | let target = RefileTarget(label: "b.org", path: try notes.write("b.org", "* B\n").path, start: nil, title: "", level: 0, contentHash: "") | |
| 97 | #expect(session.refile(to: target, from: (file.path, child))?.contains("inside an encrypted entry") == true) | |
| 98 | #expect(!FileManager.default.fileExists(atPath: archive.path) && !read(notes.url.appendingPathComponent("b.org")).contains("SECRETTITLE")) | |
| 99 | // A tagged entry is encrypted where it is, then archived. | |
| 100 | let other = (session.document!.text as NSString).range(of: "* Other").location | |
| 101 | #expect(session.archive(from: (file.path, other)) == "Archived to a.org_archive") | |
| 102 | #expect(!read(archive).contains("other secret") && read(archive).contains("-----BEGIN PGP MESSAGE-----")) | |
| 103 | #expect(session.save()) | |
| 104 | #expect(!disk.contains("child secret") && !disk.contains("SECRETTITLE")) | |
| 105 | } | |
| 106 | ||
| 107 | // Third review, A and B | |
| 108 | @Test func shareSubtreeOfAHeadingInsideAnEncryptedEntry() throws { | |
| 109 | let text = "* Parent :crypt:\nparent text\n** SECRETTITLE child\nchild secret\n* Last\n" | |
| 110 | try notes.write("a.org", text) | |
| 111 | session.open(file.path) | |
| 112 | session.cryptUsed("pw", for: file.path) | |
| 113 | let child = (text as NSString).range(of: "** SECRETTITLE").location | |
| 114 | let share = try #require(session.subtreeShare(file.path, at: child)) | |
| 115 | #expect(share.fileName == "Encrypted entry.org") | |
| 116 | #expect(!share.text.contains("SECRETTITLE") && !share.text.contains("child secret") && share.text.hasPrefix("* Encrypted entry :crypt:\n")) | |
| 117 | let opened = try OrgCrypt.decryptInPlace(share.text, at: 0, passphrase: "pw") | |
| 118 | #expect(opened.contains("** SECRETTITLE child\nchild secret\n")) | |
| 119 | // Capture under that heading, into the file closed, isn't written. | |
| 120 | session.kill(file.path) | |
| 121 | let template = CaptureTemplate(key: "s", name: "Secret", target: .headline(file: file.path, headline: "SECRETTITLE child"), template: "* %?") | |
| 122 | if case .success = session.capture("** Captured\n", template: template, root: nil) { Issue.record("captured into plaintext") } | |
| 123 | #expect(disk == text) | |
| 124 | } | |
| 125 | ||
| 126 | @Test func shareSubtreeRefusesWhatCantBeEncrypted() throws { | |
| 127 | let text = "* A :crypt:\na secret\n* B :crypt:\nb secret\n* End\n" | |
| 128 | var both = try #require(try OrgCrypt.encrypt(text, at: 0, passphrase: "one")) | |
| 129 | both = try #require(try OrgCrypt.encrypt(both, at: (both as NSString).range(of: "* B").location, passphrase: "two")) | |
| 130 | try notes.write("a.org", both) | |
| 131 | session.open(file.path) | |
| 132 | session.cryptUsed("one", for: file.path) | |
| 133 | try type("typed below b\n", at: offset(of: "* End")) | |
| 134 | let b = offset(of: "* B") | |
| 135 | #expect(session.refusesSubtreeShare(file.path, at: b)?.contains("public key") == true) | |
| 136 | #expect(session.subtreeShare(file.path, at: b) == nil) | |
| 137 | } | |
| 138 | ||
| 139 | // Third review, C | |
| 140 | @Test func hiddenClockTasksNeedTheirTitle() throws { | |
| 141 | let hidden = ClockTask(path: "/x", title: "Real", ordinal: 1, id: nil).hiding("Encrypted entry") | |
| 142 | #expect(hidden.title == "Encrypted entry" && hidden.titleHash != nil) | |
| 143 | #expect(hidden.locate(in: "* A\n* Real\n") == 4) | |
| 144 | #expect(hidden.locate(in: "* New\n* A\n* Real\n") == 10) | |
| 145 | #expect(hidden.locate(in: "* A\n* Renamed\n") == nil) | |
| 146 | #expect(hidden.refreshed(in: "* New\n* A\n* Real\n")?.title == "Encrypted entry") | |
| 147 | } | |
| 148 | ||
| 149 | // Third review, D2 | |
| 150 | @Test func keepMineHoldsWhenTheDiskVersionCantBeKept() throws { | |
| 151 | session.open(file.path) | |
| 152 | try type("x", at: 0) | |
| 153 | try notes.write("a.org", "* Plain\n* Theirs :crypt:\ntheir secret\n") | |
| 154 | session.keepMine() | |
| 155 | #expect(session.held[file.path] == .entries(1) && session.lastError == nil) | |
| 156 | #expect(disk.contains("their secret") && recoveryFiles.isEmpty) | |
| 157 | } | |
| 158 | ||
| 159 | // Third review, 3 | |
| 160 | @Test func aCancelledOpenEndsItsAuthentication() throws { | |
| 161 | let path = notes.url.appendingPathComponent("d.org.gpg") | |
| 162 | try OpenPGP.encryptedMessage(Data("* D\n".utf8), passphrase: "pw").write(to: path) | |
| 163 | session.open(path.path) | |
| 164 | let context = CryptPassphrases.context(for: path.path) | |
| 165 | session.cancelUnlock() | |
| 166 | #expect(CryptPassphrases.context(for: path.path) !== context) | |
| 167 | CryptPassphrases.endSession(for: path.path) | |
| 168 | #expect(!CryptPassphrases.protectsItems) | |
| 169 | } | |
| 170 | ||
| 171 | // 3b | |
| 172 | @Test func encryptedFilesArchiveToEncryptedFilesAndRefileOnlyThere() throws { | |
| 173 | let path = notes.url.appendingPathComponent("diary.org.gpg") | |
| 174 | try OpenPGP.encryptedMessage(Data("* Monday\nDear diary.\n* Tuesday\nMore.\n".utf8), passphrase: "pw").write(to: path) | |
| 175 | session.open(path.path) | |
| 176 | #expect(session.unlock("pw", for: path.path) == nil) | |
| 177 | let target = RefileTarget(label: "a.org", path: file.path, start: nil, title: "", level: 0, contentHash: "") | |
| 178 | #expect(session.refile(to: target, from: (path.path, 0))?.contains("isn't") == true) | |
| 179 | #expect(!disk.contains("Dear diary")) | |
| 180 | #expect(session.archive(from: (path.path, 0)) == "Archived to diary_archive.org.gpg") | |
| 181 | let archive = notes.url.appendingPathComponent("diary_archive.org.gpg") | |
| 182 | #expect(!FileManager.default.fileExists(atPath: notes.url.appendingPathComponent("diary.org.gpg_archive").path)) | |
| 183 | let bytes = try Data(contentsOf: archive) | |
| 184 | #expect(bytes.range(of: Data("Dear diary".utf8)) == nil) | |
| 185 | #expect(String(decoding: try OpenPGP.decryptFile(bytes, passphrase: "pw"), as: UTF8.self).contains("Dear diary.")) | |
| 186 | // Capture into an encrypted file that isn't open writes nothing. | |
| 187 | session.kill(path.path) | |
| 188 | let template = CaptureTemplate(key: "d", name: "Diary", target: .file(path.path), template: "* %?") | |
| 189 | if case .success = session.capture("* Captured secret\n", template: template, root: nil) { Issue.record("captured into a locked file") } | |
| 190 | #expect(try Data(contentsOf: path).range(of: Data("Captured".utf8)) == nil) | |
| 191 | } | |
| 192 | ||
| 193 | // 5 | |
| 194 | @Test func textBelowAMessageIsHeldThenSealedWithIt() throws { | |
| 195 | let encrypted = try #require(try OrgCrypt.encrypt(Self.file, at: (Self.file as NSString).range(of: "* Bank").location, passphrase: "pw")) | |
| 196 | try notes.write("a.org", encrypted) | |
| 197 | session.open(file.path) | |
| 198 | try type("typed below\n", at: offset(of: "* Last")) | |
| 199 | #expect(!session.save()) | |
| 200 | #expect(session.held[file.path] == .entries(1)) | |
| 201 | #expect(!disk.contains("typed below")) | |
| 202 | #expect(session.unlock("pw", for: file.path) == nil) | |
| 203 | #expect(!disk.contains("typed below")) | |
| 204 | let bank = (disk as NSString).range(of: "* Bank").location | |
| 205 | #expect(try OrgCrypt.decrypt(disk, at: bank, passphrase: "pw").plaintext == Self.secret + "\ntyped below\n") | |
| 206 | } | |
| 207 | ||
| 208 | // 7 | |
| 209 | @Test func exportsLeaveOutWhatIsEncryptedOnDisk() throws { | |
| 210 | session.open(file.path) | |
| 211 | session.cryptUsed("pw", for: file.path) | |
| 212 | try replace(with: Self.file) | |
| 213 | #expect(session.save()) | |
| 214 | #expect(session.exportLeavesOut(file.path)) | |
| 215 | #expect(session.exportText(of: file.path) == disk) | |
| 216 | #expect(session.exportText(of: file.path)?.contains(Self.secret) == false) | |
| 217 | let gpg = notes.url.appendingPathComponent("d.org.gpg") | |
| 218 | try OpenPGP.encryptedMessage(Data("* D\nsecret\n".utf8), passphrase: "pw").write(to: gpg) | |
| 219 | session.open(gpg.path) | |
| 220 | #expect(session.unlock("pw", for: gpg.path) == nil) | |
| 221 | #expect(session.exportText(of: gpg.path) == nil && session.exportLeavesOut(gpg.path)) | |
| 222 | // Nor is either copied for Emacs. | |
| 223 | #expect(session.refusesEmacsCopy(gpg.path) != nil && session.refusesEmacsCopy(file.path) != nil) | |
| 224 | let plain = try notes.write("c.org", "* C\n") | |
| 225 | session.open(plain.path) | |
| 226 | #expect(session.exportText(of: plain.path) == "* C\n" && session.refusesEmacsCopy(plain.path) == nil) | |
| 227 | } | |
| 228 | ||
| 229 | // 8 | |
| 230 | @Test func clockingInDoesntKeepEncryptedTitles() throws { | |
| 231 | let text = "* Bank :crypt:\nintro\n** Secret task\nbody\n* Open task\n" | |
| 232 | try notes.write("a.org", text) | |
| 233 | session.open(file.path) | |
| 234 | session.cryptUsed("pw", for: file.path) | |
| 235 | let clock = ClockModel(file: notes.url.appendingPathComponent("clock.json")) | |
| 236 | _ = clock.clockIn(session, path: file.path, at: (text as NSString).range(of: "** Secret").location) | |
| 237 | #expect(clock.running?.heading == "Encrypted entry") | |
| 238 | #expect(clock.history.allSatisfy { $0.title != "Secret task" }) | |
| 239 | #expect(!read(notes.url.appendingPathComponent("clock.json")).contains("Secret task")) | |
| 240 | #expect(session.shareableTitle("Bank", path: file.path, heading: 0) == "Bank") | |
| 241 | #expect(session.shareableTitle("Monday", path: "/x/d.org.gpg", heading: 0) == "Encrypted entry") | |
| 242 | _ = clock.clockOut(session) | |
| 243 | #expect(session.save()) | |
| 244 | #expect(!disk.contains("Secret task") && !disk.contains("intro")) | |
| 245 | } | |
| 246 | ||
| 247 | // Second review, 2 | |
| 248 | @Test func clockHistoryKeepsNoEncryptedTitle() throws { | |
| 249 | let text = "* Bank :crypt:\nintro\n** Secret task\n:PROPERTIES:\n:ID: s-1\n:END:\nbody\n** Hidden no id\nmore\n* Open task\n" | |
| 250 | try notes.write("a.org", text) | |
| 251 | session.open(file.path) | |
| 252 | session.cryptUsed("pw", for: file.path) | |
| 253 | let clockFile = notes.url.appendingPathComponent("clock.json") | |
| 254 | let clock = ClockModel(file: clockFile) | |
| 255 | _ = clock.clockIn(session, path: file.path, at: (text as NSString).range(of: "** Secret").location) | |
| 256 | _ = clock.clockIn(session, path: file.path, at: (session.document!.text as NSString).range(of: "** Hidden").location) | |
| 257 | _ = clock.clockIn(session, path: file.path, at: (session.document!.text as NSString).range(of: "* Open").location) | |
| 258 | #expect(!read(clockFile).contains("Secret task") && !read(clockFile).contains("Hidden no id")) | |
| 259 | #expect(clock.history.map(\.title) == ["Open task", "Encrypted entry", "Encrypted entry"]) | |
| 260 | } | |
| 261 | ||
| 262 | // Second review, 3 | |
| 263 | @Test func eachFileHasItsOwnAuthentication() throws { | |
| 264 | let a = CryptPassphrases.context(for: "/x/a.org"), b = CryptPassphrases.context(for: "/x/b.org") | |
| 265 | #expect(a !== b && CryptPassphrases.context(for: "/x/a.org") === a) | |
| 266 | #expect(a.touchIDAuthenticationAllowableReuseDuration == 0) | |
| 267 | CryptPassphrases.endSession(for: "/x/a.org") | |
| 268 | #expect(CryptPassphrases.context(for: "/x/a.org") !== a) | |
| 269 | } | |
| 270 | ||
| 271 | // Second review, 4a | |
| 272 | @Test func anEntryThePassphraseCantEncryptHoldsTheFile() throws { | |
| 273 | let text = "* A :crypt:\na secret\n* B :crypt:\nb secret\n* End\n" | |
| 274 | var both = try #require(try OrgCrypt.encrypt(text, at: 0, passphrase: "one")) | |
| 275 | both = try #require(try OrgCrypt.encrypt(both, at: (both as NSString).range(of: "* B").location, passphrase: "two")) | |
| 276 | try notes.write("a.org", both) | |
| 277 | session.open(file.path) | |
| 278 | #expect(session.unlock("one", for: file.path) == nil) | |
| 279 | try type("typed below b\n", at: offset(of: "* End")) | |
| 280 | #expect(!session.save()) | |
| 281 | guard case .blocked(let reason)? = session.held[file.path] else { Issue.record("\(String(describing: session.held[file.path]))"); return } | |
| 282 | #expect(reason.contains("public key") && session.lastError == nil) | |
| 283 | #expect(OrgCrypt.Failure("x").localizedDescription == "x") | |
| 284 | #expect(!disk.contains("typed below b")) | |
| 285 | } | |
| 286 | ||
| 287 | // Second review, 4b | |
| 288 | @Test func plaintextEntriesOnDiskHoldTheFileUntilThePassphrase() throws { | |
| 289 | session.open(file.path) | |
| 290 | try type("x", at: 0) | |
| 291 | // Written elsewhere, with no file event. | |
| 292 | try notes.write("a.org", "* Plain\nOpen text.\n* Last\n* Theirs :crypt:\ntheir secret\n") | |
| 293 | #expect(!session.save()) | |
| 294 | #expect(session.held[file.path] == .entries(1) && session.lastError == nil) | |
| 295 | #expect(session.unlock("pw", for: file.path) == nil) | |
| 296 | #expect(!session.isDirty && !disk.contains("their secret") && session.document?.text.contains("their secret") == true) | |
| 297 | #expect(recoveryFiles.allSatisfy { !$0.contains("their secret") }) | |
| 298 | } | |
| 299 | ||
| 300 | // Second review, 6 | |
| 301 | @Test func anEncryptedFileSavesWithOneKey() throws { | |
| 302 | let path = notes.url.appendingPathComponent("d.org.gpg") | |
| 303 | try OpenPGP.encryptedMessage(Data("* D\nbody\n".utf8), passphrase: "pw").write(to: path) | |
| 304 | session.open(path.path) | |
| 305 | #expect(session.unlock("pw", for: path.path) == nil) | |
| 306 | try type("x", at: 0) | |
| 307 | #expect(session.save()) | |
| 308 | let clock = ContinuousClock() | |
| 309 | var took: [Duration] = [] | |
| 310 | for n in 0..<3 { | |
| 311 | try type("\(n)", at: 0) | |
| 312 | took.append(clock.measure { _ = session.save() }) | |
| 313 | } | |
| 314 | print("Autosave of an .org.gpg file: \(took)") | |
| 315 | #expect(try OpenPGP.decryptFile(Data(contentsOf: path), passphrase: "pw") == Data("210x* D\nbody\n".utf8)) | |
| 316 | } | |
| 317 | ||
| 318 | // MR 490 hooks | |
| 319 | @Test func handoffAndShareSubtreeKeepWhatIsEncrypted() throws { | |
| 320 | let text = "* Bank :crypt:\nintro\n** Secret child\nbody\n* Open\n" | |
| 321 | try notes.write("a.org", text) | |
| 322 | session.open(file.path) | |
| 323 | let child = (text as NSString).range(of: "** Secret").location | |
| 324 | // Without the passphrase, the subtree isn't shared. | |
| 325 | #expect(session.handoffPlace(file.path, roots: [notes.url.path]) == nil) | |
| 326 | #expect(session.refusesSubtreeShare(file.path, at: child)?.contains("Encrypt…") == true) | |
| 327 | #expect(session.subtreeShare(file.path, at: child) == nil) | |
| 328 | session.cryptUsed("pw", for: file.path) | |
| 329 | let share = try #require(session.subtreeShare(file.path, at: child)) | |
| 330 | #expect(!share.text.contains("body") && share.text.contains("-----BEGIN PGP MESSAGE-----")) | |
| 331 | #expect(session.document?.text == text) | |
| 332 | let bank = try #require(session.subtreeShare(file.path, at: 0)) | |
| 333 | #expect(!bank.text.contains("intro") && !bank.text.contains("Secret child")) | |
| 334 | // An open file without tagged entries is advertised as before. | |
| 335 | let plain = try notes.write("b.org", "* Plain\n") | |
| 336 | session.open(plain.path) | |
| 337 | #expect(session.handoffPlace(plain.path, roots: [notes.url.path]) != nil) | |
| 338 | // An encrypted file's entries aren't shared. | |
| 339 | let gpg = notes.url.appendingPathComponent("d.org.gpg") | |
| 340 | try OpenPGP.encryptedMessage(Data("* D\nsecret\n".utf8), passphrase: "pw").write(to: gpg) | |
| 341 | session.open(gpg.path) | |
| 342 | #expect(session.unlock("pw", for: gpg.path) == nil) | |
| 343 | #expect(session.refusesSubtreeShare(gpg.path, at: 0) != nil && session.subtreeShare(gpg.path, at: 0) == nil) | |
| 344 | } | |
| 345 | ||
| 346 | // 9 | |
| 347 | @Test func unchangedEntriesKeepTheirMessageAcrossSaves() throws { | |
| 348 | session.open(file.path) | |
| 349 | session.cryptUsed("pw", for: file.path) | |
| 350 | try replace(with: Self.file) | |
| 351 | #expect(session.save()) | |
| 352 | let message = try #require(OrgCrypt.firstMessage(disk)) | |
| 353 | for n in 0..<5 { | |
| 354 | try type("\(n)", at: 0) | |
| 355 | #expect(session.save()) | |
| 356 | #expect(disk.contains(message)) | |
| 357 | } | |
| 358 | #expect(session.crypt.revealedMessages(for: file.path).count == 1) | |
| 359 | } | |
| 360 | ||
| 361 | // 10 | |
| 362 | @Test func entriesEncryptedToAPublicKeyDontBlockThePassphrase() throws { | |
| 363 | // A public-key session packet (tag 1) where a message's packets start. | |
| 364 | let publicKey = OpenPGP.armor(Data([0xC1, 0x02, 0x03, 0x00])) | |
| 365 | try notes.write("a.org", "* Pub :crypt:\n" + publicKey + "* Plain\n") | |
| 366 | session.open(file.path) | |
| 367 | try type("* New :crypt:\nnew secret\n", at: (session.document!.text as NSString).length) | |
| 368 | #expect(!session.save()) | |
| 369 | #expect(session.unlock("pw", for: file.path) == nil) | |
| 370 | #expect(!disk.contains("new secret")) | |
| 371 | #expect(disk.contains(publicKey)) | |
| 372 | } | |
| 373 | ||
| 374 | // 6 | |
| 375 | @Test func keychainItemsAreThisDeviceOnlyAfterUserPresence() throws { | |
| 376 | let item = try #require(CryptPassphrases.newItem("pw", for: "/x/a.org")) | |
| 377 | #expect(item[kSecAttrAccessControl as String] != nil) | |
| 378 | #expect(item[kSecUseDataProtectionKeychain as String] as? Bool == true) | |
| 379 | #expect(item[kSecAttrService as String] as? String == "sh.krz.orgstar.crypt.v2") | |
| 380 | #expect(item[kSecAttrAccessible as String] == nil) | |
| 381 | } | |
| 382 | } | |
Tests/OrgAppTests/CryptSaveTests.swift added +346 · view
| @@ -0,0 +1,346 @@ | ||
| 1 | import Foundation | |
| 2 | import OrgCore | |
| 3 | import OrgDocument | |
| 4 | import Testing | |
| 5 | @testable import OrgApp | |
| 6 | ||
| 7 | /// Saving with `org-crypt-use-before-save-magic`, and `.org.gpg` files: what reaches disk. | |
| 8 | @MainActor | |
| 9 | struct CryptSaveTests { | |
| 10 | static let secret = "Account 12345" | |
| 11 | static let file = "#+TITLE: Notes\n* Plain\nOpen text.\n* Bank :crypt:\n\(secret)\n* Last\n" | |
| 12 | ||
| 13 | let notes: Folder | |
| 14 | let file: URL | |
| 15 | let recoveryFolder: URL | |
| 16 | let session: DocumentSession | |
| 17 | ||
| 18 | init() throws { | |
| 19 | notes = try Folder() | |
| 20 | file = try notes.write("a.org", Self.file) | |
| 21 | recoveryFolder = notes.url.appendingPathComponent(".recovery") | |
| 22 | session = DocumentSession(recovery: FileRecoveryStore(directory: recoveryFolder)) | |
| 23 | session.saveMode = .explicit | |
| 24 | session.encryptsTaggedEntries = true | |
| 25 | session.hasStoredPassphrase = { _ in false } | |
| 26 | } | |
| 27 | ||
| 28 | /// Types `text` at `offset` in the open file, as the editor would. | |
| 29 | func type(_ text: String, at offset: Int) throws { | |
| 30 | let buffer = StateBuffer(session.document!) | |
| 31 | session.attach(buffer) | |
| 32 | try buffer.update { try $0.apply([TextEdit(range: offset..<offset, replacement: text)], baseRevision: $0.revision) } | |
| 33 | session.bufferChanged() | |
| 34 | } | |
| 35 | ||
| 36 | /// Puts `text` in place of the open file's text. | |
| 37 | func replace(with text: String) throws { | |
| 38 | let buffer = StateBuffer(session.document!) | |
| 39 | session.attach(buffer) | |
| 40 | try buffer.update { try $0.apply([TextEdit(range: 0..<($0.text as NSString).length, replacement: text)], baseRevision: $0.revision) } | |
| 41 | session.bufferChanged() | |
| 42 | } | |
| 43 | ||
| 44 | var disk: String { (try? String(contentsOf: file, encoding: .utf8)) ?? "" } | |
| 45 | ||
| 46 | /// Every file the recovery folder holds, as text. | |
| 47 | var recoveryFiles: [String] { | |
| 48 | let files = FileManager.default.enumerator(at: recoveryFolder, includingPropertiesForKeys: nil)?.compactMap { $0 as? URL } ?? [] | |
| 49 | return files.compactMap { try? Data(contentsOf: $0) }.map { String(decoding: $0, as: UTF8.self) } | |
| 50 | } | |
| 51 | ||
| 52 | func offset(of needle: String) -> Int { | |
| 53 | (session.document!.text as NSString).range(of: needle).location | |
| 54 | } | |
| 55 | ||
| 56 | /// Waits for `condition`, as the Keychain's answer comes back on a task. | |
| 57 | func wait(_ condition: () -> Bool) async throws { | |
| 58 | for _ in 0..<200 where !condition() { try await Task.sleep(for: .milliseconds(10)) } | |
| 59 | } | |
| 60 | ||
| 61 | @Test func savesTaggedEntriesEncryptedWithTheRememberedPassphrase() async throws { | |
| 62 | try notes.write("a.org", "* Bank :crypt:\nold\n* Last\n") | |
| 63 | session.hasStoredPassphrase = { _ in true } | |
| 64 | var asked = 0 | |
| 65 | session.storedPassphrase = { _ in asked += 1; return "pw" } | |
| 66 | var written: [String] = [] | |
| 67 | session.fileWritten = { written.append($0) } | |
| 68 | session.open(file.path) | |
| 69 | try replace(with: Self.file) | |
| 70 | #expect(!session.save()) | |
| 71 | try await wait { !session.isDirty } | |
| 72 | #expect(session.held.isEmpty) | |
| 73 | #expect(asked == 1) | |
| 74 | #expect(written == [file.path]) | |
| 75 | // The buffer keeps the text; the file has a message in its place. | |
| 76 | #expect(session.document?.text == Self.file) | |
| 77 | #expect(!disk.contains(Self.secret) && !disk.contains("old")) | |
| 78 | #expect(disk.contains("* Bank :crypt:\n-----BEGIN PGP MESSAGE-----\n")) | |
| 79 | let bank = (disk as NSString).range(of: "* Bank").location | |
| 80 | #expect(try OrgCrypt.decrypt(disk, at: bank, passphrase: "pw").plaintext == Self.secret + "\n") | |
| 81 | // The version the save replaced went to recovery encrypted too. | |
| 82 | #expect(!recoveryFiles.isEmpty) | |
| 83 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) && !$0.contains("old") }) | |
| 84 | // Later saves don't ask again. | |
| 85 | try type("More. ", at: offset(of: "Open text.")) | |
| 86 | #expect(session.save()) | |
| 87 | #expect(asked == 1) | |
| 88 | #expect(written.count == 2) | |
| 89 | #expect(!disk.contains(Self.secret)) | |
| 90 | // The index reads the file from disk and keeps no text of the entry. | |
| 91 | let workspace = try WorkspaceModel(directory: notes.url.appendingPathComponent(".index")) | |
| 92 | try await workspace.addRoot(notes.url) | |
| 93 | let database = try Data(contentsOf: notes.url.appendingPathComponent(".index/index.sqlite")) | |
| 94 | #expect(database.range(of: Data(Self.secret.utf8)) == nil) | |
| 95 | #expect(try workspace.search("12345").isEmpty) | |
| 96 | #expect(try workspace.search("Open").map(\.title).contains("Plain")) | |
| 97 | } | |
| 98 | ||
| 99 | @Test func holdsTheWholeFileWithoutThePassphrase() throws { | |
| 100 | try notes.write("a.org", "* Plain\nOpen text.\n") | |
| 101 | var written: [String] = [] | |
| 102 | session.fileWritten = { written.append($0) } | |
| 103 | session.open(file.path) | |
| 104 | try replace(with: Self.file) | |
| 105 | #expect(!session.save()) | |
| 106 | #expect(session.held[file.path] == .entries(1)) | |
| 107 | #expect(written.isEmpty) | |
| 108 | #expect(disk == "* Plain\nOpen text.\n") | |
| 109 | #expect(recoveryFiles.isEmpty) | |
| 110 | #expect(session.isDirty) | |
| 111 | // Nothing reads the held text from the session for the agenda or widgets. | |
| 112 | #expect(session.openTexts[file.path] == nil) | |
| 113 | // Keep Mine holds too. | |
| 114 | session.keepMine() | |
| 115 | #expect(disk == "* Plain\nOpen text.\n") | |
| 116 | #expect(recoveryFiles.isEmpty) | |
| 117 | // The passphrase, when given, encrypts and saves. | |
| 118 | #expect(written.isEmpty) | |
| 119 | #expect(session.unlock("pw", for: file.path) == nil) | |
| 120 | #expect(session.held.isEmpty) | |
| 121 | #expect(!session.isDirty) | |
| 122 | #expect(written == [file.path]) | |
| 123 | #expect(!disk.contains(Self.secret)) | |
| 124 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) | |
| 125 | #expect(session.openTexts[file.path] == nil) | |
| 126 | } | |
| 127 | ||
| 128 | @Test func restoringAVersionOfAHeldFileKeepsNoPlaintext() throws { | |
| 129 | try notes.write("a.org", "* Plain\nOpen text.\n") | |
| 130 | session.open(file.path) | |
| 131 | try replace(with: Self.file) | |
| 132 | #expect(!session.save()) | |
| 133 | // No copy of the buffer can be kept, so the version isn't restored. | |
| 134 | #expect(session.restore(text: "* Plain\nOpen text.\n* Other\n")?.contains("Encrypt…") == true) | |
| 135 | #expect(session.document?.text == Self.file) | |
| 136 | #expect(recoveryFiles.isEmpty) | |
| 137 | #expect(session.unlock("pw", for: file.path) == nil) | |
| 138 | #expect(session.restore(text: "* Plain\nOpen text.\n* Other\n") == nil) | |
| 139 | #expect(session.save()) | |
| 140 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) | |
| 141 | } | |
| 142 | ||
| 143 | @Test func replaceInFilesKeepsNoPlaintextAndIsHeld() throws { | |
| 144 | try notes.write("a.org", "* Plain\nOpen text.\n") | |
| 145 | session.open(file.path) | |
| 146 | try replace(with: Self.file) | |
| 147 | // The buffer has no editor: Replace in Files keeps a copy first, and can't keep one now. | |
| 148 | let changed = (Self.file as NSString).replacingOccurrences(of: "Open text.", with: "Shut text.") | |
| 149 | #expect(session.applyChanges(lineEdits(from: Self.file, to: changed), to: file.path, expecting: Self.file) == nil) | |
| 150 | #expect(!session.save()) | |
| 151 | #expect(session.held[file.path] == .entries(1)) | |
| 152 | #expect(recoveryFiles.isEmpty) | |
| 153 | #expect(disk == "* Plain\nOpen text.\n") | |
| 154 | // With the passphrase, the copy is kept encrypted. | |
| 155 | session.cryptUsed("pw", for: file.path) | |
| 156 | #expect(session.applyChanges(lineEdits(from: changed, to: Self.file), to: file.path, expecting: changed) == nil) | |
| 157 | #expect(session.save()) | |
| 158 | #expect(!recoveryFiles.isEmpty && recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) | |
| 159 | #expect(!disk.contains(Self.secret)) | |
| 160 | // A file that isn't open, with an unencrypted tagged entry on disk, isn't written. | |
| 161 | session.cryptUsed("other", for: "/nowhere") | |
| 162 | let closed = try notes.write("b.org", Self.file) | |
| 163 | let message = session.applyChanges(lineEdits(from: Self.file, to: changed), to: closed.path, expecting: Self.file) | |
| 164 | #expect(message?.contains("1 tagged entry isn't encrypted") == true) | |
| 165 | #expect((try String(contentsOf: closed, encoding: .utf8)) == Self.file) | |
| 166 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) | |
| 167 | } | |
| 168 | ||
| 169 | @Test func aHeldFileIsReleasedWhenTheEntryGoes() throws { | |
| 170 | session.saveMode = .automatic | |
| 171 | session.autosaveDelay = .seconds(60) | |
| 172 | session.open(file.path) | |
| 173 | try type("x", at: 0) | |
| 174 | #expect(!session.save()) | |
| 175 | #expect(session.held[file.path] == .entries(1)) | |
| 176 | let text = session.document!.text as NSString | |
| 177 | try replace(with: text.replacingOccurrences(of: " :crypt:", with: "")) | |
| 178 | #expect(session.held.isEmpty) | |
| 179 | } | |
| 180 | ||
| 181 | @Test func aWrongPassphraseForTheFilesEntriesIsRefused() throws { | |
| 182 | let encrypted = try #require(try OrgCrypt.encrypt(Self.file, at: (Self.file as NSString).range(of: "* Bank").location, passphrase: "pw")) | |
| 183 | try notes.write("a.org", encrypted + "* New :crypt:\nNew secret\n") | |
| 184 | session.open(file.path) | |
| 185 | try type("x", at: 0) | |
| 186 | #expect(!session.save()) | |
| 187 | #expect(session.held[file.path] == .entries(1)) | |
| 188 | #expect(session.unlock("other", for: file.path) == "Wrong passphrase") | |
| 189 | #expect(session.isDirty && disk.hasPrefix(encrypted)) | |
| 190 | #expect(session.unlock("pw", for: file.path) == nil) | |
| 191 | #expect(!disk.contains("New secret") && !session.isDirty) | |
| 192 | } | |
| 193 | ||
| 194 | @Test func blankTaggedEntriesDontHoldTheFile() throws { | |
| 195 | try notes.write("a.org", "* Plain\n") | |
| 196 | session.open(file.path) | |
| 197 | try type("* Empty :crypt:\n", at: 8) | |
| 198 | #expect(session.save()) | |
| 199 | #expect(disk == "* Plain\n* Empty :crypt:\n") | |
| 200 | } | |
| 201 | ||
| 202 | @Test func unchangedEncryptedEntriesStayByteForByte() throws { | |
| 203 | let bank = (Self.file as NSString).range(of: "* Bank").location | |
| 204 | let encrypted = try #require(try OrgCrypt.encrypt(Self.file, at: bank, passphrase: "pw")) | |
| 205 | try notes.write("a.org", encrypted) | |
| 206 | session.open(file.path) | |
| 207 | // Decrypt Entry in File, as the passphrase sheet runs it. | |
| 208 | let message = try #require(OrgCrypt.firstMessage(encrypted)) | |
| 209 | let decrypted = try OrgCrypt.decryptInPlace(encrypted, at: bank, passphrase: "pw") | |
| 210 | session.cryptUsed("pw", for: file.path) | |
| 211 | let body = try #require(OrgCrypt.bodyRange(decrypted, at: bank)) | |
| 212 | session.cryptDecrypted(message: message, plaintext: (decrypted as NSString).substring(with: NSRange(body)), for: file.path) | |
| 213 | try replace(with: decrypted) | |
| 214 | #expect(session.document?.text.contains(Self.secret) == true) | |
| 215 | // Saving writes the entry's message as it was. | |
| 216 | #expect(session.save()) | |
| 217 | #expect(disk == encrypted) | |
| 218 | try type("More. ", at: offset(of: "Open text.")) | |
| 219 | #expect(session.save()) | |
| 220 | #expect(disk == (encrypted as NSString).replacingOccurrences(of: "Open text.", with: "More. Open text.")) | |
| 221 | #expect(disk.contains(message)) | |
| 222 | // A changed entry gets a new message. | |
| 223 | try type("Changed. ", at: offset(of: Self.secret)) | |
| 224 | #expect(session.save()) | |
| 225 | #expect(!disk.contains(message) && !disk.contains("Changed.")) | |
| 226 | let saved = disk | |
| 227 | #expect(try OrgCrypt.decrypt(saved, at: (saved as NSString).range(of: "* Bank").location, passphrase: "pw").plaintext == "Changed. \(Self.secret)\n") | |
| 228 | // An entry left encrypted in the buffer stays as it is. | |
| 229 | let other = try notes.write("b.org", encrypted) | |
| 230 | session.open(other.path) | |
| 231 | try type("x", at: 0) | |
| 232 | #expect(session.save()) | |
| 233 | #expect((try String(contentsOf: other, encoding: .utf8)) == "x" + encrypted) | |
| 234 | } | |
| 235 | ||
| 236 | @Test func offWritesWhatTheBufferHas() throws { | |
| 237 | session.encryptsTaggedEntries = false | |
| 238 | try notes.write("a.org", "* Plain\n") | |
| 239 | session.open(file.path) | |
| 240 | try replace(with: Self.file) | |
| 241 | #expect(session.save()) | |
| 242 | #expect(disk == Self.file) | |
| 243 | #expect(session.openTexts[file.path] == Self.file) | |
| 244 | } | |
| 245 | ||
| 246 | @Test func aFileChangedOnDiskMergesWithTheDecryptedBuffer() throws { | |
| 247 | try notes.write("a.org", "* Plain\nOpen text.\n") | |
| 248 | session.open(file.path) | |
| 249 | session.cryptUsed("pw", for: file.path) | |
| 250 | try replace(with: Self.file) | |
| 251 | #expect(session.save()) | |
| 252 | // Another program appends to the file; the buffer keeps its decrypted entry. | |
| 253 | try notes.write("a.org", disk + "* From Emacs\n") | |
| 254 | session.fileChanged(file.path) | |
| 255 | #expect(session.document?.text == Self.file + "* From Emacs\n") | |
| 256 | #expect(!session.isDirty) | |
| 257 | try type("y", at: 0) | |
| 258 | #expect(session.save()) | |
| 259 | #expect(!disk.contains(Self.secret) && disk.hasSuffix("* From Emacs\n")) | |
| 260 | } | |
| 261 | ||
| 262 | // MARK: - Encrypted files | |
| 263 | ||
| 264 | static let gpgText = "* Diary\nDear diary, \(secret).\n" | |
| 265 | ||
| 266 | @Test func encryptedFilesOpenWithThePassphraseAndSaveEncrypted() throws { | |
| 267 | let message = try OpenPGP.encryptedMessage(Data(Self.gpgText.utf8), passphrase: "pw") | |
| 268 | let path = notes.url.appendingPathComponent("diary.org.gpg") | |
| 269 | try message.write(to: path) | |
| 270 | var written: [String] = [] | |
| 271 | session.fileWritten = { written.append($0) } | |
| 272 | session.open(path.path) | |
| 273 | #expect(session.unlockRequest == path.path) | |
| 274 | #expect(!session.isOpen(path.path)) | |
| 275 | #expect(session.unlock("wrong", for: path.path) == "Wrong passphrase") | |
| 276 | #expect(try Data(contentsOf: path) == message) | |
| 277 | #expect(session.unlock("pw", for: path.path) == nil) | |
| 278 | #expect(session.unlockRequest == nil) | |
| 279 | #expect(session.path == path.path && session.document?.text == Self.gpgText) | |
| 280 | #expect(session.isOrg) | |
| 281 | #expect(session.openTexts[path.path] == nil) | |
| 282 | try type("x", at: 0) | |
| 283 | #expect(session.save()) | |
| 284 | #expect(written == [path.path]) | |
| 285 | let disk = try Data(contentsOf: path) | |
| 286 | #expect(!OpenPGP.isArmored(disk)) | |
| 287 | #expect(disk.range(of: Data(Self.secret.utf8)) == nil) | |
| 288 | #expect(try OpenPGP.decryptFile(disk, passphrase: "pw") == Data(("x" + Self.gpgText).utf8)) | |
| 289 | // Recovery keeps the version replaced, encrypted, and shows it decrypted. | |
| 290 | #expect(!recoveryFiles.isEmpty && recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) | |
| 291 | let version = try #require(session.recoveryVersions().first) | |
| 292 | #expect(session.recoveryText(version.url) == Self.gpgText) | |
| 293 | // A passphrase forgotten while the file is open must be the file's when given again. | |
| 294 | session.crypt.forgetPassphrase(for: path.path) | |
| 295 | try type("y", at: 0) | |
| 296 | #expect(!session.save()) | |
| 297 | #expect(session.held[path.path] == .file) | |
| 298 | #expect(session.unlock("typo", for: path.path) == "Wrong passphrase") | |
| 299 | #expect(session.unlock("pw", for: path.path) == nil && !session.isDirty) | |
| 300 | #expect(try OpenPGP.decryptFile(Data(contentsOf: path), passphrase: "pw") == Data(("yx" + Self.gpgText).utf8)) | |
| 301 | // Closing forgets the passphrase. | |
| 302 | session.kill(path.path) | |
| 303 | session.open(path.path) | |
| 304 | #expect(session.unlockRequest == path.path) | |
| 305 | } | |
| 306 | ||
| 307 | @Test func armoredFilesStayArmored() throws { | |
| 308 | let armored = try OpenPGP.encrypt(Data(Self.gpgText.utf8), passphrase: "pw") | |
| 309 | let path = try notes.write("diary.org.gpg", armored) | |
| 310 | session.open(path.path) | |
| 311 | #expect(session.unlock("pw", for: path.path) == nil) | |
| 312 | try type("x", at: 0) | |
| 313 | #expect(session.save()) | |
| 314 | let disk = try Data(contentsOf: path) | |
| 315 | #expect(OpenPGP.isArmored(disk)) | |
| 316 | #expect(try OpenPGP.decryptFile(disk, passphrase: "pw") == Data(("x" + Self.gpgText).utf8)) | |
| 317 | } | |
| 318 | ||
| 319 | @Test func aNewEncryptedFileWaitsForItsPassphrase() throws { | |
| 320 | let path = try notes.write("new.org.gpg", "") | |
| 321 | session.open(path.path) | |
| 322 | #expect(session.unlockRequest == nil && session.path == path.path) | |
| 323 | try type(Self.gpgText, at: 0) | |
| 324 | #expect(!session.save()) | |
| 325 | #expect(session.held[path.path] == .file) | |
| 326 | #expect(try Data(contentsOf: path).isEmpty) | |
| 327 | #expect(recoveryFiles.isEmpty) | |
| 328 | #expect(session.unlock("new", for: path.path) == nil) | |
| 329 | #expect(!session.isDirty && session.held.isEmpty) | |
| 330 | #expect(try OpenPGP.decryptFile(Data(contentsOf: path), passphrase: "new") == Data(Self.gpgText.utf8)) | |
| 331 | } | |
| 332 | ||
| 333 | @Test func anEncryptedFileChangedOnDiskMergesInMemory() throws { | |
| 334 | let path = notes.url.appendingPathComponent("diary.org.gpg") | |
| 335 | try OpenPGP.encryptedMessage(Data(Self.gpgText.utf8), passphrase: "pw").write(to: path) | |
| 336 | session.open(path.path) | |
| 337 | #expect(session.unlock("pw", for: path.path) == nil) | |
| 338 | try type("x", at: 0) | |
| 339 | try OpenPGP.encryptedMessage(Data((Self.gpgText + "* Added elsewhere\n").utf8), passphrase: "pw").write(to: path) | |
| 340 | session.fileChanged(path.path) | |
| 341 | #expect(session.document?.text == "x" + Self.gpgText + "* Added elsewhere\n") | |
| 342 | #expect(session.save()) | |
| 343 | #expect(try OpenPGP.decryptFile(Data(contentsOf: path), passphrase: "pw") == Data(("x" + Self.gpgText + "* Added elsewhere\n").utf8)) | |
| 344 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) && !$0.contains("Added elsewhere") }) | |
| 345 | } | |
| 346 | } | |
Tests/OrgCoreTests/CryptFileTests.swift added +163 · view
| @@ -0,0 +1,163 @@ | ||
| 1 | import Foundation | |
| 2 | import Testing | |
| 3 | @testable import OrgCore | |
| 4 | ||
| 5 | /// Encrypting tagged entries on save (`OrgCrypt.seal`) and whole encrypted files, against | |
| 6 | /// gpg and Emacs's EasyPG. | |
| 7 | struct CryptFileTests { | |
| 8 | static var oracle: Bool { ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil } | |
| 9 | static var gpg: Bool { OpenPGPTests.gpg != nil } | |
| 10 | static var emacs: Bool { gpg && oracle && EmacsOracle.isAvailable } | |
| 11 | ||
| 12 | @Test func sealEncryptsTaggedEntriesFromTheTop() throws { | |
| 13 | let (sealed, messages) = try OrgCrypt.seal(OrgCryptTests.file, passphrase: "pw") | |
| 14 | // Bank's tagged child goes inside Bank's message; the empty entry gets one too. | |
| 15 | #expect(messages.map(\.plaintext) == ["Account 12345, ünïcödé.\n** Child\nChild text.\n", "Dear diary.\n", ""]) | |
| 16 | let (all, count) = try OrgCrypt.encryptAll(OrgCryptTests.file, passphrase: "pw") | |
| 17 | #expect(count == 3) | |
| 18 | #expect(OrgCryptTests.masked(sealed) == OrgCryptTests.masked(all)) | |
| 19 | for (message, plaintext) in messages { | |
| 20 | #expect(sealed.contains(message)) | |
| 21 | #expect(try String(decoding: OpenPGP.decrypt(OpenPGP.dearmor(message), passphrase: "pw"), as: UTF8.self) == plaintext) | |
| 22 | } | |
| 23 | // Sealing again changes nothing: every entry is encrypted. | |
| 24 | #expect(try OrgCrypt.seal(sealed, passphrase: "pw").text == sealed) | |
| 25 | // Entries known by their text get their message back. | |
| 26 | let known = Dictionary(uniqueKeysWithValues: messages.map { (OrgCrypt.checksum($0.plaintext), $0.message) }) | |
| 27 | #expect(try OrgCrypt.seal(OrgCryptTests.file, passphrase: "pw", reuse: { known[$0] }).text == sealed) | |
| 28 | // Without the tag, the text is as it was. | |
| 29 | #expect(try OrgCrypt.seal("* A\ntext\n", passphrase: "pw").text == "* A\ntext\n") | |
| 30 | } | |
| 31 | ||
| 32 | @Test func newMessagesUseGnuPGsIterationCount() throws { | |
| 33 | let clock = ContinuousClock() | |
| 34 | var message = Data() | |
| 35 | let time = try clock.measure { message = try OpenPGP.encryptedMessage(Data("x".utf8), passphrase: "pw") } | |
| 36 | let first = try #require(try OpenPGP.packets(message).first) | |
| 37 | // Version 4, AES-256, iterated and salted SHA-256, 8 bytes of salt, coded count 0xFF. | |
| 38 | #expect(first.tag == 3 && Array(first.body.prefix(4)) == [4, 9, 3, 8] && first.body[12] == 0xFF) | |
| 39 | #expect(OpenPGP.isSymmetric(message)) | |
| 40 | #expect(!OpenPGP.isSymmetric(Data([0xC1, 0x02, 0x03, 0x00]))) | |
| 41 | let read = try clock.measure { _ = try OpenPGP.decrypt(message, passphrase: "pw") } | |
| 42 | print("S2K with coded count 0xFF: encrypt \(time), decrypt \(read)") | |
| 43 | } | |
| 44 | ||
| 45 | @Test func textBelowAMessageIsSealedWithIt() throws { | |
| 46 | let bank = (OrgCryptTests.file as NSString).range(of: "* TODO Bank").location | |
| 47 | let one = try #require(try OrgCrypt.encrypt(OrgCryptTests.file, at: bank, passphrase: "pw")) | |
| 48 | let typed = one.replacingOccurrences(of: "\n* Diary", with: "\nTyped below.\n* Diary") | |
| 49 | #expect(OrgCrypt.unencrypted(typed).count == 2) | |
| 50 | let (sealed, messages) = try OrgCrypt.seal(typed, passphrase: "pw") | |
| 51 | #expect(!sealed.contains("Typed below.")) | |
| 52 | #expect(try OrgCrypt.decrypt(sealed, at: bank, passphrase: "pw").plaintext == "Account 12345, ünïcödé.\n** Child\nChild text.\n\nTyped below.\n") | |
| 53 | // What reads back for the message is the text the entry had, message and all. | |
| 54 | #expect(messages.first?.plaintext.contains("-----BEGIN PGP MESSAGE-----") == true) | |
| 55 | #expect(throws: OrgCrypt.Failure.self) { try OrgCrypt.seal(typed, passphrase: "wrong") } | |
| 56 | } | |
| 57 | ||
| 58 | @Test func unencryptedEntriesWithText() throws { | |
| 59 | #expect(OrgCrypt.unencrypted(OrgCryptTests.file).count == 2) | |
| 60 | let bank = (OrgCryptTests.file as NSString).range(of: "* TODO Bank").location | |
| 61 | let one = try #require(try OrgCrypt.encrypt(OrgCryptTests.file, at: bank, passphrase: "pw")) | |
| 62 | #expect(OrgCrypt.unencrypted(one).count == 1) | |
| 63 | #expect(OrgCrypt.firstMessage(one).map { OrgCrypt.opens($0, passphrase: "pw") } == true) | |
| 64 | #expect(OrgCrypt.firstMessage(one).map { OrgCrypt.opens($0, passphrase: "other") } == false) | |
| 65 | #expect(OrgCrypt.firstMessage(OrgCryptTests.file) == nil) | |
| 66 | #expect(OrgCrypt.unencrypted("* Empty :crypt:\n\n* B\n").isEmpty) | |
| 67 | #expect(OrgCrypt.unencrypted("#+FILETAGS: :crypt:\n* A\nsecret\n").count == 1) | |
| 68 | } | |
| 69 | ||
| 70 | @Test func encryptedFilesRoundTrip() throws { | |
| 71 | let text = Data("* Diary\nDear diary, ünïcödé.\n".utf8) | |
| 72 | let binary = try OpenPGP.encryptedMessage(text, passphrase: "pw") | |
| 73 | #expect(!OpenPGP.isArmored(binary)) | |
| 74 | #expect(try OpenPGP.decryptFile(binary, passphrase: "pw") == text) | |
| 75 | let armored = Data(try OpenPGP.encrypt(text, passphrase: "pw").utf8) | |
| 76 | #expect(OpenPGP.isArmored(armored)) | |
| 77 | #expect(try OpenPGP.decryptFile(armored, passphrase: "pw") == text) | |
| 78 | #expect(throws: OpenPGP.wrongPassphrase) { try OpenPGP.decryptFile(binary, passphrase: "wrong") } | |
| 79 | #expect(throws: OpenPGP.Failure.self) { try OpenPGP.decryptFile(Data("* plain text\n".utf8), passphrase: "pw") } | |
| 80 | } | |
| 81 | ||
| 82 | @Test(.enabled(if: gpg && oracle)) | |
| 83 | func gpgReadsAndWritesEncryptedFiles() throws { | |
| 84 | let text = Data("* Diary\nDear diary, ünïcödé.\n".utf8) | |
| 85 | // `gpg --decrypt` reads orgstar's file, binary as orgstar writes it by default. | |
| 86 | let ours = try OpenPGP.encryptedMessage(text, passphrase: "pass phrase") | |
| 87 | #expect(try OpenPGPTests.gpg(["--passphrase", "pass phrase", "--decrypt"], input: ours) == text) | |
| 88 | // orgstar reads `gpg --symmetric`, binary and armored. | |
| 89 | let theirs = try OpenPGPTests.gpg(["--passphrase", "pass phrase", "--symmetric"], input: text) | |
| 90 | #expect(!OpenPGP.isArmored(theirs)) | |
| 91 | #expect(try OpenPGP.decryptFile(theirs, passphrase: "pass phrase") == text) | |
| 92 | let armored = try OpenPGPTests.gpg(["--passphrase", "pass phrase", "--symmetric", "--armor"], input: text) | |
| 93 | #expect(try OpenPGP.decryptFile(armored, passphrase: "pass phrase") == text) | |
| 94 | #expect(throws: OpenPGP.Failure.self) { try OpenPGP.decryptFile(theirs, passphrase: "wrong") } | |
| 95 | } | |
| 96 | ||
| 97 | /// Emacs with EasyPG (`epa-file`), symmetric, the passphrase given without asking, run on | |
| 98 | /// `file` in a fresh GnuPG home: `form` runs with `file` as the variable `file`. | |
| 99 | static func emacs(_ form: String, in folder: URL) throws -> String { | |
| 100 | let home = "/tmp/ogpg-\(UUID().uuidString.prefix(8))" | |
| 101 | try FileManager.default.createDirectory(atPath: home, withIntermediateDirectories: true, attributes: [.posixPermissions: 0o700]) | |
| 102 | defer { | |
| 103 | let kill = Process() | |
| 104 | kill.executableURL = URL(fileURLWithPath: "/usr/bin/env") | |
| 105 | kill.arguments = ["gpgconf", "--homedir", home, "--kill", "gpg-agent"] | |
| 106 | try? kill.run() | |
| 107 | kill.waitUntilExit() | |
| 108 | try? FileManager.default.removeItem(atPath: home) | |
| 109 | } | |
| 110 | let elisp = """ | |
| 111 | (progn | |
| 112 | (require 'org) (require 'epa-file) (epa-file-enable) | |
| 113 | (setq epg-pinentry-mode 'loopback epa-pinentry-mode 'loopback epa-file-select-keys 'silent epa-file-encrypt-to nil | |
| 114 | epg-gpg-program \(OrgCryptTests.lisp(OpenPGPTests.gpg!)) default-directory \(OrgCryptTests.lisp(folder.path + "/"))) | |
| 115 | (cl-letf (((symbol-function 'epa-file-passphrase-callback-function) (lambda (&rest _) (copy-sequence "pw one"))) | |
| 116 | ((symbol-function 'epa-passphrase-callback-function) (lambda (&rest _) (copy-sequence "pw one")))) | |
| 117 | \(form))) | |
| 118 | """ | |
| 119 | return try EmacsOracle.run(["-Q", "--batch", "--eval", elisp], environment: ["GNUPGHOME": home, "TZ": "UTC"]) | |
| 120 | } | |
| 121 | ||
| 122 | @Test(.enabled(if: emacs)) | |
| 123 | func emacsOpensWhatOrgstarWritesAndTheReverse() throws { | |
| 124 | let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-gpg-\(UUID().uuidString)") | |
| 125 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) | |
| 126 | defer { try? FileManager.default.removeItem(at: folder) } | |
| 127 | let text = "* Diary :private:\nDear diary, ünïcödé.\n** Child\nMore.\n" | |
| 128 | // orgstar's file, binary and armored, opened by `find-file` in Emacs. | |
| 129 | for (name, data) in [("ours.org.gpg", try OpenPGP.encryptedMessage(Data(text.utf8), passphrase: "pw one")), | |
| 130 | ("armored.org.gpg", Data(try OpenPGP.encrypt(Data(text.utf8), passphrase: "pw one").utf8))] { | |
| 131 | try data.write(to: folder.appendingPathComponent(name)) | |
| 132 | let log = try Self.emacs(""" | |
| 133 | (with-current-buffer (find-file-noselect \(OrgCryptTests.lisp(name))) | |
| 134 | (let ((coding-system-for-write 'utf-8-unix)) (write-region (point-min) (point-max) "out.txt"))) | |
| 135 | """, in: folder) | |
| 136 | let read = try? String(contentsOf: folder.appendingPathComponent("out.txt"), encoding: .utf8) | |
| 137 | #expect(read == text, "\(log)") | |
| 138 | try? FileManager.default.removeItem(at: folder.appendingPathComponent("out.txt")) | |
| 139 | } | |
| 140 | // Emacs's file, saved through EasyPG, opened by orgstar. | |
| 141 | let log = try Self.emacs(""" | |
| 142 | (with-current-buffer (find-file-noselect "theirs.org.gpg") | |
| 143 | (insert \(OrgCryptTests.lisp(text))) | |
| 144 | (let ((coding-system-for-write 'utf-8-unix)) (save-buffer))) | |
| 145 | """, in: folder) | |
| 146 | let theirs = try Data(contentsOf: folder.appendingPathComponent("theirs.org.gpg")) | |
| 147 | #expect(theirs.range(of: Data("Dear diary".utf8)) == nil, "\(log)") | |
| 148 | #expect(String(decoding: try OpenPGP.decryptFile(theirs, passphrase: "pw one"), as: UTF8.self) == text) | |
| 149 | #expect(throws: OpenPGP.Failure.self) { try OpenPGP.decryptFile(theirs, passphrase: "wrong") } | |
| 150 | } | |
| 151 | ||
| 152 | @Test(.enabled(if: emacs)) | |
| 153 | func orgCryptKeepsAnUnchangedEntrysMessageAsOrgstarDoes() throws { | |
| 154 | // Emacs: an entry decrypted and encrypted again, unchanged, gets its own message back. | |
| 155 | // An entry with no text has none to carry the old message, and gets a new one. | |
| 156 | let file = OrgCryptTests.file.replacingOccurrences(of: "* Empty :crypt:\n", with: "") | |
| 157 | let (sealed, _) = try OrgCrypt.seal(file, passphrase: "pw one") | |
| 158 | let again = try OrgCryptTests.emacs(sealed, "(org-decrypt-entries) (org-encrypt-entries)") | |
| 159 | #expect(again == sealed) | |
| 160 | // And reads what orgstar sealed. | |
| 161 | #expect(try OrgCryptTests.emacs(sealed, "(org-decrypt-entries)") == file) | |
| 162 | } | |
| 163 | } | |
Tests/OrgDocumentTests/CryptSaverTests.swift added +63 · view
| @@ -0,0 +1,63 @@ | ||
| 1 | import Foundation | |
| 2 | import OrgCore | |
| 3 | import Testing | |
| 4 | @testable import OrgDocument | |
| 5 | ||
| 6 | /// A version another writer puts on disk just before ours, with crypt-tagged entries in | |
| 7 | /// plaintext and no passphrase known: recovery can't keep it, and it must not be lost. | |
| 8 | struct CryptSaverTests { | |
| 9 | static let theirs = "a\nb\nc\n* Theirs :crypt:\ntheir secret\n" | |
| 10 | ||
| 11 | func saver(_ files: FaultyFileSystem, _ recovery: MemoryRecovery) -> (Saver, CryptVault) { | |
| 12 | let vault = CryptVault() | |
| 13 | vault.encryptsTaggedEntries = true | |
| 14 | return (Saver(fileSystem: CryptFileSystem(base: files, vault: vault), recovery: CryptRecoveryStore(base: recovery, vault: vault)), vault) | |
| 15 | } | |
| 16 | ||
| 17 | @Test func anOverwrittenVersionMergesIntoTheBuffer() throws { | |
| 18 | let files = FaultyFileSystem("a\nb\nc\n") | |
| 19 | files.beforeReplace = Array(Self.theirs.utf8) | |
| 20 | let recovery = MemoryRecovery() | |
| 21 | var doc = try editedState() | |
| 22 | let outcome = try saver(files, recovery).0.save(&doc, to: url) | |
| 23 | guard case .overwroteExternalChange(.merged) = outcome else { Issue.record("\(outcome)"); return } | |
| 24 | #expect(doc.text.contains("their secret")) | |
| 25 | #expect(recovery.kept.allSatisfy { !$0.text.contains("their secret") }) | |
| 26 | } | |
| 27 | ||
| 28 | @Test func aConflictingOverwrittenVersionGoesIntoTheBufferWithMarkers() throws { | |
| 29 | let files = FaultyFileSystem("a\nb\nc\n") | |
| 30 | files.beforeReplace = Array("Z\nb\nc\n* Theirs :crypt:\ntheir secret\n".utf8) | |
| 31 | let recovery = MemoryRecovery() | |
| 32 | var doc = try editedState() | |
| 33 | let outcome = try saver(files, recovery).0.save(&doc, to: url) | |
| 34 | #expect(outcome == .overwroteExternalChange(.conflict([]))) | |
| 35 | #expect(doc.text.contains("their secret") && doc.text.contains("Z") && doc.text.contains("A")) | |
| 36 | #expect(recovery.kept.allSatisfy { !$0.text.contains("their secret") }) | |
| 37 | } | |
| 38 | ||
| 39 | @Test func keepMineDoesntReplaceAVersionItCantKeep() throws { | |
| 40 | let files = FaultyFileSystem(Self.theirs) | |
| 41 | let recovery = MemoryRecovery() | |
| 42 | var doc = try editedState() | |
| 43 | #expect(throws: CryptHold.self) { try saver(files, recovery).0.overwrite(&doc, to: url) } | |
| 44 | #expect(files.text == Self.theirs) | |
| 45 | } | |
| 46 | ||
| 47 | @Test func closedFilesKeepNothingAfterTheirWrite() async throws { | |
| 48 | let files = FaultyFileSystem("a\n") | |
| 49 | let recovery = MemoryRecovery() | |
| 50 | let (saver, vault) = saver(files, recovery) | |
| 51 | vault.unlock("pw", for: url.path) | |
| 52 | var doc = state("a\n") | |
| 53 | try doc.apply([TextEdit(range: 2..<2, replacement: "* S :crypt:\nsecret\n")], baseRevision: 0) | |
| 54 | #expect(try saver.save(&doc, to: url) == .saved) | |
| 55 | #expect(files.text?.contains("secret") == false) | |
| 56 | await MainActor.run {} | |
| 57 | try await Task.sleep(for: .milliseconds(50)) | |
| 58 | #expect(!vault.keepsAnything(for: url.path)) | |
| 59 | // Only open files keep sealing after the setting goes off. | |
| 60 | vault.encryptsTaggedEntries = false | |
| 61 | #expect(!vault.sealsEntries(for: url.path)) | |
| 62 | } | |
| 63 | } | |
docs/manual/guide/04-outlines.org +34 −1 · view
| @@ -953,7 +953,40 @@ The commands have no keys, as in Org; run them from the command palette, or bind | ||
| 953 | 953 | |
| 954 | 954 | Remember in the Keychain stores the passphrase for the file. The next command on that file uses it after Touch ID, Face ID or the device password, without asking. =org-crypt-tag-matcher= in =config.toml= sets the tag; it must be a single tag, not a match expression. |
| 955 | 955 | |
| 956 | Messages are written with AES-256 and an iterated and salted SHA-256 key, which GnuPG and Emacs read. Messages using AES-128, AES-192 or AES-256 are read, compressed or not. Messages encrypted to a public key, other ciphers, and AEAD (OpenPGP version 5 and 6) packets are not supported. Saving doesn't encrypt tagged entries, as =org-crypt-use-before-save-magic= does in Emacs; run Encrypt Tagged Entries…. | |
| 956 | Messages are written with AES-256 and an iterated and salted SHA-256 key, which GnuPG and Emacs read. Messages using AES-128, AES-192 or AES-256 are read, compressed or not. Messages encrypted to a public key, other ciphers, and AEAD (OpenPGP version 5 and 6) packets are not supported. | |
| 957 | ||
| 958 | ** Encrypting on save | |
| 959 | ||
| 960 | With =org-crypt-use-before-save-magic = true= in =config.toml=, every save, the automatic one included, encrypts the tagged entries that aren't encrypted, as =org-crypt-use-before-save-magic= does in Emacs. It is off by default. | |
| 961 | ||
| 962 | - The editor keeps the entries' text; the file gets the messages. Emacs leaves the encrypted messages in its buffer after a save; orgstar doesn't, since it saves a second after typing stops. | |
| 963 | - An entry decrypted with Decrypt Entry in File… and saved unchanged gets its old message back, byte for byte, as org-crypt does, and so does an entry left unchanged between saves. Only entries that changed get a new message, so syncing and git see no other change. A new message takes GnuPG's key iterations (about 65 MB of hashing); each changed entry adds a few hundredths of a second to its save. | |
| 964 | - Text typed below an entry's message isn't encrypted until it goes into the message: the save opens the old message with the passphrase and encrypts it with the new text as one. | |
| 965 | - Turning the setting off while a file is open doesn't write what it encrypted in plaintext: the file keeps encrypting its tagged entries until it's closed. Files opened afterwards are saved as they are. | |
| 966 | - The passphrase comes from the Keychain when it was remembered for the file, after Touch ID, Face ID or the device password. That is asked once for each file while it's open, at the first save that needs it; another file asks again, and so does the same file after it was closed. A passphrase typed for an org-crypt command on the file is used too. Closing the file or Forget Encryption Passphrase forgets it. | |
| 967 | - Without the passphrase, or when Touch ID is declined, the file isn't saved at all, and no recovery version or snapshot of it is kept, until the entries can be encrypted. A notice above the mode line (on iOS, at the top of the editor) says how many tagged entries aren't encrypted, and stays while that's so; its Encrypt… button asks for the passphrase and saves. Other edits to the file wait meanwhile. An entry with no text doesn't keep the file from being saved. | |
| 968 | - When the file has encrypted entries already, the passphrase must open them. A first passphrase is asked twice. Entries encrypted to a public key (=org-crypt-key=) are left as they are and aren't checked; text typed below one can't be encrypted, and saving says so. | |
| 969 | - Use Disk Version, Merge with Markers, restoring an earlier version and resolving a sync conflict keep a copy of the editor's text first; while the file is held that copy can't be kept encrypted, so they stop and ask for the passphrase first. Replace in Files on a held file that has no editor open replaces without keeping a copy; the replacement can be undone in the file. | |
| 970 | - Archiving, refiling or copying an entry with the tag to another file encrypts it in place first; without the passphrase it isn't moved. A heading inside an encrypted entry (in its message on disk) isn't archived, refiled or copied on its own; move the encrypted entry. | |
| 971 | - When another program saves the file with tagged entries in plaintext, the file is held the same way until the passphrase lets orgstar keep a copy of that version encrypted and merge it. A version another program writes in the moment orgstar saves goes into the editor when no copy of it can be kept; if it conflicts, both versions are there between conflict markers, and the file is marked as in conflict. Keep Mine on such a file is held until the passphrase is given. | |
| 972 | - An entry that the passphrase can't encrypt (text typed below a message encrypted with another passphrase, or to a public key) holds the file too; the notice says why, without an Encrypt… button. | |
| 973 | - Closing the file, its window, or quitting while it's held asks for the passphrase, or whether to leave without saving; any other save that fails then offers Don't Save. On iOS, the edits stay in memory while orgstar is in the background, and the notice is there on return; if iOS ends orgstar meanwhile, the edits are lost, and orgstar says so when it next opens. | |
| 974 | - While an entry is decrypted in the editor, the agenda, widgets, the watch and reminders read the file from disk, where the entry is encrypted. The index, Spotlight and Quick Look read files from disk too. iCalendar export and publishing read such a file from disk and say so. Recalculating a table in Emacs, exporting with Emacs and =elisp:= links in Emacs aren't given a copy of the file. Clocking in to a heading inside such an entry shows "Encrypted entry" in the clock's history, widgets, the Live Activity and the menu bar. Handoff doesn't offer the file, and Share Subtree… shares tagged entries encrypted as they are on disk, or, without the passphrase or when they can't be encrypted, not at all. Shared from inside an encrypted entry, a heading is shared as an entry titled "Encrypted entry" with the tag, whose one message holds the heading and everything under it. | |
| 975 | ||
| 976 | * Encrypted files | |
| 977 | ||
| 978 | orgstar opens and saves files encrypted with a passphrase as GnuPG (=gpg --symmetric=) and Emacs's EasyPG (=epa-file=) write them, named =NAME.org.gpg=. They show in the sidebar and the file list by name. | |
| 979 | ||
| 980 | Opening one asks for its passphrase, or takes it from the Keychain after Touch ID, Face ID or the device password; Remember in the Keychain keeps it for the file. A wrong passphrase leaves the file closed and as it was. While the file is open, saves encrypt it with that passphrase; closing it forgets the passphrase. A new file named =NAME.org.gpg= is empty: it isn't saved until Set Passphrase… in its notice gives it a passphrase, typed twice. | |
| 981 | ||
| 982 | The decrypted text is kept in memory only: | |
| 983 | - Files are written with AES-256 and an iterated and salted SHA-256 key, binary, or armored when the file was armored. | |
| 984 | - Recovery versions and hourly snapshots are kept encrypted with the file's passphrase, and Recovery Versions… shows them decrypted. Changes made to the file elsewhere are merged in memory, and a conflict is compared in memory. | |
| 985 | - The index, search, Spotlight, Quick Look, the agenda, widgets and the watch don't read the file's text. iCalendar export and publishing leave it out, and Emacs isn't given a copy of it. A clocked heading shows as "Encrypted entry" outside the editor. Handoff doesn't offer the file, and Share Subtree… refuses its entries. | |
| 986 | - Archiving from =NAME.org.gpg= goes to =NAME_archive.org.gpg=, encrypted with the same passphrase (Org would write =NAME.org.gpg_archive=, unencrypted). Entries aren't refiled or copied from it to a file that isn't encrypted. | |
| 987 | - Remembered passphrases are kept by the file's path, on this device only, readable while it's unlocked and after Touch ID, Face ID or the device password; renaming the file forgets it. Passphrases remembered by earlier versions move to this kind of item the first time they're used. The version of orgstar downloaded from the website can't make such items (it has no Keychain entitlement): it keeps remembered passphrases in the login keychain, not limited to this Mac, still asking for Touch ID or the password before one is used, and says so beside Remember in the Keychain. | |
| 988 | ||
| 989 | =age= files (=.age=) aren't supported. | |
| 957 | 990 | |
| 958 | 991 | * The outline pane |
| 959 | 992 | |
docs/manual/guide/13-configuration.org +2 −1 · view
| @@ -218,7 +218,7 @@ These settings have no control in the Settings window. Some are in the View menu | ||
| 218 | 218 | | =notes-package=, =denote-directory=, =denote-prompts=, =denote-silo-directories=, =denote-sequence-scheme=, =denote-journal-directory=, =denote-journal-keyword=, =denote-journal-interval=, =denote-journal-title-format= | | |
| 219 | 219 | | =org-attach-id-dir=, =org-attach-use-inheritance= | | |
| 220 | 220 | | =org-yank-image-save-method=, =org-yank-dnd-method= | | |
| 221 | | =org-crypt-tag-matcher= | | | |
| 221 | | =org-crypt-tag-matcher=, =org-crypt-use-before-save-magic= | | | |
| 222 | 222 | | =org-agenda-start-on-weekday= | | |
| 223 | 223 | | =org-deadline-warning-days= | | |
| 224 | 224 | | =org-agenda-skip-scheduled-if-done= | | |
| @@ -291,6 +291,7 @@ A key you remove from the file goes back to its default. A key that isn't in the | ||
| 291 | 291 | | =org-yank-image-save-method= | string | ="attach"= | Where a pasted image goes: =attach= for the entry's attachment folder, or a folder, relative to the org file's folder unless absolute. See [[file:09-links.org][Links]]. Mirrors =org-yank-image-save-method=. | |
| 292 | 292 | | =org-yank-dnd-method= | string | ="ask"= | What dropping files on the editor does: =ask=, =attach=, =open= or =file-link=. See [[file:09-links.org][Links]]. Mirrors =org-yank-dnd-method=. | |
| 293 | 293 | | =org-crypt-tag-matcher= | string | ="crypt"= | The tag Encrypt Tagged Entries… encrypts. A single tag. See [[file:04-outlines.org][Outlines]]. Mirrors =org-crypt-tag-matcher=. | |
| 294 | | =org-crypt-use-before-save-magic= | boolean | =false= | Encrypt the entries with =org-crypt-tag-matcher='s tag on every save. Without their passphrase the file isn't saved until it's given. See [[file:04-outlines.org][Outlines]]. Mirrors =org-crypt-use-before-save-magic=. | | |
| 294 | 295 | | =org-startup-indented= | boolean | =true= | Indent bodies under their headings, as =org-indent-mode=. =#+STARTUP: indent= / =noindent= override it. Mirrors =org-startup-indented=. | |
| 295 | 296 | | =org-hide-leading-stars= | boolean | =false= | Show only a heading's last star, without indentation. =#+STARTUP: hidestars= / =showstars= override it. Mirrors =org-hide-leading-stars=. | |
| 296 | 297 | | =org-startup-align-all-tables= | boolean | =false= | Align every table when a file opens. =#+STARTUP: align= / =noalign= override it. Mirrors =org-startup-align-all-tables=. | |
docs/manual/guide/14-ios.org +3 −1 · view
| @@ -208,6 +208,8 @@ Commands has the org-crypt commands; see [[file:04-outlines.org][Outlines]]. A r | ||
| 208 | 208 | |
| 209 | 209 | Rename Tag… and Rename TODO Keyword… in the editor's Commands, under TODO and Tags, rename a tag or a keyword in every org file of one folder or all folders, as on the Mac: a sheet asks for the old and new name (the menu beside the first field lists the tags of your folders, or the keywords), the folder, and whether to change =config.toml= too; Find lists each line that changes, with a switch to leave it out, and Rename applies them. A change to =config.toml= goes into the synced folder's file. See [[file:05-todos-and-tags.org][TODOs and tags]]. |
| 210 | 210 | |
| 211 | With =org-crypt-use-before-save-magic=, a file whose tagged entries can't be encrypted isn't saved; a notice at the top of the editor says so, with Encrypt…. Going to the background saves every other file; the held file's edits stay in memory and the notice is there on return. iOS can end orgstar in the background without asking: the held edits are then lost, and the next launch names the files. Files named =NAME.org.gpg= are listed with the org files and open after their passphrase; see [[file:04-outlines.org][Outlines]]. | |
| 212 | ||
| 211 | 213 | ** The menu bar on iPad |
| 212 | 214 | |
| 213 | 215 | The iPad's menu bar, and the list of keys shown while =⌘= is held on a hardware keyboard, have these menus, after the Mac's and with the Mac's keys: |
| @@ -525,7 +527,7 @@ These settings from =config.toml= apply on iOS: | ||
| 525 | 527 | - =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer= |
| 526 | 528 | - =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks= |
| 527 | 529 | - =org-roam-directory=, =org-roam-dailies-directory=, =org-roam-dailies-file=, =org-roam-dailies-head=, =org-roam-dailies-entry= |
| 528 | - =org-crypt-tag-matcher=, =org-attach-id-dir=, =org-attach-use-inheritance=, =org-yank-image-save-method=, =org-timer-format=, =org-timer-default-timer= | |
| 530 | - =org-crypt-tag-matcher=, =org-crypt-use-before-save-magic=, =org-attach-id-dir=, =org-attach-use-inheritance=, =org-yank-image-save-method=, =org-timer-format=, =org-timer-default-timer= | |
| 529 | 531 | - =org-archive-location=, =[org-structure-template-alist]= |
| 530 | 532 | - =org-use-tag-inheritance=, =org-tags-exclude-from-inheritance=, =org-tag-alist= |
| 531 | 533 | - =org-use-speed-commands=, with a hardware keyboard |
docs/manual/guide/15-alongside-emacs.org +2 −1 · view
| @@ -296,5 +296,6 @@ Other: | ||
| 296 | 296 | - org-timer: =org-timer-display= is always the mode line. The timer's =C-u= forms are separate commands bound to =C-u C-c C-x 0=, =C-u C-u C-c C-x 0= and =C-u C-c C-x ,=; Set Countdown Timer… has no prefix-argument forms. |
| 297 | 297 | - Radio lists are Org 9.8's =#+ATTR_ORG: :radio= checkbox lists. The =#+ORGLST= radio lists of Org 9.1 and earlier, removed in Org 9.2, aren't supported, nor is =org-list-checkbox-radio-mode=. |
| 298 | 298 | - org-attach: =org-attach-method= is always =cp= for Attach File… (the other methods have their own commands), =org-attach-auto-tag= is always =ATTACH=, =org-attach-preferred-new-method= is always =id=, and =org-attach-id-to-path-function-list= is Org's default. The dispatcher's =b=, =O= and =F= keys and =org-attach-archive-delete= aren't supported. Delete All Attachments… asks once and deletes the folder with what's in it. |
| 299 | - org-crypt works with symmetric encryption only (=org-crypt-key= nil); public keys and =org-crypt-use-before-save-magic= aren't supported. =org-crypt-tag-matcher= is a single tag. | |
| 299 | - org-crypt works with symmetric encryption only (=org-crypt-key= nil); public keys aren't supported. =org-crypt-tag-matcher= is a single tag. =org-crypt-use-before-save-magic= is a setting in =config.toml= rather than a function to call; with it, entries stay decrypted in the editor after a save, where Emacs's buffer holds the messages, and a file whose entries can't be encrypted isn't saved, where Emacs asks for the passphrase. Emacs Import doesn't read the call. =org-crypt-disable-auto-save= has no counterpart: orgstar keeps no auto-save files. | |
| 300 | - EasyPG's =.gpg= files are read and written with a passphrase only (symmetric); files encrypted to public keys aren't supported. orgstar keeps no passphrase cache beyond the open file; =epa-file-cache-passphrase-for-symmetric-encryption= has no counterpart. | |
| 300 | 301 | - When TODO dependencies refuse a change on a =COMMENT= heading, the heading keeps =COMMENT=. Org removes it before the check and doesn't put it back. |
l10n/Localizable.xcstrings +1395 · view
| @@ -430,6 +430,40 @@ | ||
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | }, |
| 433 | "%@ changed on disk while saving, and the changes conflict with yours; both are in the editor between conflict markers.": { | |
| 434 | "localizations": { | |
| 435 | "de": { | |
| 436 | "stringUnit": { | |
| 437 | "state": "translated", | |
| 438 | "value": "„%@“ wurde beim Sichern auf dem Datenträger geändert, und die Änderungen widersprechen deinen; beide stehen im Editor zwischen Konfliktmarkierungen." | |
| 439 | } | |
| 440 | }, | |
| 441 | "es": { | |
| 442 | "stringUnit": { | |
| 443 | "state": "translated", | |
| 444 | "value": "«%@» cambió en el disco mientras se guardaba y los cambios entran en conflicto con los tuyos; ambos están en el editor entre marcas de conflicto." | |
| 445 | } | |
| 446 | }, | |
| 447 | "fr": { | |
| 448 | "stringUnit": { | |
| 449 | "state": "translated", | |
| 450 | "value": "« %@ » a changé sur le disque pendant l'enregistrement, et les modifications sont en conflit avec les vôtres ; les deux sont dans l'éditeur entre des marqueurs de conflit." | |
| 451 | } | |
| 452 | }, | |
| 453 | "ja": { | |
| 454 | "stringUnit": { | |
| 455 | "state": "translated", | |
| 456 | "value": "保存中に“%@”がディスク上で変更され、あなたの変更と競合しています。両方がコンフリクトマーカーで囲まれてエディタにあります。" | |
| 457 | } | |
| 458 | }, | |
| 459 | "pt-BR": { | |
| 460 | "stringUnit": { | |
| 461 | "state": "translated", | |
| 462 | "value": "\"%@\" mudou no disco durante o salvamento, e as alterações conflitam com as suas; ambas estão no editor entre marcadores de conflito." | |
| 463 | } | |
| 464 | } | |
| 465 | } | |
| 466 | }, | |
| 433 | 467 | "%@ doesn't contain %@.": { |
| 434 | 468 | "comment": "Alert when the folder chosen to grant access doesn't contain the one needed", |
| 435 | 469 | "localizations": { |
| @@ -471,6 +505,74 @@ | ||
| 471 | 505 | } |
| 472 | 506 | } |
| 473 | 507 | }, |
| 508 | "%@ has another passphrase; open it first.": { | |
| 509 | "localizations": { | |
| 510 | "de": { | |
| 511 | "stringUnit": { | |
| 512 | "state": "translated", | |
| 513 | "value": "„%@“ hat ein anderes Passwort; öffne die Datei zuerst." | |
| 514 | } | |
| 515 | }, | |
| 516 | "es": { | |
| 517 | "stringUnit": { | |
| 518 | "state": "translated", | |
| 519 | "value": "«%@» tiene otra frase de contraseña; ábrelo primero." | |
| 520 | } | |
| 521 | }, | |
| 522 | "fr": { | |
| 523 | "stringUnit": { | |
| 524 | "state": "translated", | |
| 525 | "value": "« %@ » a une autre phrase secrète ; ouvrez-le d'abord." | |
| 526 | } | |
| 527 | }, | |
| 528 | "ja": { | |
| 529 | "stringUnit": { | |
| 530 | "state": "translated", | |
| 531 | "value": "“%@”のパスフレーズは異なります。先に開いてください。" | |
| 532 | } | |
| 533 | }, | |
| 534 | "pt-BR": { | |
| 535 | "stringUnit": { | |
| 536 | "state": "translated", | |
| 537 | "value": "\"%@\" tem outra senha; abra-o primeiro." | |
| 538 | } | |
| 539 | } | |
| 540 | } | |
| 541 | }, | |
| 542 | "%@ has decrypted entries that are encrypted on disk, so Emacs isn't given a copy of it.": { | |
| 543 | "localizations": { | |
| 544 | "de": { | |
| 545 | "stringUnit": { | |
| 546 | "state": "translated", | |
| 547 | "value": "„%@“ hat entschlüsselte Einträge, die auf dem Datenträger verschlüsselt sind, daher erhält Emacs keine Kopie davon." | |
| 548 | } | |
| 549 | }, | |
| 550 | "es": { | |
| 551 | "stringUnit": { | |
| 552 | "state": "translated", | |
| 553 | "value": "«%@» tiene entradas descifradas que están cifradas en el disco, así que Emacs no recibe una copia." | |
| 554 | } | |
| 555 | }, | |
| 556 | "fr": { | |
| 557 | "stringUnit": { | |
| 558 | "state": "translated", | |
| 559 | "value": "« %@ » contient des entrées déchiffrées qui sont chiffrées sur le disque, donc Emacs n'en reçoit pas de copie." | |
| 560 | } | |
| 561 | }, | |
| 562 | "ja": { | |
| 563 | "stringUnit": { | |
| 564 | "state": "translated", | |
| 565 | "value": "“%@”にはディスク上で暗号化されている復号済みエントリがあるため、Emacsにはコピーを渡しません。" | |
| 566 | } | |
| 567 | }, | |
| 568 | "pt-BR": { | |
| 569 | "stringUnit": { | |
| 570 | "state": "translated", | |
| 571 | "value": "\"%@\" tem entradas descriptografadas que estão criptografadas no disco, então o Emacs não recebe uma cópia." | |
| 572 | } | |
| 573 | } | |
| 574 | } | |
| 575 | }, | |
| 474 | 576 | "%@ in a buffer": { |
| 475 | 577 | "localizations": { |
| 476 | 578 | "de": { |
| @@ -505,6 +607,244 @@ | ||
| 505 | 607 | } |
| 506 | 608 | } |
| 507 | 609 | }, |
| 610 | "%@ is encrypted": { | |
| 611 | "localizations": { | |
| 612 | "de": { | |
| 613 | "stringUnit": { | |
| 614 | "state": "translated", | |
| 615 | "value": "„%@“ ist verschlüsselt" | |
| 616 | } | |
| 617 | }, | |
| 618 | "es": { | |
| 619 | "stringUnit": { | |
| 620 | "state": "translated", | |
| 621 | "value": "«%@» está cifrado" | |
| 622 | } | |
| 623 | }, | |
| 624 | "fr": { | |
| 625 | "stringUnit": { | |
| 626 | "state": "translated", | |
| 627 | "value": "« %@ » est chiffré" | |
| 628 | } | |
| 629 | }, | |
| 630 | "ja": { | |
| 631 | "stringUnit": { | |
| 632 | "state": "translated", | |
| 633 | "value": "“%@”は暗号化されています" | |
| 634 | } | |
| 635 | }, | |
| 636 | "pt-BR": { | |
| 637 | "stringUnit": { | |
| 638 | "state": "translated", | |
| 639 | "value": "\"%@\" está criptografado" | |
| 640 | } | |
| 641 | } | |
| 642 | } | |
| 643 | }, | |
| 644 | "%@ is encrypted, and %@ isn't; the entry wasn't moved.": { | |
| 645 | "localizations": { | |
| 646 | "de": { | |
| 647 | "stringUnit": { | |
| 648 | "state": "translated", | |
| 649 | "value": "„%1$@“ ist verschlüsselt, „%2$@“ nicht; der Eintrag wurde nicht verschoben." | |
| 650 | } | |
| 651 | }, | |
| 652 | "es": { | |
| 653 | "stringUnit": { | |
| 654 | "state": "translated", | |
| 655 | "value": "«%1$@» está cifrado y «%2$@» no; la entrada no se movió." | |
| 656 | } | |
| 657 | }, | |
| 658 | "fr": { | |
| 659 | "stringUnit": { | |
| 660 | "state": "translated", | |
| 661 | "value": "« %1$@ » est chiffré, « %2$@ » ne l'est pas ; l'entrée n'a pas été déplacée." | |
| 662 | } | |
| 663 | }, | |
| 664 | "ja": { | |
| 665 | "stringUnit": { | |
| 666 | "state": "translated", | |
| 667 | "value": "“%1$@”は暗号化されていますが“%2$@”はされていないため、エントリは移動しませんでした。" | |
| 668 | } | |
| 669 | }, | |
| 670 | "pt-BR": { | |
| 671 | "stringUnit": { | |
| 672 | "state": "translated", | |
| 673 | "value": "\"%1$@\" está criptografado e \"%2$@\" não; a entrada não foi movida." | |
| 674 | } | |
| 675 | } | |
| 676 | } | |
| 677 | }, | |
| 678 | "%@ is encrypted, so Emacs isn't given a copy of it.": { | |
| 679 | "localizations": { | |
| 680 | "de": { | |
| 681 | "stringUnit": { | |
| 682 | "state": "translated", | |
| 683 | "value": "„%@“ ist verschlüsselt, daher erhält Emacs keine Kopie davon." | |
| 684 | } | |
| 685 | }, | |
| 686 | "es": { | |
| 687 | "stringUnit": { | |
| 688 | "state": "translated", | |
| 689 | "value": "«%@» está cifrado, así que Emacs no recibe una copia." | |
| 690 | } | |
| 691 | }, | |
| 692 | "fr": { | |
| 693 | "stringUnit": { | |
| 694 | "state": "translated", | |
| 695 | "value": "« %@ » est chiffré, donc Emacs n'en reçoit pas de copie." | |
| 696 | } | |
| 697 | }, | |
| 698 | "ja": { | |
| 699 | "stringUnit": { | |
| 700 | "state": "translated", | |
| 701 | "value": "“%@”は暗号化されているため、Emacsにはコピーを渡しません。" | |
| 702 | } | |
| 703 | }, | |
| 704 | "pt-BR": { | |
| 705 | "stringUnit": { | |
| 706 | "state": "translated", | |
| 707 | "value": "\"%@\" está criptografado, então o Emacs não recebe uma cópia." | |
| 708 | } | |
| 709 | } | |
| 710 | } | |
| 711 | }, | |
| 712 | "%@ is encrypted.": { | |
| 713 | "localizations": { | |
| 714 | "de": { | |
| 715 | "stringUnit": { | |
| 716 | "state": "translated", | |
| 717 | "value": "„%@“ ist verschlüsselt." | |
| 718 | } | |
| 719 | }, | |
| 720 | "es": { | |
| 721 | "stringUnit": { | |
| 722 | "state": "translated", | |
| 723 | "value": "«%@» está cifrado." | |
| 724 | } | |
| 725 | }, | |
| 726 | "fr": { | |
| 727 | "stringUnit": { | |
| 728 | "state": "translated", | |
| 729 | "value": "« %@ » est chiffré." | |
| 730 | } | |
| 731 | }, | |
| 732 | "ja": { | |
| 733 | "stringUnit": { | |
| 734 | "state": "translated", | |
| 735 | "value": "“%@”は暗号化されています。" | |
| 736 | } | |
| 737 | }, | |
| 738 | "pt-BR": { | |
| 739 | "stringUnit": { | |
| 740 | "state": "translated", | |
| 741 | "value": "\"%@\" está criptografado." | |
| 742 | } | |
| 743 | } | |
| 744 | } | |
| 745 | }, | |
| 746 | "%@ is encrypted; its entries aren't shared.": { | |
| 747 | "localizations": { | |
| 748 | "de": { | |
| 749 | "stringUnit": { | |
| 750 | "state": "translated", | |
| 751 | "value": "„%@“ ist verschlüsselt; seine Einträge werden nicht geteilt." | |
| 752 | } | |
| 753 | }, | |
| 754 | "es": { | |
| 755 | "stringUnit": { | |
| 756 | "state": "translated", | |
| 757 | "value": "«%@» está cifrado; sus entradas no se comparten." | |
| 758 | } | |
| 759 | }, | |
| 760 | "fr": { | |
| 761 | "stringUnit": { | |
| 762 | "state": "translated", | |
| 763 | "value": "« %@ » est chiffré ; ses entrées ne sont pas partagées." | |
| 764 | } | |
| 765 | }, | |
| 766 | "ja": { | |
| 767 | "stringUnit": { | |
| 768 | "state": "translated", | |
| 769 | "value": "“%@”は暗号化されているため、エントリは共有されません。" | |
| 770 | } | |
| 771 | }, | |
| 772 | "pt-BR": { | |
| 773 | "stringUnit": { | |
| 774 | "state": "translated", | |
| 775 | "value": "\"%@\" está criptografado; suas entradas não são compartilhadas." | |
| 776 | } | |
| 777 | } | |
| 778 | } | |
| 779 | }, | |
| 780 | "%@ is saved encrypted with this passphrase.": { | |
| 781 | "localizations": { | |
| 782 | "de": { | |
| 783 | "stringUnit": { | |
| 784 | "state": "translated", | |
| 785 | "value": "„%@“ wird mit diesem Passwort verschlüsselt gesichert." | |
| 786 | } | |
| 787 | }, | |
| 788 | "es": { | |
| 789 | "stringUnit": { | |
| 790 | "state": "translated", | |
| 791 | "value": "«%@» se guarda cifrado con esta frase de contraseña." | |
| 792 | } | |
| 793 | }, | |
| 794 | "fr": { | |
| 795 | "stringUnit": { | |
| 796 | "state": "translated", | |
| 797 | "value": "« %@ » est enregistré chiffré avec cette phrase secrète." | |
| 798 | } | |
| 799 | }, | |
| 800 | "ja": { | |
| 801 | "stringUnit": { | |
| 802 | "state": "translated", | |
| 803 | "value": "“%@”はこのパスフレーズで暗号化して保存されます。" | |
| 804 | } | |
| 805 | }, | |
| 806 | "pt-BR": { | |
| 807 | "stringUnit": { | |
| 808 | "state": "translated", | |
| 809 | "value": "\"%@\" é salvo criptografado com esta senha." | |
| 810 | } | |
| 811 | } | |
| 812 | } | |
| 813 | }, | |
| 814 | "%@ is saved with its tagged entries encrypted.": { | |
| 815 | "localizations": { | |
| 816 | "de": { | |
| 817 | "stringUnit": { | |
| 818 | "state": "translated", | |
| 819 | "value": "„%@“ wird mit verschlüsselten markierten Einträgen gesichert." | |
| 820 | } | |
| 821 | }, | |
| 822 | "es": { | |
| 823 | "stringUnit": { | |
| 824 | "state": "translated", | |
| 825 | "value": "«%@» se guarda con sus entradas etiquetadas cifradas." | |
| 826 | } | |
| 827 | }, | |
| 828 | "fr": { | |
| 829 | "stringUnit": { | |
| 830 | "state": "translated", | |
| 831 | "value": "« %@ » est enregistré avec ses entrées taguées chiffrées." | |
| 832 | } | |
| 833 | }, | |
| 834 | "ja": { | |
| 835 | "stringUnit": { | |
| 836 | "state": "translated", | |
| 837 | "value": "“%@”はタグ付きエントリを暗号化して保存されます。" | |
| 838 | } | |
| 839 | }, | |
| 840 | "pt-BR": { | |
| 841 | "stringUnit": { | |
| 842 | "state": "translated", | |
| 843 | "value": "\"%@\" é salvo com as entradas etiquetadas criptografadas." | |
| 844 | } | |
| 845 | } | |
| 846 | } | |
| 847 | }, | |
| 508 | 848 | "%@ isn't available on iPhone and iPad. It runs on the Mac.": { |
| 509 | 849 | "comment": "A command that runs only on the Mac", |
| 510 | 850 | "localizations": { |
| @@ -610,6 +950,40 @@ | ||
| 610 | 950 | } |
| 611 | 951 | } |
| 612 | 952 | }, |
| 953 | "%@ isn't saved until it has a passphrase.": { | |
| 954 | "localizations": { | |
| 955 | "de": { | |
| 956 | "stringUnit": { | |
| 957 | "state": "translated", | |
| 958 | "value": "„%@“ wird erst gesichert, wenn es ein Passwort hat." | |
| 959 | } | |
| 960 | }, | |
| 961 | "es": { | |
| 962 | "stringUnit": { | |
| 963 | "state": "translated", | |
| 964 | "value": "«%@» no se guarda hasta que tenga una frase de contraseña." | |
| 965 | } | |
| 966 | }, | |
| 967 | "fr": { | |
| 968 | "stringUnit": { | |
| 969 | "state": "translated", | |
| 970 | "value": "« %@ » n'est pas enregistré tant qu'il n'a pas de phrase secrète." | |
| 971 | } | |
| 972 | }, | |
| 973 | "ja": { | |
| 974 | "stringUnit": { | |
| 975 | "state": "translated", | |
| 976 | "value": "パスフレーズが設定されるまで“%@”は保存されません。" | |
| 977 | } | |
| 978 | }, | |
| 979 | "pt-BR": { | |
| 980 | "stringUnit": { | |
| 981 | "state": "translated", | |
| 982 | "value": "\"%@\" só é salvo quando tiver uma senha." | |
| 983 | } | |
| 984 | } | |
| 985 | } | |
| 986 | }, | |
| 613 | 987 | "%@ late": { |
| 614 | 988 | "localizations": { |
| 615 | 989 | "de": { |
| @@ -2949,6 +3323,74 @@ | ||
| 2949 | 3323 | } |
| 2950 | 3324 | } |
| 2951 | 3325 | }, |
| 3326 | "%lld tagged entries aren't encrypted": { | |
| 3327 | "localizations": { | |
| 3328 | "de": { | |
| 3329 | "stringUnit": { | |
| 3330 | "state": "translated", | |
| 3331 | "value": "%lld markierte Einträge sind nicht verschlüsselt" | |
| 3332 | } | |
| 3333 | }, | |
| 3334 | "es": { | |
| 3335 | "stringUnit": { | |
| 3336 | "state": "translated", | |
| 3337 | "value": "%lld entradas etiquetadas no están cifradas" | |
| 3338 | } | |
| 3339 | }, | |
| 3340 | "fr": { | |
| 3341 | "stringUnit": { | |
| 3342 | "state": "translated", | |
| 3343 | "value": "%lld entrées taguées ne sont pas chiffrées" | |
| 3344 | } | |
| 3345 | }, | |
| 3346 | "ja": { | |
| 3347 | "stringUnit": { | |
| 3348 | "state": "translated", | |
| 3349 | "value": "%lld件のタグ付きエントリが暗号化されていません" | |
| 3350 | } | |
| 3351 | }, | |
| 3352 | "pt-BR": { | |
| 3353 | "stringUnit": { | |
| 3354 | "state": "translated", | |
| 3355 | "value": "%lld entradas etiquetadas não estão criptografadas" | |
| 3356 | } | |
| 3357 | } | |
| 3358 | } | |
| 3359 | }, | |
| 3360 | "%lld tagged entries aren't encrypted. Changes to %@ aren't saved until they are.": { | |
| 3361 | "localizations": { | |
| 3362 | "de": { | |
| 3363 | "stringUnit": { | |
| 3364 | "state": "translated", | |
| 3365 | "value": "%lld markierte Einträge sind nicht verschlüsselt. Änderungen an „%@“ werden erst gesichert, wenn sie es sind." | |
| 3366 | } | |
| 3367 | }, | |
| 3368 | "es": { | |
| 3369 | "stringUnit": { | |
| 3370 | "state": "translated", | |
| 3371 | "value": "%lld entradas etiquetadas no están cifradas. Los cambios en «%@» no se guardan hasta que lo estén." | |
| 3372 | } | |
| 3373 | }, | |
| 3374 | "fr": { | |
| 3375 | "stringUnit": { | |
| 3376 | "state": "translated", | |
| 3377 | "value": "%lld entrées taguées ne sont pas chiffrées. Les modifications de « %@ » ne sont pas enregistrées tant qu'elles ne le sont pas." | |
| 3378 | } | |
| 3379 | }, | |
| 3380 | "ja": { | |
| 3381 | "stringUnit": { | |
| 3382 | "state": "translated", | |
| 3383 | "value": "%lld件のタグ付きエントリが暗号化されていません。暗号化されるまで“%@”への変更は保存されません。" | |
| 3384 | } | |
| 3385 | }, | |
| 3386 | "pt-BR": { | |
| 3387 | "stringUnit": { | |
| 3388 | "state": "translated", | |
| 3389 | "value": "%lld entradas etiquetadas não estão criptografadas. As alterações em \"%@\" só são salvas quando elas estiverem." | |
| 3390 | } | |
| 3391 | } | |
| 3392 | } | |
| 3393 | }, | |
| 2952 | 3394 | "%lld words": { |
| 2953 | 3395 | "comment": "Modeline: words in the file", |
| 2954 | 3396 | "localizations": { |
| @@ -3246,6 +3688,74 @@ | ||
| 3246 | 3688 | } |
| 3247 | 3689 | } |
| 3248 | 3690 | }, |
| 3691 | "1 tagged entry isn't encrypted": { | |
| 3692 | "localizations": { | |
| 3693 | "de": { | |
| 3694 | "stringUnit": { | |
| 3695 | "state": "translated", | |
| 3696 | "value": "1 markierter Eintrag ist nicht verschlüsselt" | |
| 3697 | } | |
| 3698 | }, | |
| 3699 | "es": { | |
| 3700 | "stringUnit": { | |
| 3701 | "state": "translated", | |
| 3702 | "value": "1 entrada etiquetada no está cifrada" | |
| 3703 | } | |
| 3704 | }, | |
| 3705 | "fr": { | |
| 3706 | "stringUnit": { | |
| 3707 | "state": "translated", | |
| 3708 | "value": "1 entrée taguée n'est pas chiffrée" | |
| 3709 | } | |
| 3710 | }, | |
| 3711 | "ja": { | |
| 3712 | "stringUnit": { | |
| 3713 | "state": "translated", | |
| 3714 | "value": "1件のタグ付きエントリが暗号化されていません" | |
| 3715 | } | |
| 3716 | }, | |
| 3717 | "pt-BR": { | |
| 3718 | "stringUnit": { | |
| 3719 | "state": "translated", | |
| 3720 | "value": "1 entrada etiquetada não está criptografada" | |
| 3721 | } | |
| 3722 | } | |
| 3723 | } | |
| 3724 | }, | |
| 3725 | "1 tagged entry isn't encrypted. Changes to %@ aren't saved until it is.": { | |
| 3726 | "localizations": { | |
| 3727 | "de": { | |
| 3728 | "stringUnit": { | |
| 3729 | "state": "translated", | |
| 3730 | "value": "1 markierter Eintrag ist nicht verschlüsselt. Änderungen an „%@“ werden erst gesichert, wenn er es ist." | |
| 3731 | } | |
| 3732 | }, | |
| 3733 | "es": { | |
| 3734 | "stringUnit": { | |
| 3735 | "state": "translated", | |
| 3736 | "value": "1 entrada etiquetada no está cifrada. Los cambios en «%@» no se guardan hasta que lo esté." | |
| 3737 | } | |
| 3738 | }, | |
| 3739 | "fr": { | |
| 3740 | "stringUnit": { | |
| 3741 | "state": "translated", | |
| 3742 | "value": "1 entrée taguée n'est pas chiffrée. Les modifications de « %@ » ne sont pas enregistrées tant qu'elle ne l'est pas." | |
| 3743 | } | |
| 3744 | }, | |
| 3745 | "ja": { | |
| 3746 | "stringUnit": { | |
| 3747 | "state": "translated", | |
| 3748 | "value": "1件のタグ付きエントリが暗号化されていません。暗号化されるまで“%@”への変更は保存されません。" | |
| 3749 | } | |
| 3750 | }, | |
| 3751 | "pt-BR": { | |
| 3752 | "stringUnit": { | |
| 3753 | "state": "translated", | |
| 3754 | "value": "1 entrada etiquetada não está criptografada. As alterações em \"%@\" só são salvas quando ela estiver." | |
| 3755 | } | |
| 3756 | } | |
| 3757 | } | |
| 3758 | }, | |
| 3249 | 3759 | ":echo with a result that isn't text": { |
| 3250 | 3760 | "comment": "Why an sqlite block can't run here", |
| 3251 | 3761 | "localizations": { |
| @@ -8702,6 +9212,74 @@ | ||
| 8702 | 9212 | } |
| 8703 | 9213 | } |
| 8704 | 9214 | }, |
| 9215 | "Changes to %@ aren't saved": { | |
| 9216 | "localizations": { | |
| 9217 | "de": { | |
| 9218 | "stringUnit": { | |
| 9219 | "state": "translated", | |
| 9220 | "value": "Änderungen an „%@“ sind nicht gesichert" | |
| 9221 | } | |
| 9222 | }, | |
| 9223 | "es": { | |
| 9224 | "stringUnit": { | |
| 9225 | "state": "translated", | |
| 9226 | "value": "Los cambios en «%@» no están guardados" | |
| 9227 | } | |
| 9228 | }, | |
| 9229 | "fr": { | |
| 9230 | "stringUnit": { | |
| 9231 | "state": "translated", | |
| 9232 | "value": "Les modifications de « %@ » ne sont pas enregistrées" | |
| 9233 | } | |
| 9234 | }, | |
| 9235 | "ja": { | |
| 9236 | "stringUnit": { | |
| 9237 | "state": "translated", | |
| 9238 | "value": "“%@”への変更は保存されていません" | |
| 9239 | } | |
| 9240 | }, | |
| 9241 | "pt-BR": { | |
| 9242 | "stringUnit": { | |
| 9243 | "state": "translated", | |
| 9244 | "value": "As alterações em \"%@\" não estão salvas" | |
| 9245 | } | |
| 9246 | } | |
| 9247 | } | |
| 9248 | }, | |
| 9249 | "Changes to %@ aren't saved until that's fixed.": { | |
| 9250 | "localizations": { | |
| 9251 | "de": { | |
| 9252 | "stringUnit": { | |
| 9253 | "state": "translated", | |
| 9254 | "value": "Änderungen an „%@“ werden erst gesichert, wenn das behoben ist." | |
| 9255 | } | |
| 9256 | }, | |
| 9257 | "es": { | |
| 9258 | "stringUnit": { | |
| 9259 | "state": "translated", | |
| 9260 | "value": "Los cambios en «%@» no se guardan hasta que se corrija." | |
| 9261 | } | |
| 9262 | }, | |
| 9263 | "fr": { | |
| 9264 | "stringUnit": { | |
| 9265 | "state": "translated", | |
| 9266 | "value": "Les modifications de « %@ » ne sont pas enregistrées tant que ce n'est pas corrigé." | |
| 9267 | } | |
| 9268 | }, | |
| 9269 | "ja": { | |
| 9270 | "stringUnit": { | |
| 9271 | "state": "translated", | |
| 9272 | "value": "これが解決されるまで“%@”への変更は保存されません。" | |
| 9273 | } | |
| 9274 | }, | |
| 9275 | "pt-BR": { | |
| 9276 | "stringUnit": { | |
| 9277 | "state": "translated", | |
| 9278 | "value": "As alterações em \"%@\" só são salvas quando isso for corrigido." | |
| 9279 | } | |
| 9280 | } | |
| 9281 | } | |
| 9282 | }, | |
| 8705 | 9283 | "Check Spelling While Typing": { |
| 8706 | 9284 | "comment": "Command title", |
| 8707 | 9285 | "localizations": { |
| @@ -12051,6 +12629,41 @@ | ||
| 12051 | 12629 | } |
| 12052 | 12630 | } |
| 12053 | 12631 | }, |
| 12632 | "Couldn't Keep a Copy": { | |
| 12633 | "comment": "Error alert title", | |
| 12634 | "localizations": { | |
| 12635 | "de": { | |
| 12636 | "stringUnit": { | |
| 12637 | "state": "translated", | |
| 12638 | "value": "Kopie nicht behalten" | |
| 12639 | } | |
| 12640 | }, | |
| 12641 | "es": { | |
| 12642 | "stringUnit": { | |
| 12643 | "state": "translated", | |
| 12644 | "value": "No se pudo guardar una copia" | |
| 12645 | } | |
| 12646 | }, | |
| 12647 | "fr": { | |
| 12648 | "stringUnit": { | |
| 12649 | "state": "translated", | |
| 12650 | "value": "Impossible de garder une copie" | |
| 12651 | } | |
| 12652 | }, | |
| 12653 | "ja": { | |
| 12654 | "stringUnit": { | |
| 12655 | "state": "translated", | |
| 12656 | "value": "コピーを保持できません" | |
| 12657 | } | |
| 12658 | }, | |
| 12659 | "pt-BR": { | |
| 12660 | "stringUnit": { | |
| 12661 | "state": "translated", | |
| 12662 | "value": "Não Foi Possível Manter uma Cópia" | |
| 12663 | } | |
| 12664 | } | |
| 12665 | } | |
| 12666 | }, | |
| 12054 | 12667 | "Couldn't Merge": { |
| 12055 | 12668 | "comment": "Error alert title", |
| 12056 | 12669 | "localizations": { |
| @@ -13189,6 +13802,40 @@ | ||
| 13189 | 13802 | } |
| 13190 | 13803 | } |
| 13191 | 13804 | }, |
| 13805 | "Decrypt File": { | |
| 13806 | "localizations": { | |
| 13807 | "de": { | |
| 13808 | "stringUnit": { | |
| 13809 | "state": "translated", | |
| 13810 | "value": "Datei entschlüsseln" | |
| 13811 | } | |
| 13812 | }, | |
| 13813 | "es": { | |
| 13814 | "stringUnit": { | |
| 13815 | "state": "translated", | |
| 13816 | "value": "Descifrar archivo" | |
| 13817 | } | |
| 13818 | }, | |
| 13819 | "fr": { | |
| 13820 | "stringUnit": { | |
| 13821 | "state": "translated", | |
| 13822 | "value": "Déchiffrer le fichier" | |
| 13823 | } | |
| 13824 | }, | |
| 13825 | "ja": { | |
| 13826 | "stringUnit": { | |
| 13827 | "state": "translated", | |
| 13828 | "value": "ファイルを復号" | |
| 13829 | } | |
| 13830 | }, | |
| 13831 | "pt-BR": { | |
| 13832 | "stringUnit": { | |
| 13833 | "state": "translated", | |
| 13834 | "value": "Descriptografar Arquivo" | |
| 13835 | } | |
| 13836 | } | |
| 13837 | } | |
| 13838 | }, | |
| 13192 | 13839 | "Decrypt in File": { |
| 13193 | 13840 | "localizations": { |
| 13194 | 13841 | "de": { |
| @@ -13223,6 +13870,40 @@ | ||
| 13223 | 13870 | } |
| 13224 | 13871 | } |
| 13225 | 13872 | }, |
| 13873 | "Decrypt…": { | |
| 13874 | "localizations": { | |
| 13875 | "de": { | |
| 13876 | "stringUnit": { | |
| 13877 | "state": "translated", | |
| 13878 | "value": "Entschlüsseln …" | |
| 13879 | } | |
| 13880 | }, | |
| 13881 | "es": { | |
| 13882 | "stringUnit": { | |
| 13883 | "state": "translated", | |
| 13884 | "value": "Descifrar…" | |
| 13885 | } | |
| 13886 | }, | |
| 13887 | "fr": { | |
| 13888 | "stringUnit": { | |
| 13889 | "state": "translated", | |
| 13890 | "value": "Déchiffrer…" | |
| 13891 | } | |
| 13892 | }, | |
| 13893 | "ja": { | |
| 13894 | "stringUnit": { | |
| 13895 | "state": "translated", | |
| 13896 | "value": "復号…" | |
| 13897 | } | |
| 13898 | }, | |
| 13899 | "pt-BR": { | |
| 13900 | "stringUnit": { | |
| 13901 | "state": "translated", | |
| 13902 | "value": "Descriptografar…" | |
| 13903 | } | |
| 13904 | } | |
| 13905 | } | |
| 13906 | }, | |
| 13226 | 13907 | "Default": { |
| 13227 | 13908 | "localizations": { |
| 13228 | 13909 | "de": { |
| @@ -15053,6 +15734,40 @@ | ||
| 15053 | 15734 | } |
| 15054 | 15735 | } |
| 15055 | 15736 | }, |
| 15737 | "Edits to %@ weren't saved: they were waiting for a passphrase when orgstar was closed.": { | |
| 15738 | "localizations": { | |
| 15739 | "de": { | |
| 15740 | "stringUnit": { | |
| 15741 | "state": "translated", | |
| 15742 | "value": "Änderungen an %@ wurden nicht gesichert: Sie warteten auf ein Passwort, als orgstar beendet wurde." | |
| 15743 | } | |
| 15744 | }, | |
| 15745 | "es": { | |
| 15746 | "stringUnit": { | |
| 15747 | "state": "translated", | |
| 15748 | "value": "Los cambios en %@ no se guardaron: esperaban una frase de contraseña cuando orgstar se cerró." | |
| 15749 | } | |
| 15750 | }, | |
| 15751 | "fr": { | |
| 15752 | "stringUnit": { | |
| 15753 | "state": "translated", | |
| 15754 | "value": "Les modifications de %@ n'ont pas été enregistrées : elles attendaient une phrase secrète quand orgstar a été fermé." | |
| 15755 | } | |
| 15756 | }, | |
| 15757 | "ja": { | |
| 15758 | "stringUnit": { | |
| 15759 | "state": "translated", | |
| 15760 | "value": "%@への編集は保存されませんでした。orgstarが終了したとき、パスフレーズの入力を待っていました。" | |
| 15761 | } | |
| 15762 | }, | |
| 15763 | "pt-BR": { | |
| 15764 | "stringUnit": { | |
| 15765 | "state": "translated", | |
| 15766 | "value": "As alterações em %@ não foram salvas: aguardavam uma senha quando o orgstar foi fechado." | |
| 15767 | } | |
| 15768 | } | |
| 15769 | } | |
| 15770 | }, | |
| 15056 | 15771 | "Effort filter (<0:30, >1:00, =1:00):": { |
| 15057 | 15772 | "localizations": { |
| 15058 | 15773 | "de": { |
| @@ -15364,6 +16079,40 @@ | ||
| 15364 | 16079 | } |
| 15365 | 16080 | } |
| 15366 | 16081 | }, |
| 16082 | "Encrypt Tagged Entries": { | |
| 16083 | "localizations": { | |
| 16084 | "de": { | |
| 16085 | "stringUnit": { | |
| 16086 | "state": "translated", | |
| 16087 | "value": "Markierte Einträge verschlüsseln" | |
| 16088 | } | |
| 16089 | }, | |
| 16090 | "es": { | |
| 16091 | "stringUnit": { | |
| 16092 | "state": "translated", | |
| 16093 | "value": "Cifrar entradas etiquetadas" | |
| 16094 | } | |
| 16095 | }, | |
| 16096 | "fr": { | |
| 16097 | "stringUnit": { | |
| 16098 | "state": "translated", | |
| 16099 | "value": "Chiffrer les entrées taguées" | |
| 16100 | } | |
| 16101 | }, | |
| 16102 | "ja": { | |
| 16103 | "stringUnit": { | |
| 16104 | "state": "translated", | |
| 16105 | "value": "タグ付きエントリを暗号化" | |
| 16106 | } | |
| 16107 | }, | |
| 16108 | "pt-BR": { | |
| 16109 | "stringUnit": { | |
| 16110 | "state": "translated", | |
| 16111 | "value": "Criptografar Entradas Etiquetadas" | |
| 16112 | } | |
| 16113 | } | |
| 16114 | } | |
| 16115 | }, | |
| 15367 | 16116 | "Encrypt Tagged Entries…": { |
| 15368 | 16117 | "comment": "Command title", |
| 15369 | 16118 | "localizations": { |
| @@ -15399,6 +16148,40 @@ | ||
| 15399 | 16148 | } |
| 15400 | 16149 | } |
| 15401 | 16150 | }, |
| 16151 | "Encrypt and Save": { | |
| 16152 | "localizations": { | |
| 16153 | "de": { | |
| 16154 | "stringUnit": { | |
| 16155 | "state": "translated", | |
| 16156 | "value": "Verschlüsseln und sichern" | |
| 16157 | } | |
| 16158 | }, | |
| 16159 | "es": { | |
| 16160 | "stringUnit": { | |
| 16161 | "state": "translated", | |
| 16162 | "value": "Cifrar y guardar" | |
| 16163 | } | |
| 16164 | }, | |
| 16165 | "fr": { | |
| 16166 | "stringUnit": { | |
| 16167 | "state": "translated", | |
| 16168 | "value": "Chiffrer et enregistrer" | |
| 16169 | } | |
| 16170 | }, | |
| 16171 | "ja": { | |
| 16172 | "stringUnit": { | |
| 16173 | "state": "translated", | |
| 16174 | "value": "暗号化して保存" | |
| 16175 | } | |
| 16176 | }, | |
| 16177 | "pt-BR": { | |
| 16178 | "stringUnit": { | |
| 16179 | "state": "translated", | |
| 16180 | "value": "Criptografar e Salvar" | |
| 16181 | } | |
| 16182 | } | |
| 16183 | } | |
| 16184 | }, | |
| 15402 | 16185 | "Encrypted Entry": { |
| 15403 | 16186 | "localizations": { |
| 15404 | 16187 | "de": { |
| @@ -15433,6 +16216,74 @@ | ||
| 15433 | 16216 | } |
| 15434 | 16217 | } |
| 15435 | 16218 | }, |
| 16219 | "Encrypted entry": { | |
| 16220 | "localizations": { | |
| 16221 | "de": { | |
| 16222 | "stringUnit": { | |
| 16223 | "state": "translated", | |
| 16224 | "value": "Verschlüsselter Eintrag" | |
| 16225 | } | |
| 16226 | }, | |
| 16227 | "es": { | |
| 16228 | "stringUnit": { | |
| 16229 | "state": "translated", | |
| 16230 | "value": "Entrada cifrada" | |
| 16231 | } | |
| 16232 | }, | |
| 16233 | "fr": { | |
| 16234 | "stringUnit": { | |
| 16235 | "state": "translated", | |
| 16236 | "value": "Entrée chiffrée" | |
| 16237 | } | |
| 16238 | }, | |
| 16239 | "ja": { | |
| 16240 | "stringUnit": { | |
| 16241 | "state": "translated", | |
| 16242 | "value": "暗号化されたエントリ" | |
| 16243 | } | |
| 16244 | }, | |
| 16245 | "pt-BR": { | |
| 16246 | "stringUnit": { | |
| 16247 | "state": "translated", | |
| 16248 | "value": "Entrada criptografada" | |
| 16249 | } | |
| 16250 | } | |
| 16251 | } | |
| 16252 | }, | |
| 16253 | "Encrypted files were left out, and encrypted entries were exported as they are on disk.": { | |
| 16254 | "localizations": { | |
| 16255 | "de": { | |
| 16256 | "stringUnit": { | |
| 16257 | "state": "translated", | |
| 16258 | "value": "Verschlüsselte Dateien wurden ausgelassen, und verschlüsselte Einträge wurden so exportiert, wie sie auf dem Datenträger stehen." | |
| 16259 | } | |
| 16260 | }, | |
| 16261 | "es": { | |
| 16262 | "stringUnit": { | |
| 16263 | "state": "translated", | |
| 16264 | "value": "Se omitieron los archivos cifrados, y las entradas cifradas se exportaron tal como están en el disco." | |
| 16265 | } | |
| 16266 | }, | |
| 16267 | "fr": { | |
| 16268 | "stringUnit": { | |
| 16269 | "state": "translated", | |
| 16270 | "value": "Les fichiers chiffrés ont été omis, et les entrées chiffrées ont été exportées telles qu'elles sont sur le disque." | |
| 16271 | } | |
| 16272 | }, | |
| 16273 | "ja": { | |
| 16274 | "stringUnit": { | |
| 16275 | "state": "translated", | |
| 16276 | "value": "暗号化されたファイルは除外され、暗号化されたエントリはディスク上のまま書き出されました。" | |
| 16277 | } | |
| 16278 | }, | |
| 16279 | "pt-BR": { | |
| 16280 | "stringUnit": { | |
| 16281 | "state": "translated", | |
| 16282 | "value": "Arquivos criptografados foram deixados de fora, e entradas criptografadas foram exportadas como estão no disco." | |
| 16283 | } | |
| 16284 | } | |
| 16285 | } | |
| 16286 | }, | |
| 15436 | 16287 | "Encryption": { |
| 15437 | 16288 | "localizations": { |
| 15438 | 16289 | "de": { |
| @@ -15467,6 +16318,40 @@ | ||
| 15467 | 16318 | } |
| 15468 | 16319 | } |
| 15469 | 16320 | }, |
| 16321 | "Encrypt…": { | |
| 16322 | "localizations": { | |
| 16323 | "de": { | |
| 16324 | "stringUnit": { | |
| 16325 | "state": "translated", | |
| 16326 | "value": "Verschlüsseln …" | |
| 16327 | } | |
| 16328 | }, | |
| 16329 | "es": { | |
| 16330 | "stringUnit": { | |
| 16331 | "state": "translated", | |
| 16332 | "value": "Cifrar…" | |
| 16333 | } | |
| 16334 | }, | |
| 16335 | "fr": { | |
| 16336 | "stringUnit": { | |
| 16337 | "state": "translated", | |
| 16338 | "value": "Chiffrer…" | |
| 16339 | } | |
| 16340 | }, | |
| 16341 | "ja": { | |
| 16342 | "stringUnit": { | |
| 16343 | "state": "translated", | |
| 16344 | "value": "暗号化…" | |
| 16345 | } | |
| 16346 | }, | |
| 16347 | "pt-BR": { | |
| 16348 | "stringUnit": { | |
| 16349 | "state": "translated", | |
| 16350 | "value": "Criptografar…" | |
| 16351 | } | |
| 16352 | } | |
| 16353 | } | |
| 16354 | }, | |
| 15470 | 16355 | "End of Buffer": { |
| 15471 | 16356 | "comment": "Command title", |
| 15472 | 16357 | "localizations": { |
| @@ -15571,6 +16456,74 @@ | ||
| 15571 | 16456 | } |
| 15572 | 16457 | } |
| 15573 | 16458 | }, |
| 16459 | "Enter a passphrase.": { | |
| 16460 | "localizations": { | |
| 16461 | "de": { | |
| 16462 | "stringUnit": { | |
| 16463 | "state": "translated", | |
| 16464 | "value": "Gib ein Passwort ein." | |
| 16465 | } | |
| 16466 | }, | |
| 16467 | "es": { | |
| 16468 | "stringUnit": { | |
| 16469 | "state": "translated", | |
| 16470 | "value": "Introduce una frase de contraseña." | |
| 16471 | } | |
| 16472 | }, | |
| 16473 | "fr": { | |
| 16474 | "stringUnit": { | |
| 16475 | "state": "translated", | |
| 16476 | "value": "Saisissez une phrase secrète." | |
| 16477 | } | |
| 16478 | }, | |
| 16479 | "ja": { | |
| 16480 | "stringUnit": { | |
| 16481 | "state": "translated", | |
| 16482 | "value": "パスフレーズを入力してください。" | |
| 16483 | } | |
| 16484 | }, | |
| 16485 | "pt-BR": { | |
| 16486 | "stringUnit": { | |
| 16487 | "state": "translated", | |
| 16488 | "value": "Digite uma senha." | |
| 16489 | } | |
| 16490 | } | |
| 16491 | } | |
| 16492 | }, | |
| 16493 | "Enter the passphrase to encrypt and save them, or leave without saving.": { | |
| 16494 | "localizations": { | |
| 16495 | "de": { | |
| 16496 | "stringUnit": { | |
| 16497 | "state": "translated", | |
| 16498 | "value": "Gib das Passwort ein, um sie zu verschlüsseln und zu sichern, oder verlasse die Datei ohne Sichern." | |
| 16499 | } | |
| 16500 | }, | |
| 16501 | "es": { | |
| 16502 | "stringUnit": { | |
| 16503 | "state": "translated", | |
| 16504 | "value": "Introduce la frase de contraseña para cifrarlos y guardarlos, o sal sin guardar." | |
| 16505 | } | |
| 16506 | }, | |
| 16507 | "fr": { | |
| 16508 | "stringUnit": { | |
| 16509 | "state": "translated", | |
| 16510 | "value": "Saisissez la phrase secrète pour les chiffrer et les enregistrer, ou quittez sans enregistrer." | |
| 16511 | } | |
| 16512 | }, | |
| 16513 | "ja": { | |
| 16514 | "stringUnit": { | |
| 16515 | "state": "translated", | |
| 16516 | "value": "パスフレーズを入力して暗号化して保存するか、保存せずに閉じてください。" | |
| 16517 | } | |
| 16518 | }, | |
| 16519 | "pt-BR": { | |
| 16520 | "stringUnit": { | |
| 16521 | "state": "translated", | |
| 16522 | "value": "Digite a senha para criptografá-las e salvá-las, ou saia sem salvar." | |
| 16523 | } | |
| 16524 | } | |
| 16525 | } | |
| 16526 | }, | |
| 15574 | 16527 | "Entries can't be done before their TODO children": { |
| 15575 | 16528 | "localizations": { |
| 15576 | 16529 | "de": { |
| @@ -18771,6 +19724,40 @@ | ||
| 18771 | 19724 | } |
| 18772 | 19725 | } |
| 18773 | 19726 | }, |
| 19727 | "Give the passphrase with Encrypt… first, so that a copy of your edits can be kept encrypted.": { | |
| 19728 | "localizations": { | |
| 19729 | "de": { | |
| 19730 | "stringUnit": { | |
| 19731 | "state": "translated", | |
| 19732 | "value": "Gib zuerst mit „Verschlüsseln …“ das Passwort ein, damit eine Kopie deiner Änderungen verschlüsselt behalten werden kann." | |
| 19733 | } | |
| 19734 | }, | |
| 19735 | "es": { | |
| 19736 | "stringUnit": { | |
| 19737 | "state": "translated", | |
| 19738 | "value": "Introduce primero la frase de contraseña con Cifrar… para que se pueda guardar cifrada una copia de tus cambios." | |
| 19739 | } | |
| 19740 | }, | |
| 19741 | "fr": { | |
| 19742 | "stringUnit": { | |
| 19743 | "state": "translated", | |
| 19744 | "value": "Saisissez d'abord la phrase secrète avec Chiffrer… pour qu'une copie de vos modifications puisse être gardée chiffrée." | |
| 19745 | } | |
| 19746 | }, | |
| 19747 | "ja": { | |
| 19748 | "stringUnit": { | |
| 19749 | "state": "translated", | |
| 19750 | "value": "編集内容のコピーを暗号化して保持できるよう、まず「暗号化…」でパスフレーズを入力してください。" | |
| 19751 | } | |
| 19752 | }, | |
| 19753 | "pt-BR": { | |
| 19754 | "stringUnit": { | |
| 19755 | "state": "translated", | |
| 19756 | "value": "Informe primeiro a senha em Criptografar… para que uma cópia das suas alterações possa ser mantida criptografada." | |
| 19757 | } | |
| 19758 | } | |
| 19759 | } | |
| 19760 | }, | |
| 18774 | 19761 | "Go": { |
| 18775 | 19762 | "comment": "The iPad menu bar's Go menu", |
| 18776 | 19763 | "localizations": { |
| @@ -36643,6 +37630,40 @@ | ||
| 36643 | 37630 | } |
| 36644 | 37631 | } |
| 36645 | 37632 | }, |
| 37633 | "Saved encrypted": { | |
| 37634 | "localizations": { | |
| 37635 | "de": { | |
| 37636 | "stringUnit": { | |
| 37637 | "state": "translated", | |
| 37638 | "value": "Verschlüsselt gesichert" | |
| 37639 | } | |
| 37640 | }, | |
| 37641 | "es": { | |
| 37642 | "stringUnit": { | |
| 37643 | "state": "translated", | |
| 37644 | "value": "Guardado cifrado" | |
| 37645 | } | |
| 37646 | }, | |
| 37647 | "fr": { | |
| 37648 | "stringUnit": { | |
| 37649 | "state": "translated", | |
| 37650 | "value": "Enregistré chiffré" | |
| 37651 | } | |
| 37652 | }, | |
| 37653 | "ja": { | |
| 37654 | "stringUnit": { | |
| 37655 | "state": "translated", | |
| 37656 | "value": "暗号化して保存しました" | |
| 37657 | } | |
| 37658 | }, | |
| 37659 | "pt-BR": { | |
| 37660 | "stringUnit": { | |
| 37661 | "state": "translated", | |
| 37662 | "value": "Salvo criptografado" | |
| 37663 | } | |
| 37664 | } | |
| 37665 | } | |
| 37666 | }, | |
| 36646 | 37667 | "Save…": { |
| 36647 | 37668 | "localizations": { |
| 36648 | 37669 | "de": { |
| @@ -37780,6 +38801,74 @@ | ||
| 37780 | 38801 | } |
| 37781 | 38802 | } |
| 37782 | 38803 | }, |
| 38804 | "Set Passphrase": { | |
| 38805 | "localizations": { | |
| 38806 | "de": { | |
| 38807 | "stringUnit": { | |
| 38808 | "state": "translated", | |
| 38809 | "value": "Passwort festlegen" | |
| 38810 | } | |
| 38811 | }, | |
| 38812 | "es": { | |
| 38813 | "stringUnit": { | |
| 38814 | "state": "translated", | |
| 38815 | "value": "Definir frase de contraseña" | |
| 38816 | } | |
| 38817 | }, | |
| 38818 | "fr": { | |
| 38819 | "stringUnit": { | |
| 38820 | "state": "translated", | |
| 38821 | "value": "Définir la phrase secrète" | |
| 38822 | } | |
| 38823 | }, | |
| 38824 | "ja": { | |
| 38825 | "stringUnit": { | |
| 38826 | "state": "translated", | |
| 38827 | "value": "パスフレーズを設定" | |
| 38828 | } | |
| 38829 | }, | |
| 38830 | "pt-BR": { | |
| 38831 | "stringUnit": { | |
| 38832 | "state": "translated", | |
| 38833 | "value": "Definir Senha" | |
| 38834 | } | |
| 38835 | } | |
| 38836 | } | |
| 38837 | }, | |
| 38838 | "Set Passphrase…": { | |
| 38839 | "localizations": { | |
| 38840 | "de": { | |
| 38841 | "stringUnit": { | |
| 38842 | "state": "translated", | |
| 38843 | "value": "Passwort festlegen …" | |
| 38844 | } | |
| 38845 | }, | |
| 38846 | "es": { | |
| 38847 | "stringUnit": { | |
| 38848 | "state": "translated", | |
| 38849 | "value": "Definir frase de contraseña…" | |
| 38850 | } | |
| 38851 | }, | |
| 38852 | "fr": { | |
| 38853 | "stringUnit": { | |
| 38854 | "state": "translated", | |
| 38855 | "value": "Définir la phrase secrète…" | |
| 38856 | } | |
| 38857 | }, | |
| 38858 | "ja": { | |
| 38859 | "stringUnit": { | |
| 38860 | "state": "translated", | |
| 38861 | "value": "パスフレーズを設定…" | |
| 38862 | } | |
| 38863 | }, | |
| 38864 | "pt-BR": { | |
| 38865 | "stringUnit": { | |
| 38866 | "state": "translated", | |
| 38867 | "value": "Definir Senha…" | |
| 38868 | } | |
| 38869 | } | |
| 38870 | } | |
| 38871 | }, | |
| 37783 | 38872 | "Set Priority A": { |
| 37784 | 38873 | "comment": "Command title", |
| 37785 | 38874 | "localizations": { |
| @@ -42261,6 +43350,74 @@ | ||
| 42261 | 43350 | } |
| 42262 | 43351 | } |
| 42263 | 43352 | }, |
| 43353 | "Tagged entries encrypted and saved": { | |
| 43354 | "localizations": { | |
| 43355 | "de": { | |
| 43356 | "stringUnit": { | |
| 43357 | "state": "translated", | |
| 43358 | "value": "Markierte Einträge verschlüsselt und gesichert" | |
| 43359 | } | |
| 43360 | }, | |
| 43361 | "es": { | |
| 43362 | "stringUnit": { | |
| 43363 | "state": "translated", | |
| 43364 | "value": "Entradas etiquetadas cifradas y guardadas" | |
| 43365 | } | |
| 43366 | }, | |
| 43367 | "fr": { | |
| 43368 | "stringUnit": { | |
| 43369 | "state": "translated", | |
| 43370 | "value": "Entrées taguées chiffrées et enregistrées" | |
| 43371 | } | |
| 43372 | }, | |
| 43373 | "ja": { | |
| 43374 | "stringUnit": { | |
| 43375 | "state": "translated", | |
| 43376 | "value": "タグ付きエントリを暗号化して保存しました" | |
| 43377 | } | |
| 43378 | }, | |
| 43379 | "pt-BR": { | |
| 43380 | "stringUnit": { | |
| 43381 | "state": "translated", | |
| 43382 | "value": "Entradas etiquetadas criptografadas e salvas" | |
| 43383 | } | |
| 43384 | } | |
| 43385 | } | |
| 43386 | }, | |
| 43387 | "Tagged entries in the subtree aren't encrypted; give the passphrase with Encrypt… first.": { | |
| 43388 | "localizations": { | |
| 43389 | "de": { | |
| 43390 | "stringUnit": { | |
| 43391 | "state": "translated", | |
| 43392 | "value": "Markierte Einträge im Teilbaum sind nicht verschlüsselt; gib zuerst mit „Verschlüsseln …“ das Passwort ein." | |
| 43393 | } | |
| 43394 | }, | |
| 43395 | "es": { | |
| 43396 | "stringUnit": { | |
| 43397 | "state": "translated", | |
| 43398 | "value": "Hay entradas etiquetadas sin cifrar en el subárbol; introduce primero la frase de contraseña con Cifrar…." | |
| 43399 | } | |
| 43400 | }, | |
| 43401 | "fr": { | |
| 43402 | "stringUnit": { | |
| 43403 | "state": "translated", | |
| 43404 | "value": "Des entrées taguées du sous-arbre ne sont pas chiffrées ; saisissez d'abord la phrase secrète avec Chiffrer…." | |
| 43405 | } | |
| 43406 | }, | |
| 43407 | "ja": { | |
| 43408 | "stringUnit": { | |
| 43409 | "state": "translated", | |
| 43410 | "value": "サブツリー内のタグ付きエントリが暗号化されていません。まず「暗号化…」でパスフレーズを入力してください。" | |
| 43411 | } | |
| 43412 | }, | |
| 43413 | "pt-BR": { | |
| 43414 | "stringUnit": { | |
| 43415 | "state": "translated", | |
| 43416 | "value": "Há entradas etiquetadas não criptografadas na subárvore; informe primeiro a senha em Criptografar…." | |
| 43417 | } | |
| 43418 | } | |
| 43419 | } | |
| 43420 | }, | |
| 42264 | 43421 | "Tags": { |
| 42265 | 43422 | "comment": "Key bar button", |
| 42266 | 43423 | "localizations": { |
| @@ -43354,6 +44511,74 @@ | ||
| 43354 | 44511 | } |
| 43355 | 44512 | } |
| 43356 | 44513 | }, |
| 44514 | "The file has no passphrase yet": { | |
| 44515 | "localizations": { | |
| 44516 | "de": { | |
| 44517 | "stringUnit": { | |
| 44518 | "state": "translated", | |
| 44519 | "value": "Die Datei hat noch kein Passwort" | |
| 44520 | } | |
| 44521 | }, | |
| 44522 | "es": { | |
| 44523 | "stringUnit": { | |
| 44524 | "state": "translated", | |
| 44525 | "value": "El archivo aún no tiene frase de contraseña" | |
| 44526 | } | |
| 44527 | }, | |
| 44528 | "fr": { | |
| 44529 | "stringUnit": { | |
| 44530 | "state": "translated", | |
| 44531 | "value": "Le fichier n'a pas encore de phrase secrète" | |
| 44532 | } | |
| 44533 | }, | |
| 44534 | "ja": { | |
| 44535 | "stringUnit": { | |
| 44536 | "state": "translated", | |
| 44537 | "value": "このファイルにはまだパスフレーズがありません" | |
| 44538 | } | |
| 44539 | }, | |
| 44540 | "pt-BR": { | |
| 44541 | "stringUnit": { | |
| 44542 | "state": "translated", | |
| 44543 | "value": "O arquivo ainda não tem senha" | |
| 44544 | } | |
| 44545 | } | |
| 44546 | } | |
| 44547 | }, | |
| 44548 | "The file is encrypted, and its passphrase isn't known": { | |
| 44549 | "localizations": { | |
| 44550 | "de": { | |
| 44551 | "stringUnit": { | |
| 44552 | "state": "translated", | |
| 44553 | "value": "Die Datei ist verschlüsselt, und ihr Passwort ist nicht bekannt" | |
| 44554 | } | |
| 44555 | }, | |
| 44556 | "es": { | |
| 44557 | "stringUnit": { | |
| 44558 | "state": "translated", | |
| 44559 | "value": "El archivo está cifrado y no se conoce su frase de contraseña" | |
| 44560 | } | |
| 44561 | }, | |
| 44562 | "fr": { | |
| 44563 | "stringUnit": { | |
| 44564 | "state": "translated", | |
| 44565 | "value": "Le fichier est chiffré et sa phrase secrète n'est pas connue" | |
| 44566 | } | |
| 44567 | }, | |
| 44568 | "ja": { | |
| 44569 | "stringUnit": { | |
| 44570 | "state": "translated", | |
| 44571 | "value": "このファイルは暗号化されていて、パスフレーズが不明です" | |
| 44572 | } | |
| 44573 | }, | |
| 44574 | "pt-BR": { | |
| 44575 | "stringUnit": { | |
| 44576 | "state": "translated", | |
| 44577 | "value": "O arquivo está criptografado e sua senha não é conhecida" | |
| 44578 | } | |
| 44579 | } | |
| 44580 | } | |
| 44581 | }, | |
| 43357 | 44582 | "The folder and its files stay on disk.": { |
| 43358 | 44583 | "localizations": { |
| 43359 | 44584 | "de": { |
| @@ -43661,6 +44886,74 @@ | ||
| 43661 | 44886 | } |
| 43662 | 44887 | } |
| 43663 | 44888 | }, |
| 44889 | "The passphrase wasn't remembered: the Keychain refused it.": { | |
| 44890 | "localizations": { | |
| 44891 | "de": { | |
| 44892 | "stringUnit": { | |
| 44893 | "state": "translated", | |
| 44894 | "value": "Das Passwort wurde nicht gemerkt: Der Schlüsselbund hat es abgelehnt." | |
| 44895 | } | |
| 44896 | }, | |
| 44897 | "es": { | |
| 44898 | "stringUnit": { | |
| 44899 | "state": "translated", | |
| 44900 | "value": "No se recordó la frase de contraseña: el llavero la rechazó." | |
| 44901 | } | |
| 44902 | }, | |
| 44903 | "fr": { | |
| 44904 | "stringUnit": { | |
| 44905 | "state": "translated", | |
| 44906 | "value": "La phrase secrète n'a pas été mémorisée : le trousseau l'a refusée." | |
| 44907 | } | |
| 44908 | }, | |
| 44909 | "ja": { | |
| 44910 | "stringUnit": { | |
| 44911 | "state": "translated", | |
| 44912 | "value": "パスフレーズは保存されませんでした。キーチェーンが拒否しました。" | |
| 44913 | } | |
| 44914 | }, | |
| 44915 | "pt-BR": { | |
| 44916 | "stringUnit": { | |
| 44917 | "state": "translated", | |
| 44918 | "value": "A senha não foi lembrada: as Chaves a recusaram." | |
| 44919 | } | |
| 44920 | } | |
| 44921 | } | |
| 44922 | }, | |
| 44923 | "The passphrases differ": { | |
| 44924 | "localizations": { | |
| 44925 | "de": { | |
| 44926 | "stringUnit": { | |
| 44927 | "state": "translated", | |
| 44928 | "value": "Die Passwörter stimmen nicht überein" | |
| 44929 | } | |
| 44930 | }, | |
| 44931 | "es": { | |
| 44932 | "stringUnit": { | |
| 44933 | "state": "translated", | |
| 44934 | "value": "Las frases de contraseña no coinciden" | |
| 44935 | } | |
| 44936 | }, | |
| 44937 | "fr": { | |
| 44938 | "stringUnit": { | |
| 44939 | "state": "translated", | |
| 44940 | "value": "Les phrases secrètes diffèrent" | |
| 44941 | } | |
| 44942 | }, | |
| 44943 | "ja": { | |
| 44944 | "stringUnit": { | |
| 44945 | "state": "translated", | |
| 44946 | "value": "パスフレーズが一致しません" | |
| 44947 | } | |
| 44948 | }, | |
| 44949 | "pt-BR": { | |
| 44950 | "stringUnit": { | |
| 44951 | "state": "translated", | |
| 44952 | "value": "As senhas não coincidem" | |
| 44953 | } | |
| 44954 | } | |
| 44955 | } | |
| 44956 | }, | |
| 43664 | 44957 | "The purchase didn't go through. %@": { |
| 43665 | 44958 | "localizations": { |
| 43666 | 44959 | "de": { |
| @@ -44211,6 +45504,40 @@ | ||
| 44211 | 45504 | } |
| 44212 | 45505 | } |
| 44213 | 45506 | }, |
| 45507 | "This heading is inside an encrypted entry, so it isn't moved on its own; move the encrypted entry.": { | |
| 45508 | "localizations": { | |
| 45509 | "de": { | |
| 45510 | "stringUnit": { | |
| 45511 | "state": "translated", | |
| 45512 | "value": "Diese Überschrift liegt in einem verschlüsselten Eintrag und wird daher nicht einzeln verschoben; verschiebe den verschlüsselten Eintrag." | |
| 45513 | } | |
| 45514 | }, | |
| 45515 | "es": { | |
| 45516 | "stringUnit": { | |
| 45517 | "state": "translated", | |
| 45518 | "value": "Este encabezado está dentro de una entrada cifrada, así que no se mueve por separado; mueve la entrada cifrada." | |
| 45519 | } | |
| 45520 | }, | |
| 45521 | "fr": { | |
| 45522 | "stringUnit": { | |
| 45523 | "state": "translated", | |
| 45524 | "value": "Ce titre est dans une entrée chiffrée, il n'est donc pas déplacé seul ; déplacez l'entrée chiffrée." | |
| 45525 | } | |
| 45526 | }, | |
| 45527 | "ja": { | |
| 45528 | "stringUnit": { | |
| 45529 | "state": "translated", | |
| 45530 | "value": "この見出しは暗号化されたエントリの中にあるため、単独では移動しません。暗号化されたエントリを移動してください。" | |
| 45531 | } | |
| 45532 | }, | |
| 45533 | "pt-BR": { | |
| 45534 | "stringUnit": { | |
| 45535 | "state": "translated", | |
| 45536 | "value": "Este título está dentro de uma entrada criptografada, então não é movido sozinho; mova a entrada criptografada." | |
| 45537 | } | |
| 45538 | } | |
| 45539 | } | |
| 45540 | }, | |
| 44214 | 45541 | "This is the only pane.": { |
| 44215 | 45542 | "comment": "Close Pane with one pane", |
| 44216 | 45543 | "localizations": { |
| @@ -44456,6 +45783,40 @@ | ||
| 44456 | 45783 | } |
| 44457 | 45784 | } |
| 44458 | 45785 | }, |
| 45786 | "This version of orgstar keeps remembered passphrases in your login keychain without limiting them to this Mac; Touch ID or your password is still asked before one is used.": { | |
| 45787 | "localizations": { | |
| 45788 | "de": { | |
| 45789 | "stringUnit": { | |
| 45790 | "state": "translated", | |
| 45791 | "value": "Diese Version von orgstar bewahrt gemerkte Passwörter im Anmeldeschlüsselbund auf, ohne sie auf diesen Mac zu beschränken; Touch ID oder dein Passwort wird trotzdem abgefragt, bevor eines verwendet wird." | |
| 45792 | } | |
| 45793 | }, | |
| 45794 | "es": { | |
| 45795 | "stringUnit": { | |
| 45796 | "state": "translated", | |
| 45797 | "value": "Esta versión de orgstar guarda las frases de contraseña recordadas en tu llavero de inicio de sesión sin limitarlas a este Mac; aun así se pide Touch ID o tu contraseña antes de usar una." | |
| 45798 | } | |
| 45799 | }, | |
| 45800 | "fr": { | |
| 45801 | "stringUnit": { | |
| 45802 | "state": "translated", | |
| 45803 | "value": "Cette version d'orgstar garde les phrases secrètes mémorisées dans votre trousseau de session sans les limiter à ce Mac ; Touch ID ou votre mot de passe est quand même demandé avant d'en utiliser une." | |
| 45804 | } | |
| 45805 | }, | |
| 45806 | "ja": { | |
| 45807 | "stringUnit": { | |
| 45808 | "state": "translated", | |
| 45809 | "value": "このバージョンのorgstarは、保存したパスフレーズをこのMacに限定せずログインキーチェーンに保持します。使用する前にTouch IDまたはパスワードを求めます。" | |
| 45810 | } | |
| 45811 | }, | |
| 45812 | "pt-BR": { | |
| 45813 | "stringUnit": { | |
| 45814 | "state": "translated", | |
| 45815 | "value": "Esta versão do orgstar guarda as senhas lembradas nas suas chaves de início de sessão sem limitá-las a este Mac; o Touch ID ou sua senha ainda são pedidos antes de usar uma." | |
| 45816 | } | |
| 45817 | } | |
| 45818 | } | |
| 45819 | }, | |
| 44459 | 45820 | "This view can't be saved from here; write it in views.toml.": { |
| 44460 | 45821 | "localizations": { |
| 44461 | 45822 | "de": { |
| @@ -47210,6 +48571,40 @@ | ||
| 47210 | 48571 | } |
| 47211 | 48572 | } |
| 47212 | 48573 | }, |
| 48574 | "Wrong passphrase": { | |
| 48575 | "localizations": { | |
| 48576 | "de": { | |
| 48577 | "stringUnit": { | |
| 48578 | "state": "translated", | |
| 48579 | "value": "Falsches Passwort" | |
| 48580 | } | |
| 48581 | }, | |
| 48582 | "es": { | |
| 48583 | "stringUnit": { | |
| 48584 | "state": "translated", | |
| 48585 | "value": "Frase de contraseña incorrecta" | |
| 48586 | } | |
| 48587 | }, | |
| 48588 | "fr": { | |
| 48589 | "stringUnit": { | |
| 48590 | "state": "translated", | |
| 48591 | "value": "Phrase secrète incorrecte" | |
| 48592 | } | |
| 48593 | }, | |
| 48594 | "ja": { | |
| 48595 | "stringUnit": { | |
| 48596 | "state": "translated", | |
| 48597 | "value": "パスフレーズが違います" | |
| 48598 | } | |
| 48599 | }, | |
| 48600 | "pt-BR": { | |
| 48601 | "stringUnit": { | |
| 48602 | "state": "translated", | |
| 48603 | "value": "Senha incorreta" | |
| 48604 | } | |
| 48605 | } | |
| 48606 | } | |
| 48607 | }, | |
| 47213 | 48608 | "Yank": { |
| 47214 | 48609 | "comment": "Command title", |
| 47215 | 48610 | "localizations": { |