polish P1: carry the cipher scheme through the channels, diagnose a mismatch
ChannelConfig and BulkConfig carry MacCipherScheme; a change to it reopens every connection the way a key change does. PeerConnection reads the scheme's preamble length (16 legacy, 48 modern) instead of a hard-coded 48. The diagnostic: the peer's opening bytes are kept until one packet has framed. If the first packet fails framing under the configured scheme and the same raw bytes frame under the other one, the connection closes with .invalidKey(.cipherSchemeMismatch) and reports status .cipherSchemeMismatch, so the menu names the setting to change rather than blaming the security key. Costs one AES setup on a connection that was going to fail anyway, and nothing at all on success. The bulk channel needs no diagnostic: a transfer only starts with a peer whose control connection already framed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
c0031c00da
commit
1445d546a1
6 files changed
+108
-20
No files matched your search
@@ -88,8 +88,8 @@ final class BulkConnection: @unchecked Sendable {
|
||||
self.onEvent = onEvent
|
||||
self.peerName = peerName ?? ""
|
||||
self.postAction = postAction
|
||||
writer = try CipherWriter(securityKey: config.securityKey)
|
||||
reader = CipherReader(securityKey: config.securityKey)
|
||||
writer = try CipherWriter(securityKey: config.securityKey, scheme: config.cipherScheme)
|
||||
reader = CipherReader(securityKey: config.securityKey, scheme: config.cipherScheme)
|
||||
}
|
||||
|
||||
// MARK: - Lifecycle
|
||||
@@ -120,7 +120,11 @@ final class BulkConnection: @unchecked Sendable {
|
||||
started = true
|
||||
armDeadline()
|
||||
// `ShakeHand` (`Clipboard.cs:983-987`): the cipher preamble, then one
|
||||
// unframed 64-byte package, before anything is read.
|
||||
// unframed 64-byte package, before anything is read. There is no
|
||||
// scheme-mismatch diagnostic here, and none is needed: a bulk transfer
|
||||
// only starts with a peer whose control connection already framed under
|
||||
// the configured scheme (`BulkSink.authorise`), so the mismatch has
|
||||
// already been reported by then (`docs/protocol.md` §2.5).
|
||||
send(writer.header, encrypted: false)
|
||||
send(handshakePacket().bytes, encrypted: true)
|
||||
receive()
|
||||
|
||||
Reference in new issue
Block a user