Archived
Stop a one-off label from moving the session's, and guard locked folders
Three things, found while chasing two intermittent failures that turned out
to be the test harness tapping the app.
`ensureLabelKey` put the request label back with
`defer { Task { await api.setLabel(previous) } }`, which reads like a
restore and is not one: the task is detached, so the label goes back at
some later moment of the runtime's choosing. Until then every request
carries the wrong area, and when it lands it can undo a label some other
call has since set. Android and the browser both restore synchronously in
a `finally` — only this port drifted. The label is now not moved at all:
storing a grant carries its own label for that one request, so anything in
flight alongside it still goes out under the area the caller is in.
`currentLabelKey` threw `notCleared` — "You aren't cleared for this" — when
the truth was that this device has not minted a key for the area yet, which
is every account before its first write. In a system built on clearance,
telling a properly cleared newcomer they are not cleared is both wrong and
alarming. It now says what is true and what to do about it.
A folder whose name will not decrypt is now checked the same way a file is.
Opening one navigated into somebody else's folder and then complained about
a missing key, which is a confusing way to say "this is not yours" — and
the file branch has always checked.
Also translates CryptoKit's authentication failures, which reached people
as "(CryptoKit.CryptoKitError error 3.)".
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
3ad9a93449
commit
61bac2ab6d
@@ -382,6 +382,14 @@ final class AppState: ObservableObject {
|
||||
if text.contains("no recovery code on file") {
|
||||
return "This account has no recovery code on file."
|
||||
}
|
||||
if text.contains("cryptokit") || text.contains("authenticationfailure") {
|
||||
// An AEAD tag that did not verify. The person cannot act on
|
||||
// "CryptoKitError error 3", and telling them the operation could
|
||||
// not be completed says nothing at all — this at least names the
|
||||
// shape of the problem and the usual cause.
|
||||
return "Something here could not be unlocked with the keys on this device. "
|
||||
+ "If somebody else filed it, you need their key for this area."
|
||||
}
|
||||
if text.contains("too many") {
|
||||
// Already a sentence, and one worth showing exactly as sent.
|
||||
return raw
|
||||
|
||||
@@ -144,9 +144,13 @@ struct BrowseView: View {
|
||||
}
|
||||
|
||||
private func open(_ entry: FilesSession.Entry) async {
|
||||
if entry.isFolder {
|
||||
// A folder whose name will not decrypt is checked the same way a file
|
||||
// is. Opening one navigated into somebody else's folder and then
|
||||
// reported a missing key, which is a confusing way to say "this is not
|
||||
// yours" — and the file branch below has always checked.
|
||||
if entry.isFolder, entry.name != nil {
|
||||
await state.open(entry)
|
||||
} else if entry.name != nil {
|
||||
} else if !entry.isFolder, entry.name != nil {
|
||||
exportedFile = await state.download(entry)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +66,15 @@ class UITestCase: XCTestCase {
|
||||
/// screen and blurs the code out — the one thing on that screen the person
|
||||
/// has just been told to write down, and the only way back into the
|
||||
/// account.
|
||||
/// ⚠️ Only call this when something is *actually* blocked.
|
||||
///
|
||||
/// Both taps land on the app when no dialog is there — the first in the
|
||||
/// middle of the screen, the second wherever that offset falls — and on the
|
||||
/// file list that means opening whichever row happens to be under it. In a
|
||||
/// shared area that is usually somebody else's folder, so the app navigates
|
||||
/// into something it cannot read and reports a missing key. Two tests spent
|
||||
/// a long time being blamed on the client for it.
|
||||
func clearSystemPrompt() {
|
||||
app.tap()
|
||||
// "Not Now", in the left-hand button of the pair.
|
||||
app.coordinate(withNormalizedOffset: CGVector(dx: 0.315, dy: 0.625)).tap()
|
||||
}
|
||||
|
||||
@@ -208,8 +214,12 @@ class UITestCase: XCTestCase {
|
||||
NSPredicate(format: "label BEGINSWITH 'Working at'")).firstMatch
|
||||
for _ in 0..<4 {
|
||||
if banner.exists { return code }
|
||||
clearSystemPrompt()
|
||||
if done.exists {
|
||||
guard done.exists else { break }
|
||||
if done.isHittable {
|
||||
done.tap()
|
||||
} else {
|
||||
// Blocked, so something is over it — now it is worth clearing.
|
||||
clearSystemPrompt()
|
||||
if done.isHittable {
|
||||
done.tap()
|
||||
} else {
|
||||
|
||||
@@ -27,7 +27,18 @@ public actor FilesAPI {
|
||||
return try http.decode(Wire.ServerConfig.self, from: data)
|
||||
}
|
||||
|
||||
private var headers: [String: String] {
|
||||
private var headers: [String: String] { headers(for: label) }
|
||||
|
||||
/// Headers for one request, at a label that need not be the session's.
|
||||
///
|
||||
/// The label is shared state read at the moment a request is sent, so
|
||||
/// switching it around a single call — set, send, put it back — is only
|
||||
/// safe if nothing else is in flight. In an app something always is, and
|
||||
/// the request that overlaps goes out under the wrong area: rows arrive
|
||||
/// from a label whose key this device does not hold, and the failure
|
||||
/// surfaces as ciphertext that will not authenticate. Anything needing a
|
||||
/// one-off label passes it here instead of moving the session's.
|
||||
private func headers(for label: Label?) -> [String: String] {
|
||||
var headers = ["Authorization": "Bearer \(token)"]
|
||||
if let label {
|
||||
headers["X-Enclave-Classification"] = String(label.classification)
|
||||
@@ -45,10 +56,12 @@ public actor FilesAPI {
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func post<T: Decodable>(_ type: T.Type, _ path: String, _ body: some Encodable & Sendable)
|
||||
func post<T: Decodable>(_ type: T.Type, _ path: String, _ body: some Encodable & Sendable,
|
||||
at oneOff: Label? = nil)
|
||||
async throws -> T? {
|
||||
let (data, response) = try await http.request(
|
||||
"POST", try .endpoint(baseURL, path), headers: headers, json: body)
|
||||
"POST", try .endpoint(baseURL, path),
|
||||
headers: headers(for: oneOff ?? label), json: body)
|
||||
if response.statusCode == 204 || data.isEmpty { return nil }
|
||||
return try? http.decode(type, from: data)
|
||||
}
|
||||
@@ -95,10 +108,12 @@ public actor FilesAPI {
|
||||
}
|
||||
|
||||
func storeGrant(label: Label, wrappedKey: Data) async throws {
|
||||
// Sent at the grant's own label without disturbing the session's.
|
||||
_ = try await post(
|
||||
Wire.LabelGrant.self, "/api/keys/labels",
|
||||
GrantBody(classification: label.classification,
|
||||
compartments: label.compartments.sorted(), wrappedKey: wrappedKey))
|
||||
compartments: label.compartments.sorted(), wrappedKey: wrappedKey),
|
||||
at: label)
|
||||
}
|
||||
|
||||
struct DelegateBody: Encodable, Sendable {
|
||||
|
||||
@@ -185,13 +185,14 @@ public actor FilesSession {
|
||||
guard clearance.permits(wanted) else { throw ClientError.notCleared }
|
||||
if let existing = labelKeys[wanted] { return existing }
|
||||
|
||||
// Stored at the wanted label without moving the session's, so a
|
||||
// request that overlaps this one still goes out under the area the
|
||||
// caller is actually in.
|
||||
let key = Random.bytes(32)
|
||||
let previous = label
|
||||
await api.setLabel(wanted)
|
||||
defer { Task { await api.setLabel(previous) } }
|
||||
try await api.storeGrant(
|
||||
label: wanted,
|
||||
wrappedKey: try Keys.grantLabelKey(key, label: wanted, to: publicKey))
|
||||
|
||||
labelKeys[wanted] = key
|
||||
return key
|
||||
}
|
||||
@@ -220,7 +221,7 @@ public actor FilesSession {
|
||||
|
||||
var currentLabelKey: Data {
|
||||
get throws {
|
||||
guard let key = labelKeys[label] else { throw ClientError.notCleared }
|
||||
guard let key = labelKeys[label] else { throw ClientError.noKeyForArea }
|
||||
return key
|
||||
}
|
||||
}
|
||||
@@ -422,7 +423,7 @@ public actor FilesSession {
|
||||
|
||||
let shareLabel = Label(classification: classification,
|
||||
compartments: Set(row.compartments ?? []))
|
||||
guard let labelKey = labelKeys[shareLabel] else { throw ClientError.notCleared }
|
||||
guard let labelKey = labelKeys[shareLabel] else { throw ClientError.noKeyForArea }
|
||||
|
||||
let opened = try Shares.open(
|
||||
labelKey: labelKey, label: shareLabel,
|
||||
|
||||
@@ -162,6 +162,11 @@ public enum Wire {
|
||||
public enum ClientError: LocalizedError, Equatable {
|
||||
case http(status: Int, detail: String)
|
||||
case notCleared
|
||||
/// Not the same thing as being uncleared, and saying so matters: the first
|
||||
/// is a permission the server decides, the second is a key this device has
|
||||
/// simply not minted yet — which happens to every account before it first
|
||||
/// writes anywhere.
|
||||
case noKeyForArea
|
||||
case badServer(String)
|
||||
case wrongPassphrase
|
||||
/// Refused before reading, not after uploading.
|
||||
@@ -178,6 +183,9 @@ public enum ClientError: LocalizedError, Equatable {
|
||||
return "That handle and passphrase don't match."
|
||||
case .notCleared:
|
||||
return "You aren't cleared for this."
|
||||
case .noKeyForArea:
|
||||
return "You don't have a key for this area yet. Put something in it, "
|
||||
+ "or ask somebody who works there to give you theirs."
|
||||
case .badServer(let why):
|
||||
return why
|
||||
case .http(let status, let detail):
|
||||
|
||||
Reference in New Issue
Block a user