polish P1: protocol §2.5 and §10.9, README D3 and Status, TODO §10
§2.5 is the legacy stream: the fixed salt, IV and iteration count with citations into the pre-a9e1f0f20e Encryption.cs, the missing cleartext header, why the sacrificial block exists, the MacCipherScheme setting and the mismatch diagnostic. §2.3 now says plainly that it describes v0.101 and later only. §10.9 records the one fact in this document confirmed against a live Windows machine rather than the source: the lead's independent Python probe completed the whole handshake against the user's PC under the legacy scheme, which proves framing, the magic hash, the packet layout and the handshake as transcribed, and localises the earlier failure to the stream cipher alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
2de39f79de
commit
81e35b6691
4 files changed
+216
-4
No files matched your search
@@ -73,14 +73,104 @@ user had not granted Accessibility yet; the menu says so. No code
|
||||
change unless the user reports the menu text was unclear. Kept here so
|
||||
the CP1 record is complete.
|
||||
|
||||
## Handshakes
|
||||
|
||||
*Requests to other lanes, raised by P1 and deliberately not made here.*
|
||||
|
||||
1. **app-ui / app-engine — the notification for a scheme mismatch.**
|
||||
`UIBridge.updateNotifications` fires `notifier.invalidKey(for:)` on
|
||||
`status == .invalidKey` only (`Sources/mwb/UIBridge.swift:198-200`), so a
|
||||
`.cipherSchemeMismatch` row shows in the menu but posts no notification.
|
||||
One `else if` in that method would fix it; `UIBridge.swift` is not in this
|
||||
item's file list, so it is a request rather than an edit.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [ ] P1: legacy scheme + setting + diagnostic, files as listed;
|
||||
- [x] P1: legacy scheme + setting + diagnostic, files as listed;
|
||||
`docs/protocol.md` §2.5 and §10.9.
|
||||
- [ ] P2: none.
|
||||
|
||||
## Work log
|
||||
|
||||
**2026-09-16 — Dev (P1).** Implemented as decided above.
|
||||
|
||||
*Offline first.* Before any app code, the legacy constants were checked
|
||||
against an independent implementation, in the scratchpad: our
|
||||
`CipherWriter(scheme: .legacy)` stream decrypts under Python
|
||||
`cryptography`'s AES-CBC with
|
||||
`hashlib.pbkdf2_hmac('sha512', key, '18446744073709551615'.encode('utf-16-le'), 50000, 32)`
|
||||
and IV `b"1844674407370955"`, and our `CipherReader(scheme: .legacy)`
|
||||
recovers a stream Python encrypted the same way. Both directions matched
|
||||
byte for byte, and the derived key and IV matched Python's before either
|
||||
stream was built. No socket was opened and the app was not launched.
|
||||
|
||||
*What changed.*
|
||||
|
||||
- `Sources/MWBCore/CipherStream.swift`: a `CipherScheme` enum
|
||||
(`.legacy` default, `.modern`) with `preambleSize` and `other`;
|
||||
`LegacyCipherConstants` carrying the fixed salt (UTF-16LE of
|
||||
`"18446744073709551615"`, 40 bytes, `Encryption.cs:126` +
|
||||
`Common.cs:407-410`), 50 000 iterations (`:127`) and the ASCII IV
|
||||
(`GenLegalIV`, `:140-154`), all cited to the pre-`a9e1f0f20e` file;
|
||||
`deriveStreamKey` takes the iteration count; a `StreamMaterial` value
|
||||
computes key/IV/cleartext-header per scheme for each side.
|
||||
`CipherWriter.header` is now 16 bytes under `.legacy` (the encrypted
|
||||
sacrificial block alone) and 48 under `.modern`; `CipherReader`
|
||||
consumes a cleartext header only when the scheme has one.
|
||||
- `Sources/MWBCore/Settings.swift`: `MacCipherScheme` in the defaults and
|
||||
a `macCipherScheme: CipherScheme` accessor, default `.legacy`.
|
||||
- `Sources/MWBCore/Session.swift`: `InvalidKeyReason.cipherSchemeMismatch`
|
||||
and a `SocketStatus.cipherSchemeMismatch` case. The status case has raw
|
||||
value **100**, outside the Windows 0–9 range, so the Windows numbering
|
||||
the menu colours depend on is untouched; nothing serialises this enum.
|
||||
- `Sources/MWBNet/ChannelConfig.swift`, `BulkChannel.swift`: both configs
|
||||
carry the scheme; a change to it triggers `needsFullReopen`, like a key
|
||||
or port change.
|
||||
- `Sources/MWBNet/PeerConnection.swift`: writer, reader and the preamble
|
||||
read all take the scheme (`cipherScheme.preambleSize`, replacing the
|
||||
hard-coded 48). The diagnostic keeps the peer's raw opening bytes and
|
||||
the plaintext they yielded until one packet frames; if the first packet
|
||||
fails framing under our scheme *and* the same raw bytes frame under the
|
||||
other, the connection closes `.invalidKey(.cipherSchemeMismatch)` and
|
||||
reports the matching status. Nothing is fed to the `Session` on that
|
||||
path (invariant 2).
|
||||
- `Sources/MWBNet/BulkConnection.swift`: takes the scheme. **No
|
||||
diagnostic there** — a bulk transfer only begins with a peer whose
|
||||
control connection already framed under the configured scheme
|
||||
(`BulkSink.authorise`), so a mismatch has already been reported.
|
||||
- `Sources/MWBMac/StatusItem.swift`: the new status is painted the
|
||||
invalid-key brown (same kind of failure) with its own words, "wrong
|
||||
encryption compatibility setting".
|
||||
- `Sources/MWBMac/SettingsWindow/SecurityPane.swift`: an "Encryption
|
||||
compatibility" radio group, "PowerToys 0.100 and earlier" /
|
||||
"PowerToys 0.101 and later", bound straight through
|
||||
`SettingsViewModel.binding`. Not a draft like the key and port: one
|
||||
click is a whole change.
|
||||
- `Sources/mwb/EngineActions.swift` and `Sources/mwb/ClipboardBridge.swift`
|
||||
map `settings.macCipherScheme` into `ChannelConfig` / `BulkConfig`. The
|
||||
brief said `Engine.swift`; those two files are where `channelConfig()`
|
||||
and `bulkConfig()` actually live (both are `Engine` extensions).
|
||||
- `docs/protocol.md` §2.5 and §10.9, `README.md` D3 + §Status + the
|
||||
architecture line for `CipherStream.swift`, `TODO.md` §10.
|
||||
|
||||
*Deviations and decisions worth flagging to the lead.*
|
||||
|
||||
1. Two files outside the stated list were touched, each additively and by
|
||||
necessity: `Sources/MWBNet/BulkChannel.swift` (the `cipherScheme`
|
||||
field on `BulkConfig` — `BulkConnection` cannot be handed a scheme
|
||||
without it) and `Sources/mwb/ClipboardBridge.swift` (where
|
||||
`bulkConfig()` is built).
|
||||
2. The diagnostic needs up to 48 + 32 raw bytes, not one packet's worth.
|
||||
Configured `.legacy` against a `.modern` peer, our reader treats the
|
||||
peer's first 16 bytes as the sacrificial block, so the first 32 bytes
|
||||
of plaintext appear after only 48 raw bytes — too few to re-run the
|
||||
modern reader, which wants 32 header bytes before it decrypts
|
||||
anything. The probe therefore waits for `diagnosticBytes` before
|
||||
replaying. While it waits, the garbage keeps spending the session's
|
||||
untrusted budget exactly as it would without the diagnostic, and
|
||||
Windows sends ten handshakes at once, so the bytes are always there.
|
||||
3. The notification gap in Handshakes 1 above.
|
||||
|
||||
## QA log
|
||||
|
||||
## Review
|
||||
Reference in new issue
Block a user