mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 02:25: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
|
* Send leave announcement
|
||||||
*/
|
*/
|
||||||
private fun sendLeaveAnnouncement() {
|
private fun sendLeaveAnnouncement() {
|
||||||
val nickname = delegate?.getNickname() ?: myPeerID
|
|
||||||
val packet = BitchatPacket(
|
val packet = BitchatPacket(
|
||||||
type = MessageType.LEAVE.value,
|
type = MessageType.LEAVE.value,
|
||||||
ttl = MAX_TTL,
|
ttl = MAX_TTL,
|
||||||
senderID = myPeerID,
|
senderID = myPeerID,
|
||||||
payload = nickname.toByteArray()
|
payload = byteArrayOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sign the packet before broadcasting
|
// Sign the packet before broadcasting
|
||||||
|
|||||||
@@ -50,24 +50,11 @@ class SecurityManager(private val encryptionService: EncryptionService, private
|
|||||||
return false
|
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)
|
// Replay attack protection (same 5-minute window as iOS)
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
val packetTime = packet.timestamp.toLong()
|
val messageType = MessageType.fromValue(packet.type)
|
||||||
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
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Duplicate detection
|
// Duplicate detection
|
||||||
val messageType = MessageType.fromValue(packet.type)
|
|
||||||
val messageID = generateMessageID(packet, peerID)
|
val messageID = generateMessageID(packet, peerID)
|
||||||
if (messageType != MessageType.ANNOUNCE) {
|
if (messageType != MessageType.ANNOUNCE) {
|
||||||
if (processedMessages.contains(messageID)) {
|
if (processedMessages.contains(messageID)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user