Commit 52d620b11e

52d620b11ecb28c3cd78962df6e07dbbe747bda1

parent: 251e90e5c9

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-26 16:10 UTC

Save only passphrases that open the file; late answers change nothing

A typed passphrase is saved only when it opens every passphrase-encrypted
message in the file's text, so Encrypt beside an entry under another
passphrase, or an unlock that opened only the first message, keeps the saved
item. The "encrypted already" path saves nothing. answer(enable:) changes the
setting only while it is undecided. Turning off deletes by service. The shared
instance has no Keychain in a test process. The sheet's keep and answer logic
moved into CryptPassphrases.typed and answer(enable:passphrase:for:text:).

Ref #239

Layout: unified · split

Changed files (6)
Sources/OrgApp/CryptPassphrases.swift +61 −10 · view
@@ -1,6 +1,7 @@
11import CryptoKit
22import Foundation
33import LocalAuthentication
4import OrgCore
45import OrgDocument
56import Security
67
@@ -14,6 +15,8 @@ public protocol PassphraseKeychain: AnyObject {
1415 /// Saves `passphrase` for `path`. A message to show when it wasn't kept; nil otherwise.
1516 func write(_ passphrase: String, for path: String) -> String?
1617 func delete(_ path: String)
18 /// Deletes every saved passphrase, whatever the listing finds.
19 func deleteAll()
1720 /// The paths passphrases are saved for, without asking for authentication.
1821 func paths() -> [String]
1922}
@@ -26,7 +29,8 @@ public protocol PassphraseKeychain: AnyObject {
2629@MainActor
2730@Observable
2831public final class CryptPassphrases {
29 public static let shared = CryptPassphrases()
32 /// The app's passphrases. A test process, which has XCTest loaded, gets no Keychain.
33 public static let shared = CryptPassphrases(keychain: NSClassFromString("XCTestCase") != nil ? NoKeychain() : SystemKeychain())
3034
3135 /// "Use Face ID to Decrypt", kept in user defaults on this device, not in `config.toml`.
3236 public enum Setting: String, Sendable {
@@ -38,7 +42,7 @@ public final class CryptPassphrases {
3842 /// Where earlier versions kept passphrases, readable without authentication.
3943 nonisolated static let legacyService = "sh.krz.orgstar.crypt"
4044
41 @ObservationIgnored private let keychain: PassphraseKeychain
45 @ObservationIgnored let keychain: PassphraseKeychain
4246 @ObservationIgnored private let defaults: UserDefaults
4347 public private(set) var setting: Setting
4448 /// The question waits to be asked at launch: passphrases saved by an earlier version.
@@ -115,10 +119,36 @@ public final class CryptPassphrases {
115119 /// Whether a typed passphrase waits for the question before it can be saved.
116120 public var asksFirst: Bool { setting == .undecided }
117121
118 /// The answer to the question: Enable turns the setting on, Not Now off.
119 public func answer(enable: Bool) {
120 set(enable ? .on : .off)
122 /// The answer to the question: Enable turns the setting on, Not Now off. Nothing changes when
123 /// the setting was decided meanwhile (another window's question, or Settings).
124 @discardableResult
125 public func answer(enable: Bool) -> Bool {
121126 asking = false
127 guard setting == .undecided else { return false }
128 set(enable ? .on : .off)
129 return true
130 }
131
132 /// A passphrase typed for `path` worked, and the file's text is now `text`: saved while the
133 /// setting is on, with the Keychain's message in `note`. True when the question must be
134 /// answered first, with `answer(enable:passphrase:for:text:)`.
135 public func typed(_ passphrase: String, for path: String, text: String, note: inout String?) -> Bool {
136 if asksFirst { return true }
137 note = keep(passphrase, for: path, text: text)
138 return false
139 }
140
141 /// The answer to the question asked for a typed passphrase: the passphrase is saved when the
142 /// answer turned the setting on. The Keychain's message; nil otherwise.
143 public func answer(enable: Bool, passphrase: String, for path: String, text: String) -> String? {
144 guard answer(enable: enable) else { return nil }
145 return keep(passphrase, for: path, text: text)
146 }
147
148 /// Whether `passphrase` opens every message in `text` encrypted with a passphrase, so that
149 /// saving it can't replace the one the file's other entries need.
150 nonisolated static func opensAll(_ text: String, with passphrase: String) -> Bool {
151 OrgCrypt.messages(text).allSatisfy { OrgCrypt.opens($0, passphrase: passphrase) }
122152 }
123153
124154 /// Turns the setting on from Settings.
@@ -130,7 +160,9 @@ public final class CryptPassphrases {
130160 /// there are any.
131161 public func turnOff() {
132162 set(.off)
133 for path in keychain.paths() { forget(path) }
163 let paths = keychain.paths()
164 keychain.deleteAll()
165 for path in paths { endSession(for: path) }
134166 refresh()
135167 }
136168
@@ -163,11 +195,12 @@ public final class CryptPassphrases {
163195 contexts.removeValue(forKey: path)?.invalidate()
164196 }
165197
166 /// A passphrase typed for `path` that opened or encrypted it: saved while the setting is on.
167 /// A message to show when it wasn't kept; nil otherwise.
198 /// A passphrase typed for `path` that opened or encrypted it, whose text is now `text`: saved
199 /// while the setting is on and it opens every message in `text`. A message to show when it
200 /// wasn't kept; nil otherwise.
168201 @discardableResult
169 public func keep(_ passphrase: String, for path: String) -> String? {
170 guard setting == .on else { return nil }
202 public func keep(_ passphrase: String, for path: String, text: String) -> String? {
203 guard setting == .on, Self.opensAll(text, with: passphrase) else { return nil }
171204 let note = keychain.write(passphrase, for: path)
172205 refresh()
173206 return note
@@ -254,6 +287,13 @@ public final class SystemKeychain: PassphraseKeychain {
254287 SecItemDelete(Self.query(path, service: CryptPassphrases.legacyService) as CFDictionary)
255288 }
256289
290 public func deleteAll() {
291 for service in [CryptPassphrases.service, CryptPassphrases.legacyService] {
292 // The file-based keychain may delete one match per call.
293 for _ in 0..<1000 where SecItemDelete(Self.query(nil, service: service) as CFDictionary) == errSecSuccess {}
294 }
295 }
296
257297 /// `query` for attributes only, without asking for authentication.
258298 nonisolated static func quiet(_ query: [String: Any]) -> [String: Any] {
259299 var q = query
@@ -317,6 +357,17 @@ public final class SystemKeychain: PassphraseKeychain {
317357 }
318358}
319359
360/// No Keychain: nothing is saved or found. For test processes.
361@MainActor
362final class NoKeychain: PassphraseKeychain {
363 func contains(_ path: String) -> Bool { false }
364 func read(_ path: String, context: LAContext) async -> String? { nil }
365 func write(_ passphrase: String, for path: String) -> String? { nil }
366 func delete(_ path: String) {}
367 func deleteAll() {}
368 func paths() -> [String] { [] }
369}
370
320371/// The key clock history hashes encrypted headings' titles with, made once and kept in the
321372/// Keychain, on this device only, without asking for authentication.
322373public enum ClockTitleKey {
Sources/OrgApp/CryptSheet.swift +25 −21 · view
@@ -68,9 +68,9 @@ public struct CryptSheet: View {
6868 @State private var repeated = ""
6969 /// What the Keychain said when the passphrase was saved, shown with the result.
7070 @State private var keychainNote: String?
71 /// A typed passphrase that worked, waiting for the answer to whether to use Face ID, and
72 /// what follows.
73 @State private var question: (passphrase: String, then: () -> Void)?
71 /// A typed passphrase that worked, the file's text with it, waiting for the answer to
72 /// whether to use Face ID, and what follows.
73 @State private var question: (passphrase: String, text: String, then: () -> Void)?
7474 @State private var problem: String?
7575 /// The decrypted entry being edited, and the passphrase it came with.
7676 @State private var editing: (original: String, passphrase: String)?
@@ -132,23 +132,25 @@ public struct CryptSheet: View {
132132
133133 private var passphrases: CryptPassphrases { session?.passphrases ?? .shared }
134134
135 /// A typed passphrase worked: saved while the setting is on, after the question while it's
136 /// undecided, then `then`.
137 private func keep(_ passphrase: String, remembered: Bool, then: @escaping () -> Void) {
138 guard !remembered else { return then() }
139 if passphrases.asksFirst { return question = (passphrase, then) }
140 keychainNote = passphrases.keep(passphrase, for: request.path)
135 /// A typed passphrase worked, and the file's text is now `text`: saved while the setting is
136 /// on, after the question while it's undecided, then `then`. A nil `text` (nothing was
137 /// checked) saves nothing.
138 private func keep(_ passphrase: String, remembered: Bool, text: String?, then: @escaping () -> Void) {
139 guard !remembered, let text else { return then() }
140 if passphrases.typed(passphrase, for: request.path, text: text, note: &keychainNote) { return question = (passphrase, text, then) }
141141 then()
142142 }
143143
144144 private func answer(enable: Bool) {
145145 guard let question else { return }
146146 self.question = nil
147 passphrases.answer(enable: enable)
148 keychainNote = passphrases.keep(question.passphrase, for: request.path)
147 keychainNote = passphrases.answer(enable: enable, passphrase: question.passphrase, for: request.path, text: question.text)
149148 question.then()
150149 }
151150
151 /// The open file's text, after a passphrase opened or saved it.
152 private var unlockedText: String { session?.document(of: request.path)?.text ?? "" }
153
152154 private var title: String {
153155 switch request.mode {
154156 case .encrypt: "Encrypt Entry"
@@ -195,9 +197,9 @@ public struct CryptSheet: View {
195197 if request.unlocks {
196198 if let failure = session?.unlock(passphrase, for: request.path) { return problem = failure }
197199 switch request.mode {
198 case .encryptOnSave: return finish(String(localized: "Tagged entries encrypted and saved"), passphrase: passphrase, remembered: remembered)
199 case .newFile: return finish(String(localized: "Saved encrypted"), passphrase: passphrase, remembered: remembered)
200 default: return finish(nil, passphrase: passphrase, remembered: remembered)
200 case .encryptOnSave: return finish(String(localized: "Tagged entries encrypted and saved"), passphrase: passphrase, remembered: remembered, text: unlockedText)
201 case .newFile: return finish(String(localized: "Saved encrypted"), passphrase: passphrase, remembered: remembered, text: unlockedText)
202 default: return finish(nil, passphrase: passphrase, remembered: remembered, text: unlockedText)
201203 }
202204 }
203205 let current = text()
@@ -205,21 +207,21 @@ public struct CryptSheet: View {
205207 switch request.mode {
206208 case .encrypt:
207209 guard let encrypted = try OrgCrypt.encrypt(current, at: request.offset, passphrase: passphrase) else {
208 return finish("The entry is encrypted already", passphrase: passphrase, remembered: remembered)
210 return finish("The entry is encrypted already", passphrase: passphrase, remembered: remembered, text: nil)
209211 }
210212 apply(encrypted)
211 finish("Entry encrypted", passphrase: passphrase, remembered: remembered)
213 finish("Entry encrypted", passphrase: passphrase, remembered: remembered, text: encrypted)
212214 case .encryptAll(let tag):
213215 let (encrypted, count) = try OrgCrypt.encryptAll(current, passphrase: passphrase, tag: tag)
214216 if count > 0 { apply(encrypted) }
215 finish("Encrypted \(count) \(count == 1 ? "entry" : "entries")", passphrase: passphrase, remembered: remembered)
217 finish("Encrypted \(count) \(count == 1 ? "entry" : "entries")", passphrase: passphrase, remembered: remembered, text: count > 0 ? encrypted : nil)
216218 case .open:
217219 let plain = try OrgCrypt.decrypt(current, at: request.offset, passphrase: passphrase).plaintext
218220 session?.cryptUsed(passphrase, for: request.path)
219221 plaintext = plain
220222 editing = (plain, passphrase)
221223 problem = nil
222 keep(passphrase, remembered: remembered) {}
224 keep(passphrase, remembered: remembered, text: current) {}
223225 case .decryptInPlace:
224226 let message = OrgCrypt.encryptedRange(current, at: request.offset).map { (current as NSString).substring(with: NSRange($0)) }
225227 let decrypted = try OrgCrypt.decryptInPlace(current, at: request.offset, passphrase: passphrase)
@@ -228,7 +230,7 @@ public struct CryptSheet: View {
228230 session?.cryptDecrypted(message: message, plaintext: (decrypted as NSString).substring(with: NSRange(body)), for: request.path)
229231 }
230232 apply(decrypted)
231 finish("Entry decrypted", passphrase: passphrase, remembered: remembered)
233 finish("Entry decrypted", passphrase: passphrase, remembered: remembered, text: decrypted)
232234 case .encryptOnSave, .openFile, .newFile:
233235 break
234236 }
@@ -237,9 +239,11 @@ public struct CryptSheet: View {
237239 }
238240 }
239241
240 private func finish(_ message: String?, passphrase: String, remembered: Bool) {
242 /// Closes with `message`; `text` is the file's text the passphrase was checked against, nil
243 /// when it wasn't.
244 private func finish(_ message: String?, passphrase: String, remembered: Bool, text: String?) {
241245 if !request.unlocks { session?.cryptUsed(passphrase, for: request.path) }
242 keep(passphrase, remembered: remembered) {
246 keep(passphrase, remembered: remembered, text: text) {
243247 let text = [message, keychainNote].compactMap { $0 }.joined(separator: " ")
244248 done(text.isEmpty ? nil : text)
245249 }
Sources/OrgCore/Crypto/OrgCrypt.swift +17 · view
@@ -237,6 +237,23 @@ public enum OrgCrypt {
237237 }
238238 }
239239
240 /// Every entry's message in `text` encrypted with a passphrase.
241 public static func messages(_ text: String) -> [String] {
242 let ns = text as NSString
243 var found: [String] = []
244 var search = NSRange(location: 0, length: ns.length)
245 while true {
246 let begin = ns.range(of: "-----BEGIN PGP MESSAGE-----", options: [], range: search)
247 guard begin.location != NSNotFound else { return found }
248 let lineStart = ns.lineRange(for: NSRange(location: begin.location, length: 0)).location
249 if let range = encryptedRange(text, at: lineStart), range.lowerBound == lineStart {
250 let message = ns.substring(with: NSRange(range))
251 if let data = try? OpenPGP.dearmor(message), OpenPGP.isSymmetric(data) { found.append(message) }
252 }
253 search = NSRange(location: NSMaxRange(begin), length: ns.length - NSMaxRange(begin))
254 }
255 }
256
240257 /// Whether `passphrase` opens `message`.
241258 public static func opens(_ message: String, passphrase: String) -> Bool {
242259 (try? OpenPGP.decrypt(OpenPGP.dearmor(message), passphrase: passphrase)) != nil
Sources/Orgstar/OrgstarApp.swift +1 −1 · view
@@ -408,7 +408,7 @@ enum UnsavedChanges {
408408 } else if let failure = session.unlock(passphrase, for: path) {
409409 problem = failure
410410 } else {
411 session.passphrases.keep(passphrase, for: path)
411 session.passphrases.keep(passphrase, for: path, text: session.document(of: path)?.text ?? "")
412412 return !session.dirtyPaths.contains(path)
413413 }
414414 case .alertSecondButtonReturn: return true
Tests/OrgAppTests/CryptPassphrasesTests.swift +118 −7 · view
@@ -45,9 +45,17 @@ final class FakeKeychain: PassphraseKeychain {
4545 saved[path] = nil
4646 }
4747
48 func deleteAll() {
49 calls.append("deleteAll")
50 saved = [:]
51 }
52
53 /// The listing finds nothing, as when the Keychain refuses it.
54 var listingFails = false
55
4856 func paths() -> [String] {
4957 calls.append("paths")
50 return Array(saved.keys)
58 return listingFails ? [] : Array(saved.keys)
5159 }
5260}
5361
@@ -99,7 +107,7 @@ struct CryptPassphrasesTests {
99107 #expect(await passphrases.stored(for: file.path) == nil)
100108 #expect(await passphrases.stored(for: gpg.path) == nil)
101109 #expect(!passphrases.hasStored(file.path))
102 #expect(passphrases.keep("typed", for: file.path) == nil)
110 #expect(passphrases.keep("typed", for: file.path, text: "") == nil)
103111 #expect(session.unlock("pw", for: gpg.path) == nil)
104112 #expect(session.isOpen(gpg.path))
105113
@@ -110,7 +118,7 @@ struct CryptPassphrasesTests {
110118 @Test func onSavesATypedPassphraseAndReadsItThroughTheFilesAuthentication() async throws {
111119 let (keychain, passphrases) = FakeKeychain.passphrases(.on)
112120 #expect(!passphrases.asksFirst)
113 #expect(passphrases.keep("pw", for: "/x/a.org") == nil)
121 #expect(passphrases.keep("pw", for: "/x/a.org", text: "") == nil)
114122 #expect(keychain.saved == ["/x/a.org": "pw"])
115123 #expect(passphrases.savedPaths == ["/x/a.org"])
116124 #expect(passphrases.hasStored("/x/a.org"))
@@ -151,11 +159,11 @@ struct CryptPassphrasesTests {
151159 // Undecided: the first typed passphrase asks, and isn't saved before the answer.
152160 let (keychain, passphrases) = FakeKeychain.passphrases(.undecided, defaults: defaults)
153161 #expect(passphrases.setting == .undecided && passphrases.asksFirst)
154 #expect(passphrases.keep("pw", for: "/x/a.org") == nil && keychain.saved.isEmpty)
162 #expect(passphrases.keep("pw", for: "/x/a.org", text: "") == nil && keychain.saved.isEmpty)
155163 // Not Now turns it off, for good.
156164 passphrases.answer(enable: false)
157165 #expect(passphrases.setting == .off && !passphrases.asksFirst)
158 #expect(passphrases.keep("pw", for: "/x/a.org") == nil && keychain.saved.isEmpty)
166 #expect(passphrases.keep("pw", for: "/x/a.org", text: "") == nil && keychain.saved.isEmpty)
159167 let later = CryptPassphrases(keychain: FakeKeychain(["/x/old.org": "pw"]), defaults: defaults)
160168 #expect(later.setting == .off && !later.asksFirst)
161169 later.askIfSavedBefore()
@@ -164,7 +172,7 @@ struct CryptPassphrasesTests {
164172 let (enabled, enabling) = FakeKeychain.passphrases(.undecided)
165173 enabling.answer(enable: true)
166174 #expect(enabling.setting == .on && !enabling.asksFirst)
167 enabling.keep("pw", for: "/x/a.org")
175 enabling.keep("pw", for: "/x/a.org", text: "")
168176 #expect(enabled.saved == ["/x/a.org": "pw"])
169177 }
170178
@@ -200,7 +208,7 @@ struct CryptPassphrasesTests {
200208 passphrases.turnOff()
201209 #expect(passphrases.setting == .off)
202210 #expect(keychain.saved.isEmpty && passphrases.savedPaths.isEmpty)
203 #expect(Set(keychain.calls.filter { $0.hasPrefix("delete ") }) == ["delete /x/a.org", "delete /x/b.org.gpg"])
211 #expect(keychain.calls.contains("deleteAll"))
204212 #expect(passphrases.context(for: "/x/a.org") !== context)
205213 // Forget in Settings removes one.
206214 let (one, forgetting) = FakeKeychain.passphrases(.on, saved: ["/x/a.org": "a", "/x/b.org": "b"])
@@ -217,4 +225,107 @@ struct CryptPassphrasesTests {
217225 passphrases.turnOff()
218226 #expect(defaults.string(forKey: "decryptWithBiometrics") == "off")
219227 }
228
229 // MARK: - Review of MR 494
230
231 /// Two entries, A encrypted with "pw" and B with "other".
232 static func twoPassphrases() throws -> String {
233 let text = "* A :crypt:\na\n* B :crypt:\nb\n"
234 let a = try #require(try OrgCrypt.encrypt(text, at: 0, passphrase: "pw"))
235 let b = (a as NSString).range(of: "* B").location
236 return try #require(try OrgCrypt.encrypt(a, at: b, passphrase: "other"))
237 }
238
239 /// 1: a passphrase is saved only when it opens every message in the file.
240 @Test func onlyAPassphraseThatOpensEveryMessageIsSaved() throws {
241 let mixed = try Self.twoPassphrases()
242 #expect(OrgCrypt.messages(mixed).count == 2)
243 let (keychain, passphrases) = FakeKeychain.passphrases(.on, saved: ["/x/a.org": "saved"])
244 // Encrypting an entry with "pw" beside one encrypted with "other": not saved, and the
245 // saved one stays.
246 #expect(passphrases.keep("pw", for: "/x/a.org", text: mixed) == nil)
247 #expect(keychain.saved == ["/x/a.org": "saved"])
248 #expect(!keychain.calls.contains { $0.hasPrefix("write ") })
249 // One that opens them all, or a file with no other message, is saved.
250 let one = try #require(try OrgCrypt.encrypt("* A :crypt:\na\n", at: 0, passphrase: "pw"))
251 passphrases.keep("pw", for: "/x/a.org", text: one)
252 #expect(keychain.saved == ["/x/a.org": "pw"])
253 passphrases.keep("new", for: "/x/b.org", text: "* Plain\n")
254 #expect(keychain.saved["/x/b.org"] == "new")
255 }
256
257 /// 1: the sheet's path, through the question, checks the same way.
258 @Test func theQuestionsAnswerSavesOnlyAPassphraseThatFits() throws {
259 let mixed = try Self.twoPassphrases()
260 let (keychain, passphrases) = FakeKeychain.passphrases(.undecided)
261 var note: String?
262 #expect(passphrases.typed("pw", for: "/x/a.org", text: mixed, note: &note))
263 #expect(passphrases.answer(enable: true, passphrase: "pw", for: "/x/a.org", text: mixed) == nil)
264 #expect(passphrases.setting == .on && keychain.saved.isEmpty)
265 #expect(!passphrases.typed("other", for: "/x/a.org", text: "* Plain\n", note: &note))
266 #expect(keychain.saved == ["/x/a.org": "other"])
267 }
268
269 /// 1: unlocking a file with a passphrase that opens its first message but not another.
270 @Test func unlockingWithAPassphraseThatOpensOnlySomeMessagesSavesNothing() async throws {
271 let mixed = try Self.twoPassphrases()
272 let file = try notes.write("a.org", mixed)
273 let (keychain, passphrases) = FakeKeychain.passphrases(.on, saved: [file.path: "saved"])
274 let session = DocumentSession(recovery: FileRecoveryStore(directory: notes.url.appendingPathComponent(".recovery")))
275 session.saveMode = .explicit
276 session.passphrases = passphrases
277 session.open(file.path)
278 #expect(session.unlock("pw", for: file.path) == nil)
279 passphrases.keep("pw", for: file.path, text: session.document(of: file.path)?.text ?? "")
280 #expect(keychain.saved == [file.path: "saved"])
281 }
282
283 /// 2: a question answered after the setting was decided elsewhere changes nothing.
284 @Test func aLateAnswerChangesNothing() {
285 // Two sheets asked; the first said Enable, the second Not Now.
286 let (keychain, passphrases) = FakeKeychain.passphrases(.undecided)
287 var note: String?
288 #expect(passphrases.typed("a", for: "/x/a.org", text: "", note: &note))
289 #expect(passphrases.typed("b", for: "/x/b.org", text: "", note: &note))
290 _ = passphrases.answer(enable: true, passphrase: "a", for: "/x/a.org", text: "")
291 _ = passphrases.answer(enable: false, passphrase: "b", for: "/x/b.org", text: "")
292 #expect(passphrases.setting == .on)
293 #expect(keychain.saved == ["/x/a.org": "a"])
294 // Settings turned it off while the question was open: Enable doesn't turn it on.
295 let (other, settings) = FakeKeychain.passphrases(.undecided)
296 #expect(settings.typed("a", for: "/x/a.org", text: "", note: &note))
297 settings.turnOff()
298 _ = settings.answer(enable: true, passphrase: "a", for: "/x/a.org", text: "")
299 #expect(settings.setting == .off && other.saved.isEmpty)
300 // The launch question too.
301 let (_, launch) = FakeKeychain.passphrases(.off)
302 launch.asking = true
303 #expect(!launch.answer(enable: true))
304 #expect(launch.setting == .off && !launch.asking)
305 }
306
307 /// 2: Not Now leaves earlier passphrases in place, unread, listed for Forget.
308 @Test func notNowKeepsEarlierPassphrasesListed() async {
309 let (keychain, passphrases) = FakeKeychain.passphrases(.undecided, saved: ["/x/old.org": "pw"])
310 passphrases.askIfSavedBefore()
311 passphrases.answer(enable: false)
312 #expect(keychain.saved == ["/x/old.org": "pw"])
313 #expect(await passphrases.stored(for: "/x/old.org") == nil)
314 passphrases.refresh()
315 #expect(passphrases.savedPaths == ["/x/old.org"])
316 }
317
318 /// 3: turning off deletes by service, so a listing that fails leaves nothing behind.
319 @Test func turningOffDeletesEverythingWhenTheListingFails() {
320 let (keychain, passphrases) = FakeKeychain.passphrases(.on, saved: ["/x/a.org": "a", "/x/b.org": "b"])
321 keychain.listingFails = true
322 passphrases.turnOff()
323 #expect(keychain.saved.isEmpty)
324 }
325
326 /// 4: the test process's sessions get no Keychain, whatever the setting in user defaults.
327 @Test func testSessionsDontReachTheKeychain() {
328 #expect(CryptPassphrases.shared.keychain is NoKeychain)
329 #expect(DocumentSession(recovery: FileRecoveryStore(directory: notes.url)).passphrases.keychain is NoKeychain)
330 }
220331}
docs/manual/guide/04-outlines.org +1 −1 · view
@@ -960,7 +960,7 @@ Messages are written with AES-256 and an iterated and salted SHA-256 key, which
960960One setting decides whether passphrases are saved in the Keychain: Use Face ID to Decrypt on iPhone and iPad (Use Touch ID to Decrypt on the Mac and on an iPad with Touch ID). It is in Settings ▸ Encryption on the Mac and in the Settings tab on iOS. It is kept in the app's settings on the device, not in =config.toml=, so it isn't synced to other devices and can't be changed by editing a file.
961961
962962- Off :: No passphrase is saved in the Keychain or read from it. A passphrase is typed when it's needed: by the org-crypt commands, to open a =.org.gpg= file, and by Encrypt… for a held file. Once typed, it is kept in memory for that file until the file is closed.
963- On :: A passphrase typed for a file, once it has opened or encrypted the file, is saved in the Keychain for that file. From then on the commands, opening the file, Encrypt… and encrypting on save use it after Face ID, Touch ID or the device's passcode or password, without asking for the passphrase.
963- On :: A passphrase typed for a file, once it has opened or encrypted the file, is saved in the Keychain for that file, unless an encrypted entry in the file doesn't open with it (one encrypted with another passphrase); then the passphrase saved before, if any, is kept. From then on the commands, opening the file, Encrypt… and encrypting on save use it after Face ID, Touch ID or the device's passcode or password, without asking for the passphrase.
964964
965965Until you choose, the setting is undecided and works as Off. The first time you type a passphrase that works, orgstar explains that Face ID can then decrypt anything whose passphrase is saved in your Keychain, and asks whether to use it: Enable turns the setting on and saves that passphrase; Not Now turns it off. Either answer is kept, so the question isn't asked again; change it in Settings. If passphrases saved by an earlier version of orgstar are in the Keychain, the question is asked once at the first launch instead, and they aren't used unless you choose Enable.
966966
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form