Files
bitchat-android/.goose/memory/Noise Handshake Start() Key Setting Fix.txt
T
callebtc 75cc4615c7 Fix Noise session race condition with elegant per-peer actor serialization
- 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
2025-07-20 18:45:21 +02:00

47 lines
2.0 KiB
Plaintext

# noise handshake xx static-keys start validation noise-java
**CRITICAL FIX: "Local static key required" Error Resolved**
**Problem**: The noise-java library was throwing "Local static key required" during `HandshakeState.start()`, preventing handshake initialization.
**Root Cause**: The noise-java library **validates that required static keys are present before allowing start()** to proceed. This is different from the iOS approach and requires keys to be set **before** calling `start()`, not during handshake progression.
**Stack Trace**: Error occurred in `HandshakeState.start()` at line 501, indicating key validation failure.
**Critical Fix Applied**:
```kotlin
// CRITICAL FIX: Set static keys BEFORE calling start()
// The noise-java library validates key presence during start()
if (handshakeState?.needsLocalKeyPair() == true) {
Log.d(TAG, "Setting static keys before start() - required by noise-java")
val localKeyPair = handshakeState?.getLocalKeyPair()
if (localKeyPair != null) {
localKeyPair.setPrivateKey(localStaticPrivateKey, 0)
if (!localKeyPair.hasPrivateKey() || !localKeyPair.hasPublicKey()) {
throw IllegalStateException("Failed to set static identity keys")
}
Log.d(TAG, "✓ Static identity keys set successfully before start()")
}
}
handshakeState?.start() // NOW WORKS: Keys are set before validation
```
**Key Insight**: The noise-java library architecture requires:
1. Create HandshakeState
2. **Set static keys (if needed)**
3. Call start() (which validates keys)
4. Proceed with writeMessage/readMessage
This differs from iOS CryptoKit approach where keys can be set dynamically during handshake progression.
**Expected Result**:
- Android responder can now initialize XX handshake successfully
- Should eliminate "Local static key required" error
- Handshake should progress to message processing phase
**Files Modified**: `/app/src/main/java/com/bitchat/android/noise/NoiseSession.kt` - `initializeNoiseHandshake()` method
**Build Status**: ✅ Successful compilation