Fix: do not reject empty packets that arent message type (#510)

* do not reject empty packets that arent message type

* leave message with empty byte array

* clean up comments
This commit is contained in:
callebtc
2025-11-03 20:37:31 +01:00
committed by GitHub
parent cf53c65cfe
commit 282ac0fe5a
2 changed files with 2 additions and 16 deletions
@@ -949,12 +949,11 @@ class BluetoothMeshService(private val context: Context) {
* Send leave announcement
*/
private fun sendLeaveAnnouncement() {
val nickname = delegate?.getNickname() ?: myPeerID
val packet = BitchatPacket(
type = MessageType.LEAVE.value,
ttl = MAX_TTL,
senderID = myPeerID,
payload = nickname.toByteArray()
payload = byteArrayOf()
)
// Sign the packet before broadcasting
@@ -50,24 +50,11 @@ class SecurityManager(private val encryptionService: EncryptionService, private
return false
}
// Validate packet payload
if (packet.payload.isEmpty()) {
Log.d(TAG, "Dropping packet with empty payload")
return false
}
// Replay attack protection (same 5-minute window as iOS)
val currentTime = System.currentTimeMillis()
val packetTime = packet.timestamp.toLong()
val timeDiff = kotlin.math.abs(currentTime - packetTime)
// if (timeDiff > MESSAGE_TIMEOUT) {
// Log.d(TAG, "Dropping old packet from $peerID, time diff: ${timeDiff/1000}s")
// return false
// }
val messageType = MessageType.fromValue(packet.type)
// Duplicate detection
val messageType = MessageType.fromValue(packet.type)
val messageID = generateMessageID(packet, peerID)
if (messageType != MessageType.ANNOUNCE) {
if (processedMessages.contains(messageID)) {