mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-24 21:45:21 +00:00
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:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user