mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 22:05:21 +00:00
Fix topology update running before announce verification
Move updateNeighbors call to after signature verification passes, preventing spoofed or stale announces from injecting bad routing data. Also reset isNewPeer/isReconnectedPeer flags on verification failure to prevent spurious peer connection notifications. Addresses review feedback from PR #938. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3580,11 +3580,6 @@ extension BLEService {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update topology with their claimed neighbors
|
|
||||||
if let neighbors = announcement.directNeighbors {
|
|
||||||
meshTopology.updateNeighbors(for: peerID.routingData, neighbors: neighbors)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify that the sender's derived ID from the announced noise public key matches the packet senderID
|
// Verify that the sender's derived ID from the announced noise public key matches the packet senderID
|
||||||
// This helps detect relayed or spoofed announces. Only warn in release; assert in debug.
|
// This helps detect relayed or spoofed announces. Only warn in release; assert in debug.
|
||||||
let derivedFromKey = PeerID(publicKey: announcement.noisePublicKey)
|
let derivedFromKey = PeerID(publicKey: announcement.noisePublicKey)
|
||||||
@@ -3657,6 +3652,9 @@ extension BLEService {
|
|||||||
// Require verified announce; ignore otherwise (no backward compatibility)
|
// Require verified announce; ignore otherwise (no backward compatibility)
|
||||||
if !verified {
|
if !verified {
|
||||||
SecureLogger.warning("❌ Ignoring unverified announce from \(peerID.id.prefix(8))…", category: .security)
|
SecureLogger.warning("❌ Ignoring unverified announce from \(peerID.id.prefix(8))…", category: .security)
|
||||||
|
// Reset flags to prevent post-barrier code from acting on unverified announces
|
||||||
|
isNewPeer = false
|
||||||
|
isReconnectedPeer = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3704,6 +3702,11 @@ extension BLEService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update topology with verified neighbor claims (only for authenticated announces)
|
||||||
|
if verifiedAnnounce, let neighbors = announcement.directNeighbors {
|
||||||
|
meshTopology.updateNeighbors(for: peerID.routingData, neighbors: neighbors)
|
||||||
|
}
|
||||||
|
|
||||||
// Persist cryptographic identity and signing key for robust offline verification
|
// Persist cryptographic identity and signing key for robust offline verification
|
||||||
identityManager.upsertCryptographicIdentity(
|
identityManager.upsertCryptographicIdentity(
|
||||||
fingerprint: announcement.noisePublicKey.sha256Fingerprint(),
|
fingerprint: announcement.noisePublicKey.sha256Fingerprint(),
|
||||||
|
|||||||
Reference in New Issue
Block a user