mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 20:05:21 +00:00
hashing
This commit is contained in:
@@ -61,7 +61,7 @@ class BluetoothMeshService(private val context: Context) {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
setupDelegates()
|
setupDelegates()
|
||||||
startPeriodicDebugLogging()
|
// startPeriodicDebugLogging()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.bitchat.android.noise
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.bitchat.android.noise.southernstorm.protocol.*
|
import com.bitchat.android.noise.southernstorm.protocol.*
|
||||||
|
import com.bitchat.android.util.toHexString
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ class NoiseSession(
|
|||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Local static key pair not needed for this handshake pattern/role")
|
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()
|
handshakeState?.start()
|
||||||
Log.d(TAG, "Handshake state started successfully with persistent identity keys")
|
Log.d(TAG, "Handshake state started successfully with persistent identity keys")
|
||||||
|
|
||||||
@@ -193,7 +194,7 @@ class NoiseSession(
|
|||||||
|
|
||||||
val messageBuffer = ByteArray(XX_MESSAGE_1_SIZE)
|
val messageBuffer = ByteArray(XX_MESSAGE_1_SIZE)
|
||||||
val handshakeStateLocal = handshakeState ?: throw IllegalStateException("Handshake state is null")
|
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)
|
val firstMessage = messageBuffer.copyOf(messageLength)
|
||||||
|
|
||||||
// Validate message size matches XX pattern expectations
|
// Validate message size matches XX pattern expectations
|
||||||
@@ -223,7 +224,7 @@ class NoiseSession(
|
|||||||
if (state == NoiseSessionState.Uninitialized && !isInitiator) {
|
if (state == NoiseSessionState.Uninitialized && !isInitiator) {
|
||||||
initializeNoiseHandshake(HandshakeState.RESPONDER)
|
initializeNoiseHandshake(HandshakeState.RESPONDER)
|
||||||
state = NoiseSessionState.Handshaking
|
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) {
|
if (state != NoiseSessionState.Handshaking) {
|
||||||
@@ -246,8 +247,8 @@ class NoiseSession(
|
|||||||
return when (action) {
|
return when (action) {
|
||||||
HandshakeState.WRITE_MESSAGE -> {
|
HandshakeState.WRITE_MESSAGE -> {
|
||||||
// Noise library says we need to send a response
|
// Noise library says we need to send a response
|
||||||
val responseBuffer = ByteArray(MAX_PAYLOAD_SIZE) // Large buffer for any response
|
val responseBuffer = ByteArray(XX_MESSAGE_2_SIZE + MAX_PAYLOAD_SIZE) // Large buffer for any response
|
||||||
val responseLength = handshakeStateLocal.writeMessage(responseBuffer, 0, ByteArray(0), 0, 0)
|
val responseLength = handshakeStateLocal.writeMessage(responseBuffer, 0, null, 0, 0)
|
||||||
val response = responseBuffer.copyOf(responseLength)
|
val response = responseBuffer.copyOf(responseLength)
|
||||||
|
|
||||||
Log.d(TAG, "Generated handshake response: ${response.size} bytes, action still: ${handshakeStateLocal.getAction()}")
|
Log.d(TAG, "Generated handshake response: ${response.size} bytes, action still: ${handshakeStateLocal.getAction()}")
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class NoiseSessionManager(
|
|||||||
val shouldInitiate = resolveTieBreaker(peerID)
|
val shouldInitiate = resolveTieBreaker(peerID)
|
||||||
if (!shouldInitiate) {
|
if (!shouldInitiate) {
|
||||||
Log.d(TAG, "Tie-breaker: Waiting for $peerID to initiate handshake")
|
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
|
// Remove any existing non-established session
|
||||||
|
|||||||
+13
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
package com.bitchat.android.noise.southernstorm.protocol;
|
package com.bitchat.android.noise.southernstorm.protocol;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -545,6 +547,17 @@ public class HandshakeState implements Destroyable {
|
|||||||
if ((requirements & LOCAL_PREMSG) != 0)
|
if ((requirements & LOCAL_PREMSG) != 0)
|
||||||
symmetric.mixPublicKey(localKeyPair);
|
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.
|
// The handshake has officially started - set the first action.
|
||||||
if (isInitiator)
|
if (isInitiator)
|
||||||
|
|||||||
Reference in New Issue
Block a user