This commit is contained in:
callebtc
2025-07-19 19:03:26 +02:00
parent a19b4dc991
commit 342796dc01
4 changed files with 24 additions and 10 deletions
@@ -61,7 +61,7 @@ class BluetoothMeshService(private val context: Context) {
init {
setupDelegates()
startPeriodicDebugLogging()
// startPeriodicDebugLogging()
}
/**
@@ -2,6 +2,7 @@ package com.bitchat.android.noise
import android.util.Log
import com.bitchat.android.noise.southernstorm.protocol.*
import com.bitchat.android.util.toHexString
import java.security.SecureRandom
@@ -148,7 +149,7 @@ class NoiseSession(
Log.d(TAG, "Persistent identity public key: ${localStaticPublicKey.joinToString("") { "%02x".format(it) }}")
Log.d(TAG, "Set public key: ${verifyPublic.joinToString("") { "%02x".format(it) }}")
} else {
throw IllegalStateException("HandshakeState returned null for local key pair")
}
@@ -156,10 +157,10 @@ class NoiseSession(
} else {
Log.d(TAG, "Local static key pair not needed for this handshake pattern/role")
}
handshakeState?.setPrologue(PROTOCOL_NAME.toByteArray(), 0, PROTOCOL_NAME.toByteArray().size)
handshakeState?.start()
Log.d(TAG, "Handshake state started successfully with persistent identity keys")
} catch (e: Exception) {
Log.e(TAG, "Exception during handshake initialization: ${e.message}", e)
throw e
@@ -193,7 +194,7 @@ class NoiseSession(
val messageBuffer = ByteArray(XX_MESSAGE_1_SIZE)
val handshakeStateLocal = handshakeState ?: throw IllegalStateException("Handshake state is null")
val messageLength = handshakeStateLocal.writeMessage(messageBuffer, 0, ByteArray(0), 0, 0)
val messageLength = handshakeStateLocal.writeMessage(messageBuffer, 0, null, 0, 0)
val firstMessage = messageBuffer.copyOf(messageLength)
// Validate message size matches XX pattern expectations
@@ -223,7 +224,7 @@ class NoiseSession(
if (state == NoiseSessionState.Uninitialized && !isInitiator) {
initializeNoiseHandshake(HandshakeState.RESPONDER)
state = NoiseSessionState.Handshaking
Log.d(TAG, "Initialized as responder for real XX handshake with $peerID")
Log.d(TAG, "Initialized as RESPONDER for XX handshake with $peerID")
}
if (state != NoiseSessionState.Handshaking) {
@@ -246,8 +247,8 @@ class NoiseSession(
return when (action) {
HandshakeState.WRITE_MESSAGE -> {
// Noise library says we need to send a response
val responseBuffer = ByteArray(MAX_PAYLOAD_SIZE) // Large buffer for any response
val responseLength = handshakeStateLocal.writeMessage(responseBuffer, 0, ByteArray(0), 0, 0)
val responseBuffer = ByteArray(XX_MESSAGE_2_SIZE + MAX_PAYLOAD_SIZE) // Large buffer for any response
val responseLength = handshakeStateLocal.writeMessage(responseBuffer, 0, null, 0, 0)
val response = responseBuffer.copyOf(responseLength)
Log.d(TAG, "Generated handshake response: ${response.size} bytes, action still: ${handshakeStateLocal.getAction()}")
@@ -111,7 +111,7 @@ class NoiseSessionManager(
val shouldInitiate = resolveTieBreaker(peerID)
if (!shouldInitiate) {
Log.d(TAG, "Tie-breaker: Waiting for $peerID to initiate handshake")
throw IllegalStateException("Tie-breaker: Should not initiate with $peerID")
// throw IllegalStateException("Tie-breaker: Should not initiate with $peerID")
}
// Remove any existing non-established session
@@ -22,6 +22,8 @@
package com.bitchat.android.noise.southernstorm.protocol;
import android.util.Log;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -545,7 +547,18 @@ public class HandshakeState implements Destroyable {
if ((requirements & LOCAL_PREMSG) != 0)
symmetric.mixPublicKey(localKeyPair);
}
// Log the symmetric.hash in hex:
byte[] currentHandshakeHash = symmetric.h;
if (currentHandshakeHash != null) {
StringBuilder hexString = new StringBuilder(currentHandshakeHash.length * 2);
for (byte b : currentHandshakeHash) {
hexString.append(String.format("%02X", b));
}
Log.d("TAG", "Initial Handshake Hash (h): " + hexString.toString());
} else {
Log.d("TAG", "Initial Handshake Hash (h): null");
}
// The handshake has officially started - set the first action.
if (isInitiator)
action = WRITE_MESSAGE;