mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-26 03:05:20 +00:00
- Use Kotlin coroutine actors for per-peer packet processing - Each peer gets dedicated actor that processes packets sequentially - Eliminates race conditions in session management without complex locking - Single surgical change in PacketProcessor - minimal, maintainable - Leverages Kotlin's native concurrency primitives
34 lines
1.8 KiB
Plaintext
34 lines
1.8 KiB
Plaintext
# noise handshake xx android ios step-counting aead crypto
|
|
**FIXED: Critical Noise Handshake Step Counting Bug**
|
|
**Problem**: Android was failing on step 2 of XX handshake with AEADBadTagException when acting as initiator. The logs showed "Unknown handshake step 1 for initiator" when receiving the 96-byte response from macOS.
|
|
|
|
**Root Cause**: The handshake step counting logic was incorrect. When the initiator (Android) received message 2 from the responder (macOS), the `handshakeMessageCount` was still 1 (from `startHandshake()`), but the validation expected it to be 2.
|
|
|
|
**Fix Applied**:
|
|
1. **Corrected Step Calculation**: Added logic to calculate `currentStep` properly before processing:
|
|
```kotlin
|
|
val currentStep = if (isInitiator) {
|
|
handshakeMessageCount + 1 // Initiator receiving message 2, 3, etc.
|
|
} else {
|
|
handshakeMessageCount // Responder receiving message 1, 2, etc.
|
|
}
|
|
```
|
|
|
|
2. **Enhanced Message Size Validation**: Made validation more lenient to accept larger messages (iOS might include additional payload):
|
|
```kotlin
|
|
// More lenient validation - allow larger messages (they may contain additional payload)
|
|
if (message.size < expectedSize) {
|
|
Log.w(TAG, "Handshake message too small: got ${message.size}, minimum expected $expectedSize for step $step")
|
|
} else if (message.size != expectedSize) {
|
|
Log.d(TAG, "Handshake message size: got ${message.size}, expected $expectedSize for step $step (accepting larger message)")
|
|
}
|
|
```
|
|
|
|
**Expected Result**: The XX handshake should now complete successfully between Android (initiator) and macOS/iOS (responder).
|
|
|
|
**Files Modified**:
|
|
- `/app/src/main/java/com/bitchat/android/noise/NoiseSession.kt` - `processHandshakeMessage()` and `validateHandshakeMessageSize()` methods
|
|
|
|
**Build Status**: ✅ Successful compilation with `./gradlew assembleDebug`
|
|
|