Commit 9954efcbf4
Verified · cmc
Changed files (11)
- Sources/OrgApp/ClockModel.swift +1 −1
- Sources/OrgApp/CryptPassphrases.swift +17 −8
- Sources/OrgApp/CryptSheet.swift +3
- Sources/OrgApp/DocumentSession.swift +18 −2
- Sources/OrgApp/SubtreeShare.swift +41 −23
- Sources/OrgCore/Commands/ClockHistory.swift +12 −8
- Sources/OrgDocument/Saving.swift +2 −1
- Tests/OrgAppTests/CryptReviewTests.swift +77 −7
- Tests/OrgDocumentTests/CryptSaverTests.swift +2 −1
- docs/manual/guide/04-outlines.org +4 −4
- l10n/Localizable.xcstrings +68
Sources/OrgApp/ClockModel.swift +1 −1 · view
| @@ -314,7 +314,7 @@ public final class ClockModel { | |||
| 314 | 314 | ||
| 315 | /// `task` with a placeholder title when its heading is encrypted on disk. | 315 | /// `task` with a placeholder title when its heading is encrypted on disk. |
| 316 | static func shareable(_ task: ClockTask, _ session: DocumentSession) -> ClockTask { | 316 | static func shareable(_ task: ClockTask, _ session: DocumentSession) -> ClockTask { |
| 317 | guard task.titleHidden != true, let heading = text(task.path, session).flatMap(task.locate) else { return task } | 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) | 318 | let shown = session.shareableTitle(task.title, path: task.path, heading: heading) |
| 319 | return shown == task.title ? task : task.hiding(shown) | 319 | return shown == task.title ? task : task.hiding(shown) |
| 320 | } | 320 | } |
Sources/OrgApp/CryptPassphrases.swift +17 −8 · view
| @@ -13,8 +13,20 @@ public enum CryptPassphrases { | |||
| 13 | nonisolated static let service = "sh.krz.orgstar.crypt.v2" | 13 | nonisolated static let service = "sh.krz.orgstar.crypt.v2" |
| 14 | /// Where earlier versions kept passphrases, readable without authentication. | 14 | /// Where earlier versions kept passphrases, readable without authentication. |
| 15 | nonisolated static let legacyService = "sh.krz.orgstar.crypt" | 15 | nonisolated static let legacyService = "sh.krz.orgstar.crypt" |
| 16 | /// Set once the person was told this build keeps passphrases the old way. | 16 | /// Whether this build can keep passphrases limited to this device: the Developer ID Mac app |
| 17 | static let toldLegacyKey = "cryptKeychainLegacyTold" | 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 | } | ||
| 18 | 30 | ||
| 19 | /// A Keychain query handed to the thread that waits on it; nothing else uses it meanwhile. | 31 | /// A Keychain query handed to the thread that waits on it; nothing else uses it meanwhile. |
| 20 | struct Request: @unchecked Sendable { | 32 | struct Request: @unchecked Sendable { |
| @@ -62,10 +74,9 @@ public enum CryptPassphrases { | |||
| 62 | return status | 74 | return status |
| 63 | } | 75 | } |
| 64 | 76 | ||
| 65 | /// Remembers `passphrase` for `path`. A message to show when it wasn't kept, or (once) when | 77 | /// Remembers `passphrase` for `path`. A message to show when it wasn't kept; nil otherwise. |
| 66 | /// this build keeps it without device-only protection; nil otherwise. | ||
| 67 | @discardableResult | 78 | @discardableResult |
| 68 | public static func store(_ passphrase: String, for path: String, defaults: UserDefaults = .standard) -> String? { | 79 | public static func store(_ passphrase: String, for path: String) -> String? { |
| 69 | guard let item = newItem(passphrase, for: path) else { return String(localized: "The passphrase wasn't remembered: the Keychain refused it.") } | 80 | guard let item = newItem(passphrase, for: path) else { return String(localized: "The passphrase wasn't remembered: the Keychain refused it.") } |
| 70 | let status = add(item, replacing: query(path)) | 81 | let status = add(item, replacing: query(path)) |
| 71 | if status == errSecSuccess { | 82 | if status == errSecSuccess { |
| @@ -80,9 +91,7 @@ public enum CryptPassphrases { | |||
| 80 | return String(localized: "The passphrase wasn't remembered: the Keychain refused it.") | 91 | return String(localized: "The passphrase wasn't remembered: the Keychain refused it.") |
| 81 | } | 92 | } |
| 82 | SecItemDelete(query(path) as CFDictionary) | 93 | SecItemDelete(query(path) as CFDictionary) |
| 83 | guard !defaults.bool(forKey: toldLegacyKey) else { return nil } | 94 | return nil |
| 84 | defaults.set(true, forKey: toldLegacyKey) | ||
| 85 | return 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.") | ||
| 86 | } | 95 | } |
| 87 | 96 | ||
| 88 | public static func forget(_ path: String) { | 97 | public static func forget(_ path: String) { |
Sources/OrgApp/CryptSheet.swift +3 · view
| @@ -102,6 +102,9 @@ public struct CryptSheet: View { | |||
| 102 | SecureField("Passphrase", text: $passphrase).onSubmit(submit) | 102 | SecureField("Passphrase", text: $passphrase).onSubmit(submit) |
| 103 | if asksTwice { SecureField("Repeat passphrase", text: $repeated).onSubmit(submit) } | 103 | if asksTwice { SecureField("Repeat passphrase", text: $repeated).onSubmit(submit) } |
| 104 | Toggle("Remember in the Keychain", isOn: $remember) | 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 | } | ||
| 105 | if let problem { Text(problem).foregroundStyle(.red).font(.callout) } | 108 | if let problem { Text(problem).foregroundStyle(.red).font(.callout) } |
| 106 | HStack { | 109 | HStack { |
| 107 | Spacer() | 110 | Spacer() |
Sources/OrgApp/DocumentSession.swift +18 −2 · view
| @@ -242,6 +242,7 @@ public final class DocumentSession { | |||
| 242 | 242 | ||
| 243 | /// The encrypted file waiting for its passphrase stays closed. | 243 | /// The encrypted file waiting for its passphrase stays closed. |
| 244 | public func cancelUnlock() { | 244 | public func cancelUnlock() { |
| 245 | if let unlockRequest { CryptPassphrases.endSession(for: unlockRequest) } | ||
| 245 | unlockRequest = nil | 246 | unlockRequest = nil |
| 246 | unlockPane = nil | 247 | unlockPane = nil |
| 247 | } | 248 | } |
| @@ -666,8 +667,11 @@ public final class DocumentSession { | |||
| 666 | case .conflict: | 667 | case .conflict: |
| 667 | entry.conflict = "\(name) changed on disk, and the changes conflict with yours." | 668 | entry.conflict = "\(name) changed on disk, and the changes conflict with yours." |
| 668 | case .overwroteExternalChange(let change), .changedAfterWrite(let change): | 669 | case .overwroteExternalChange(let change), .changedAfterWrite(let change): |
| 669 | if case .conflict = change { | 670 | if case .conflict(let conflicts) = change { |
| 670 | entry.conflict = "\(name) changed on disk while saving, and the changes conflict with yours." | 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." | ||
| 671 | } | 675 | } |
| 672 | } | 676 | } |
| 673 | } catch let hold as CryptHold { | 677 | } catch let hold as CryptHold { |
| @@ -690,6 +694,13 @@ public final class DocumentSession { | |||
| 690 | do { | 694 | do { |
| 691 | try buffer.update { try saver.overwrite(&$0, to: url) } | 695 | try buffer.update { try saver.overwrite(&$0, to: url) } |
| 692 | current?.conflict = nil | 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 | } | ||
| 693 | } catch { | 704 | } catch { |
| 694 | showError(String(localized: "Couldn't Save File", comment: "Error alert title"), "Can't save \(name): \(error.localizedDescription)") | 705 | showError(String(localized: "Couldn't Save File", comment: "Error alert title"), "Can't save \(name): \(error.localizedDescription)") |
| 695 | } | 706 | } |
| @@ -1026,6 +1037,11 @@ public final class DocumentSession { | |||
| 1026 | } | 1037 | } |
| 1027 | } | 1038 | } |
| 1028 | guard crypt.sealsEntries(for: path), let heading = OrgCrypt.heading(context.text, at: context.selection.first?.lowerBound ?? 0) else { return .ready } | 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 | } | ||
| 1029 | let end = OrgCrypt.bodyRange(context.text, at: heading)?.upperBound ?? heading | 1045 | let end = OrgCrypt.bodyRange(context.text, at: heading)?.upperBound ?? heading |
| 1030 | let subtree = heading..<max(heading + 1, end) | 1046 | let subtree = heading..<max(heading + 1, end) |
| 1031 | guard !OrgCrypt.unencrypted(context.text, tag: cryptTag, within: subtree).isEmpty else { return .ready } | 1047 | guard !OrgCrypt.unencrypted(context.text, tag: cryptTag, within: subtree).isEmpty else { return .ready } |
Sources/OrgApp/SubtreeShare.swift +41 −23 · view
| @@ -62,38 +62,56 @@ public struct SubtreeShare: Sendable, Identifiable { | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | extension DocumentSession { | 64 | extension DocumentSession { |
| 65 | /// Share Subtree… for the entry at `offset` in the open file at `path`, its tagged entries | 65 | /// Share Subtree… for the entry at `offset` in the open file at `path`, as it is on disk: |
| 66 | /// encrypted as they are on disk. Nil when there's no entry there, or `refusesSubtreeShare`. | 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`. | ||
| 67 | public func subtreeShare(_ path: String, at offset: Int) -> SubtreeShare? { | 69 | public func subtreeShare(_ path: String, at offset: Int) -> SubtreeShare? { |
| 68 | guard refusesSubtreeShare(path, at: offset) == nil, var text = document(of: path)?.text else { return nil } | 70 | guard case .success(let source) = shareSource(path, at: offset) else { return nil } |
| 69 | var offset = offset | 71 | return SubtreeShare(text: source.text, at: source.offset, path: path, settings: defaults) |
| 70 | if let (sealed, heading) = sealedSubtree(path, text: text, at: offset) { | ||
| 71 | text = sealed | ||
| 72 | offset = heading | ||
| 73 | } | ||
| 74 | return SubtreeShare(text: text, at: offset, path: path, settings: defaults) | ||
| 75 | } | 72 | } |
| 76 | 73 | ||
| 77 | /// Why the entry at `offset` in `path` isn't shared: its file is encrypted, or it has tagged | 74 | /// Why the entry at `offset` in `path` isn't shared: its file is encrypted, or what's |
| 78 | /// entries the file encrypts on disk and their passphrase isn't known. | 75 | /// encrypted on disk can't be encrypted in the copy (no passphrase, or one that fails). |
| 79 | public func refusesSubtreeShare(_ path: String, at offset: Int) -> String? { | 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> { | ||
| 80 | let name = (path as NSString).lastPathComponent | 87 | let name = (path as NSString).lastPathComponent |
| 81 | if Self.isEncryptedFile(path) { return String(localized: "\(name) is encrypted; its entries aren't shared.") } | 88 | if Self.isEncryptedFile(path) { return .failure(ShareRefusal(message: String(localized: "\(name) is encrypted; its entries aren't shared."))) } |
| 82 | guard let text = document(of: path)?.text, crypt.sealsEntries(for: path), crypt.passphrase(for: path) == nil, | 89 | guard let text = document(of: path)?.text else { return .success((text: "", offset: offset)) } |
| 83 | let range = subtreeRange(text, at: offset), !OrgCrypt.unencrypted(text, tag: cryptTag, within: range).isEmpty else { return nil } | 90 | guard crypt.sealsEntries(for: path), let heading = OrgCrypt.heading(text, at: offset), let range = subtreeRange(text, at: offset) else { |
| 84 | return String(localized: "Tagged entries in the subtree aren't encrypted; give the passphrase with Encrypt… first.") | 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 | } | ||
| 85 | } | 111 | } |
| 86 | 112 | ||
| 87 | private func subtreeRange(_ text: String, at offset: Int) -> Range<Int>? { | 113 | private func subtreeRange(_ text: String, at offset: Int) -> Range<Int>? { |
| 88 | guard let heading = OrgCrypt.heading(text, at: offset) else { return nil } | 114 | guard let heading = OrgCrypt.heading(text, at: offset) else { return nil } |
| 89 | return heading..<max(heading + 1, OrgCrypt.bodyRange(text, at: heading)?.upperBound ?? heading) | 115 | return heading..<max(heading + 1, OrgCrypt.bodyRange(text, at: heading)?.upperBound ?? heading) |
| 90 | } | 116 | } |
| 91 | |||
| 92 | /// `text` with the subtree's tagged entries encrypted, and where its heading starts. | ||
| 93 | private func sealedSubtree(_ path: String, text: String, at offset: Int) -> (String, Int)? { | ||
| 94 | guard crypt.sealsEntries(for: path), let passphrase = crypt.passphrase(for: path), let range = subtreeRange(text, at: offset), | ||
| 95 | !OrgCrypt.unencrypted(text, tag: cryptTag, within: range).isEmpty, | ||
| 96 | let sealed = try? OrgCrypt.seal(text, passphrase: passphrase, tag: cryptTag, within: range).text else { return nil } | ||
| 97 | return (sealed, range.lowerBound) | ||
| 98 | } | ||
| 99 | } | 117 | } |
Sources/OrgCore/Commands/ClockHistory.swift +12 −8 · view
| @@ -12,16 +12,16 @@ public struct ClockTask: Codable, Equatable, Hashable, Sendable { | |||
| 12 | /// The heading's index among the file's headings. | 12 | /// The heading's index among the file's headings. |
| 13 | public let ordinal: Int | 13 | public let ordinal: Int |
| 14 | public let id: String? | 14 | public let id: String? |
| 15 | /// The title is a placeholder for one that isn't kept (an encrypted heading's): the task | 15 | /// For a task whose title is a placeholder for one that isn't kept (an encrypted |
| 16 | /// is found by its ID or position. | 16 | /// heading's): a checksum of the real title, which finds it with its ID or position. |
| 17 | public let titleHidden: Bool? | 17 | public let titleHash: String? |
| 18 | 18 | ||
| 19 | public init(path: String, title: String, ordinal: Int, id: String?, titleHidden: Bool? = nil) { | 19 | public init(path: String, title: String, ordinal: Int, id: String?, titleHash: String? = nil) { |
| 20 | self.path = path | 20 | self.path = path |
| 21 | self.title = title | 21 | self.title = title |
| 22 | self.ordinal = ordinal | 22 | self.ordinal = ordinal |
| 23 | self.id = id | 23 | self.id = id |
| 24 | self.titleHidden = titleHidden | 24 | self.titleHash = titleHash |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | /// The entry containing `offset`; nil before the first heading. | 27 | /// The entry containing `offset`; nil before the first heading. |
| @@ -36,7 +36,11 @@ public struct ClockTask: Codable, Equatable, Hashable, Sendable { | |||
| 36 | /// and title, or by title; a task kept without its title by position alone. | 36 | /// and title, or by title; a task kept without its title by position alone. |
| 37 | public func index(in model: DocumentModel) -> Int? { | 37 | public func index(in model: DocumentModel) -> Int? { |
| 38 | if let id, let index = model.headings.firstIndex(where: { $0.id == id }) { return index } | 38 | if let id, let index = model.headings.firstIndex(where: { $0.id == id }) { return index } |
| 39 | if titleHidden == true { return ordinal < model.headings.count ? ordinal : nil } | 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 | } | ||
| 40 | if ordinal < model.headings.count, model.headings[ordinal].title == title { return ordinal } | 44 | if ordinal < model.headings.count, model.headings[ordinal].title == title { return ordinal } |
| 41 | return model.headings.firstIndex { $0.title == title } | 45 | return model.headings.firstIndex { $0.title == title } |
| 42 | } | 46 | } |
| @@ -52,13 +56,13 @@ public struct ClockTask: Codable, Equatable, Hashable, Sendable { | |||
| 52 | let model = DocumentModel(tree: OrgParser.parse(text)) | 56 | let model = DocumentModel(tree: OrgParser.parse(text)) |
| 53 | guard let index = index(in: model) else { return nil } | 57 | guard let index = index(in: model) else { return nil } |
| 54 | return ClockTask(path: path, title: model.headings[index].title, ordinal: index, id: model.headings[index].id) | 58 | return ClockTask(path: path, title: model.headings[index].title, ordinal: index, id: model.headings[index].id) |
| 55 | .hiding(titleHidden == true ? title : nil) | 59 | .hiding(titleHash == nil ? nil : title) |
| 56 | } | 60 | } |
| 57 | 61 | ||
| 58 | /// The task with `placeholder` for its title, or as it is with nil. | 62 | /// The task with `placeholder` for its title, or as it is with nil. |
| 59 | public func hiding(_ placeholder: String?) -> ClockTask { | 63 | public func hiding(_ placeholder: String?) -> ClockTask { |
| 60 | guard let placeholder else { return self } | 64 | guard let placeholder else { return self } |
| 61 | return ClockTask(path: path, title: placeholder, ordinal: ordinal, id: id, titleHidden: true) | 65 | return ClockTask(path: path, title: placeholder, ordinal: ordinal, id: id, titleHash: titleHash ?? OrgCrypt.checksum(title)) |
| 62 | } | 66 | } |
| 63 | } | 67 | } |
| 64 | 68 | ||
Sources/OrgDocument/Saving.swift +2 −1 · view
| @@ -117,7 +117,8 @@ public struct Saver: Sendable { | |||
| 117 | let both = mergeWithMarkers(base: SourceText(bytes: base).text, ours: state.text, theirs: theirs, oursLabel: "yours", theirsLabel: "disk") | 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) | 118 | let edits = lineEdits(from: state.text, to: both) |
| 119 | guard (try? state.apply(edits, baseRevision: state.revision)) != nil else { return change } | 119 | guard (try? state.apply(edits, baseRevision: state.revision)) != nil else { return change } |
| 120 | return .merged(edits) | 120 | // A conflict with none listed: both versions are in the buffer between markers. |
| 121 | return .conflict([]) | ||
| 121 | } | 122 | } |
| 122 | } | 123 | } |
| 123 | } | 124 | } |
Tests/OrgAppTests/CryptReviewTests.swift +77 −7 · view
| @@ -84,18 +84,88 @@ struct CryptReviewTests { | |||
| 84 | 84 | ||
| 85 | // 3a | 85 | // 3a |
| 86 | @Test func archivingAChildOfATaggedEntryEncryptsItFirst() throws { | 86 | @Test func archivingAChildOfATaggedEntryEncryptsItFirst() throws { |
| 87 | let text = "* Parent :crypt:\nparent text\n** Child\nchild secret\n* Last\n" | 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) | 88 | try notes.write("a.org", text) |
| 89 | session.open(file.path) | 89 | session.open(file.path) |
| 90 | let child = (text as NSString).range(of: "** Child").location | 90 | let child = (text as NSString).range(of: "** SECRETTITLE").location |
| 91 | let archive = notes.url.appendingPathComponent("a.org_archive") | 91 | let archive = notes.url.appendingPathComponent("a.org_archive") |
| 92 | #expect(session.archive(from: (file.path, child))?.contains("Encrypt…") == true) | 92 | // A heading inside an encrypted entry isn't moved on its own, passphrase or not. |
| 93 | #expect(!FileManager.default.fileExists(atPath: archive.path)) | 93 | #expect(session.archive(from: (file.path, child))?.contains("inside an encrypted entry") == true) |
| 94 | session.cryptUsed("pw", for: file.path) | 94 | session.cryptUsed("pw", for: file.path) |
| 95 | #expect(session.archive(from: (file.path, child)) == "Archived to a.org_archive") | 95 | #expect(session.archive(from: (file.path, child))?.contains("inside an encrypted entry") == true) |
| 96 | #expect(!read(archive).contains("child secret") && read(archive).contains("-----BEGIN PGP MESSAGE-----")) | 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-----")) | ||
| 97 | #expect(session.save()) | 103 | #expect(session.save()) |
| 98 | #expect(!disk.contains("child secret") && !disk.contains("parent text")) | 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) | ||
| 99 | } | 169 | } |
| 100 | 170 | ||
| 101 | // 3b | 171 | // 3b |
Tests/OrgDocumentTests/CryptSaverTests.swift +2 −1 · view
| @@ -30,7 +30,8 @@ struct CryptSaverTests { | |||
| 30 | files.beforeReplace = Array("Z\nb\nc\n* Theirs :crypt:\ntheir secret\n".utf8) | 30 | files.beforeReplace = Array("Z\nb\nc\n* Theirs :crypt:\ntheir secret\n".utf8) |
| 31 | let recovery = MemoryRecovery() | 31 | let recovery = MemoryRecovery() |
| 32 | var doc = try editedState() | 32 | var doc = try editedState() |
| 33 | _ = try saver(files, recovery).0.save(&doc, to: url) | 33 | let outcome = try saver(files, recovery).0.save(&doc, to: url) |
| 34 | #expect(outcome == .overwroteExternalChange(.conflict([]))) | ||
| 34 | #expect(doc.text.contains("their secret") && doc.text.contains("Z") && doc.text.contains("A")) | 35 | #expect(doc.text.contains("their secret") && doc.text.contains("Z") && doc.text.contains("A")) |
| 35 | #expect(recovery.kept.allSatisfy { !$0.text.contains("their secret") }) | 36 | #expect(recovery.kept.allSatisfy { !$0.text.contains("their secret") }) |
| 36 | } | 37 | } |
docs/manual/guide/04-outlines.org +4 −4 · view
| @@ -967,11 +967,11 @@ With =org-crypt-use-before-save-magic = true= in =config.toml=, every save, the | |||
| 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. | 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. | 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. | 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 that has the tag, its own or inherited, to another file encrypts it in place first, since the tag it inherits doesn't go with it; without the passphrase it isn't moved. | 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, between conflict markers if it conflicts, when no copy of it can be kept. | 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. | 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. | 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, not at all. | 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 | 975 | ||
| 976 | * Encrypted files | 976 | * Encrypted files |
| 977 | 977 | ||
| @@ -984,7 +984,7 @@ The decrypted text is kept in memory only: | |||
| 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. | 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. | 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. | 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 the first time. | 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 | 988 | ||
| 989 | =age= files (=.age=) aren't supported. | 989 | =age= files (=.age=) aren't supported. |
| 990 | 990 | ||
l10n/Localizable.xcstrings +68 · 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 | "%@ doesn't contain %@.": { | 467 | "%@ doesn't contain %@.": { |
| 434 | "comment": "Alert when the folder chosen to grant access doesn't contain the one needed", | 468 | "comment": "Alert when the folder chosen to grant access doesn't contain the one needed", |
| 435 | "localizations": { | 469 | "localizations": { |
| @@ -45470,6 +45504,40 @@ | |||
| 45470 | } | 45504 | } |
| 45471 | } | 45505 | } |
| 45472 | }, | 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 | }, | ||
| 45473 | "This is the only pane.": { | 45541 | "This is the only pane.": { |
| 45474 | "comment": "Close Pane with one pane", | 45542 | "comment": "Close Pane with one pane", |
| 45475 | "localizations": { | 45543 | "localizations": { |