qa: P1 QA log — legacy cipher scheme verified, verdict PASS

Verified constants against a9e1f0f20e^ Encryption.cs/Common.cs, the
MacCipherScheme setting's default/round-trip/reach into both configs,
the PeerConnection scheme-mismatch diagnostic (both directions traced
by hand, including the wrong-key non-misfire case), SocketStatus 100
never hits the wire, and the Security-pane picker's commit-on-change +
full-reopen path. gates.sh green under tools/guard.sh; no app launch,
no sockets, no tests (none exist in this repo).

One non-blocking finding: BulkChannel.reconfigure's disruptive check
omits cipherScheme, unlike ChannelConfig.needsFullReopen — traced as
harmless (new BulkConnections pick up the current config regardless)
but worth a comment for the next reader.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
lucioandClaude Sonnet 5 committed 2026-09-16 21:19:20 -07:00
1 parent 9930412c6b
commit 367c739252
1 file changed
+129
+129
View File
@@ -173,4 +173,133 @@ stream was built. No socket was opened and the app was not launched.
## QA log
### 2026-09-16 — QA (P1)
Verified `git diff 32a0c72..HEAD` against CLAUDE.md, `docs/protocol.md`
§2 (incl. §2.5) and §10.9, and the Work log above. Build only —
`tools/guard.sh -m 8 -t 600 -- tools/gates.sh` (all three gates: `swift-format
lint --strict`, `MWBCore` layering, `swift build -Xswiftc
-warnings-as-errors`) — green, no app launch, no sockets opened, no tests
(none exist in this repo; `README.md` says so by design). No
force-unwrap/`try!`/`fatalError`/`precondition` introduced, no `log`/`print`
statements anywhere in the diff.
1. **Legacy constants**, against
`git -C /Users/guoliangchen/repo/PowerToys show a9e1f0f20e^:src/modules/MouseWithoutBorders/App/Core/Encryption.cs`
and the paired `Common.cs`: `InitialIV = "18446744073709551615"`
(`Encryption.cs:41`); `GenLegalKey` salts with `Common.GetBytesU(InitialIV)` =
`ASCIIEncoding.Unicode.GetBytes` = UTF-16LE (`Common.cs:407-410`), 50 000
iterations, `HashAlgorithmName.SHA512`, 32 bytes (`Encryption.cs:117-138`);
`GenLegalIV` takes `InitialIV` as ASCII, truncated to `symAl.IV.Length` (16)
(`Encryption.cs:140-154`, `Common.cs:397-400`). `LegacyCipherConstants` in
`Sources/MWBCore/CipherStream.swift:70-84` matches all four facts exactly:
`salt` builds UTF-16LE by hand (low byte, high byte per UTF-16 code unit,
correct for this all-ASCII string), `iterations = 50_000`,
`iv = Array(initialIV.utf8.prefix(16))` = `"1844674407370955"`. No header,
sacrificial block first: `CipherWriter.header` is `cleartextHeader
(empty under .legacy) + sacrificial`, confirmed at
`CipherStream.swift:243-259`. **Modern path unchanged**: `CipherConstants`
(`saltSize`/`blockSize` 16, `iterations` 100_000, `derivedKeyLength` 32,
`CipherStream.swift:58-67`) are untouched by the diff, and both production
call sites (`PeerConnection.swift:107-108`, `BulkConnection.swift:91-92`)
pass `scheme:` explicitly from `config.cipherScheme`, so no caller falls
through to the new `= .legacy` default parameter.
2. **`MacCipherScheme` setting** (`Settings.swift:163, 174-184`): defaults to
`.legacy` via `Settings.defaultProperties["MacCipherScheme"]` and the `??
.legacy` fallback in the getter; round-trips through the same
boxed-JSONValue mechanism every other string setting uses. Reaches
`ChannelConfig.cipherScheme` (`EngineActions.swift:262`) and
`BulkConfig.cipherScheme` (`ClipboardBridge.swift:408`), both sourced from
`settings.macCipherScheme`. "Preserved for Windows" checks out as: the
generic `properties: [String: JSONValue]` store round-trips every key it
doesn't interpret, so `MacCipherScheme` free-rides the same mechanism as
every Windows-owned property this port doesn't implement — confirmed by
reading, not by a round-trip test (none exist).
3. **`PeerConnection` preamble sizes**: `cipherScheme.preambleSize` used at
`readPreamble()` (`PeerConnection.swift:189`), computed as
`cleartextHeaderSize + blockSize` (`CipherStream.swift:29-56`) — 16 for
`.legacy` (0 + 16), 48 for `.modern` (32 + 16). Confirmed by reading, not
by opening a socket.
4. **Mismatch diagnostic** (`PeerConnection.swift:234-294`): traced both
directions by hand — configured `.legacy` vs. an actual `.modern` peer, and
the reverse. `SchemeProbe.raw` accumulates from the very first
`consume()` call (the preamble chunk included, since `readPreamble()`
itself calls `consume(bytes)`), so by the time `diagnosticBytes` (48 + 32 =
80) raw bytes have arrived, replaying them from byte 0 under the other
scheme's `CipherReader` lines up correctly with that scheme's own
preamble-then-packet framing — matches Work log deviation #2's
explanation. The diagnostic only evaluates the first post-preamble packet
(`self.probe = nil` on every exit path from `noteForDiagnostic`, so it
never re-arms). Wrong-key case traced: a bad key produces
framing-failing garbage under *both* the configured and the other scheme
(AES output is uncorrelated with the plaintext for a wrong key, so framing
fails independently under each), so `framesUnderOtherScheme` returns
`false` and `consume()` falls through to the ordinary `session.feed`,
which is what eventually produces a plain `.invalidKey` once the
session's own 10-non-handshake-packet budget (`docs/protocol.md` §3.2
guard 5) is spent — well after the diagnostic's ~2-3 packets, so there is
no race between the two. `BulkConnection` takes no diagnostic, correctly:
`BulkSink.authorise` gates a transfer on the control connection already
being trusted.
5. **`SocketStatus.cipherSchemeMismatch = 100`**: not a wire type anywhere —
grepped every `SocketStatus` use in `Sources/`; nothing serialises it to
`Data`/`UInt8`/a socket write. `report(_:)` (`PeerConnection.swift:315`)
only updates the local `Session` and drains local queues. Every `switch`
over `SocketStatus` (`StatusItem.swift` colour and wording) is exhaustive
with no `default`, compiles clean under `-warnings-as-errors`, and both
new cases have sensible values (brown, "wrong encryption compatibility
setting") with a comment explaining why it shares the invalid-key colour.
`UIBridge.bestStatuses`/`rank` uses `default: return 0`, so the new case
doesn't break that switch either. The one gap — `updateNotifications`
doesn't fire a notification for `.cipherSchemeMismatch`
(`UIBridge.swift:190-200`) — is exactly the gap the Work log's Handshakes
§1 already discloses; not a silent omission.
6. **Security-pane picker**: `model.binding(\.macCipherScheme)`
(`SecurityPane.swift:63`) goes through `SettingsViewModel.binding` →
`commit` → `store.update` → `publishToEngine()`
(`SettingsViewModel.swift:67-83`), i.e. `SettingsStore.update`, matching
the "not a draft, commits as it changes" pattern documented in
`SettingsViewModel.swift:8-12`. The control channel path reopens fully:
`ChannelConfig.needsFullReopen` now compares `cipherScheme`
(`ChannelConfig.swift:85-87`), and `ControlChannel.reconfigure` calls
`reopen()` whenever `needsFullReopen` is true (`ControlChannel.swift:126-134`).
**Minor finding, not blocking**: `BulkChannel.reconfigure`'s `disruptive`
flag (`BulkChannel.swift:159-166`) does not include `cipherScheme`, unlike
`ChannelConfig.needsFullReopen`. Traced through: this is not a wire bug —
`config = new` runs unconditionally before the `disruptive` check, and
every new `BulkConnection` is built from `self.config` at accept/dial
time (`BulkChannel.swift:271-276`), so a scheme toggle takes effect on the
next transfer regardless. Unlike the control channel's `PeerConnection`s,
`BulkConnection`s are one-shot per transfer, not long-lived sessions, so
there is no persistent connection left running on the stale scheme in
steady state — only a transfer already in flight at the moment of the
toggle, which finishes under the scheme it started with rather than being
cancelled. That's arguably the better behaviour (a background settings
click doesn't kill an active file transfer), but the asymmetry with the
control channel's explicit `cipherScheme` comparison has no comment
explaining it was a deliberate choice rather than an oversight. Worth a
one-line comment at `BulkChannel.swift:161-163` for the next reader; not
worth a rework.
7. **Readability / CLAUDE.md**: all touched files stay within the 300-600
line guidance except `Settings.swift` (666), `BulkConnection.swift`
(550→unchanged range) and `ClipboardBridge.swift` (560) — all three were
already over 600 before this diff (652/546/559 at `32a0c72`) and this
diff adds only a handful of lines to each; not a new violation to raise
here. New functions (`StreamMaterial.forWriter/forReader`,
`noteForDiagnostic`, `framingFails`, `framesUnderOtherScheme`,
`startStream(consuming:)`) are all well under the 50-line target, doc
comments are present and say why, and every citation checked against
PowerToys resolves to real, matching lines.
8. **No key material logged**: no `Log.*`/`print` call touches
`securityKey`, derived key bytes, salt, IV, or plaintext anywhere in the
diff; `CipherError` cases carry only status codes, never key or plaintext
bytes (unchanged from before this diff).
**Not verified** (out of scope per the task): no test suite exists in this
repo to run; no socket was opened and the app was not launched, so the
legacy scheme's correctness rests on the Dev's offline Python cross-check
(Work log) and this diff read, not on a fresh independent run.
Verdict: PASS
## Review