mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 18:05:21 +00:00
Discard deferred Noise ciphertext during panic
This commit is contained in:
@@ -149,6 +149,16 @@ final class BLENoisePacketHandler {
|
||||
drainDeferredCiphertextsIfReady(for: peerID)
|
||||
}
|
||||
|
||||
/// Synchronously discards ciphertext retained for a pre-panic Noise
|
||||
/// generation. The handler survives the service's identity replacement,
|
||||
/// so keeping this queue would replay old bytes after post-panic auth.
|
||||
func resetForPanic() {
|
||||
deferredLock.lock()
|
||||
deferredCiphertexts.removeAll(keepingCapacity: false)
|
||||
deferredCiphertextBytes = 0
|
||||
deferredLock.unlock()
|
||||
}
|
||||
|
||||
private func handleEncrypted(
|
||||
_ packet: BitchatPacket,
|
||||
from peerID: PeerID,
|
||||
|
||||
@@ -707,6 +707,7 @@ final class BLEService: NSObject {
|
||||
/// or advertising while the full panic transaction is incomplete.
|
||||
func suspendForPanicReset() {
|
||||
setPanicSuspended(true)
|
||||
noisePacketHandler.resetForPanic()
|
||||
gossipSyncManager?.stop()
|
||||
gossipSyncManager = nil
|
||||
// Stop the radio and drain CoreBluetooth's delegate queue first. A
|
||||
@@ -717,7 +718,11 @@ final class BLEService: NSObject {
|
||||
// Drain every receive/send submitted by callbacks that finished ahead
|
||||
// of the radio stop. Later callbacks observe the closed lifecycle, and
|
||||
// generation-bound handoffs that raced this barrier reject themselves.
|
||||
messageQueue.sync(flags: .barrier) {}
|
||||
// Clear the old identity's bounded early-ciphertext queue again after
|
||||
// those callbacks drain so none can repopulate it after the first wipe.
|
||||
messageQueue.sync(flags: .barrier) {
|
||||
noisePacketHandler.resetForPanic()
|
||||
}
|
||||
clearEmergencySessionState()
|
||||
}
|
||||
|
||||
@@ -736,6 +741,7 @@ final class BLEService: NSObject {
|
||||
gossipSyncManager?.stop()
|
||||
gossipSyncManager = nil
|
||||
messageQueue.sync(flags: .barrier) {
|
||||
noisePacketHandler.resetForPanic()
|
||||
pendingNoiseSessionQueues.removeAll()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user