mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 22:45:19 +00:00
Make Noise-service replacement atomic with the identity swap
During a panic reset, the new NoiseEncryptionService was assigned before the identity barrier ran, so a previously queued send block could observe the new crypto service alongside the old peer ID - signing with the new identity while carrying the old sender. The service teardown, replacement, callback configuration, and derived identity swap now run inside one messageQueue barrier (refreshPeerIdentity executes inline via its re-entrancy check), so queued sends see either the complete old identity or the complete new one, never a mix. Found by Codex review on #1336. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -317,13 +317,20 @@ final class BLEService: NSObject {
|
|||||||
}
|
}
|
||||||
disconnectNotifyDebouncer.removeAll()
|
disconnectNotifyDebouncer.removeAll()
|
||||||
|
|
||||||
noiseService.clearEphemeralStateForPanic()
|
// The crypto-service replacement and the derived identity swap must be
|
||||||
noiseService.clearPersistentIdentity()
|
// one atomic unit with respect to messageQueue senders: a queued send
|
||||||
|
// must never observe the new Noise service alongside the old peer ID
|
||||||
|
// (it would sign with the new identity while carrying the old sender).
|
||||||
|
// refreshPeerIdentity() executes inline here via its re-entrancy check.
|
||||||
|
messageQueue.sync(flags: .barrier) {
|
||||||
|
noiseService.clearEphemeralStateForPanic()
|
||||||
|
noiseService.clearPersistentIdentity()
|
||||||
|
|
||||||
let newNoise = NoiseEncryptionService(keychain: keychain)
|
let newNoise = NoiseEncryptionService(keychain: keychain)
|
||||||
noiseService = newNoise
|
noiseService = newNoise
|
||||||
configureNoiseServiceCallbacks(for: newNoise)
|
configureNoiseServiceCallbacks(for: newNoise)
|
||||||
refreshPeerIdentity()
|
refreshPeerIdentity()
|
||||||
|
}
|
||||||
restartGossipManager()
|
restartGossipManager()
|
||||||
|
|
||||||
setNickname(currentNickname)
|
setNickname(currentNickname)
|
||||||
|
|||||||
Reference in New Issue
Block a user