@magicred-1/ble-mesh 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1210,7 +1210,12 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1210
1210
|
}
|
|
1211
1211
|
|
|
1212
1212
|
private fun handleNoiseHandshake(packet: BitchatPacket, senderId: String) {
|
|
1213
|
-
|
|
1213
|
+
Log.d(TAG, "Received handshake from $senderId, payload size: ${packet.payload.size}")
|
|
1214
|
+
|
|
1215
|
+
if (packet.payload.size != 65) {
|
|
1216
|
+
Log.e(TAG, "Invalid handshake payload size: ${packet.payload.size}, expected 65")
|
|
1217
|
+
return
|
|
1218
|
+
}
|
|
1214
1219
|
|
|
1215
1220
|
try {
|
|
1216
1221
|
// Derive shared secret
|
|
@@ -1227,6 +1232,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1227
1232
|
val symmetricKey = digest.digest(sharedSecret)
|
|
1228
1233
|
|
|
1229
1234
|
sessions[senderId] = symmetricKey
|
|
1235
|
+
Log.d(TAG, "✅ Encrypted session established with $senderId")
|
|
1230
1236
|
|
|
1231
1237
|
// Update peer's noise public key
|
|
1232
1238
|
peers[senderId]?.let { peer ->
|
|
@@ -1235,10 +1241,14 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1235
1241
|
|
|
1236
1242
|
// Send response handshake
|
|
1237
1243
|
if (packet.recipientId == null || packet.recipientId.contentEquals(myPeerIdBytes)) {
|
|
1244
|
+
Log.d(TAG, "Sending handshake response to $senderId")
|
|
1238
1245
|
initiateHandshakeInternal(senderId)
|
|
1246
|
+
} else {
|
|
1247
|
+
Log.d(TAG, "Handshake not for us, recipient: ${byteArrayToHexString(packet.recipientId ?: byteArrayOf())}")
|
|
1239
1248
|
}
|
|
1240
1249
|
} catch (e: Exception) {
|
|
1241
1250
|
Log.e(TAG, "Handshake failed: ${e.message}")
|
|
1251
|
+
e.printStackTrace()
|
|
1242
1252
|
sendErrorEvent("HANDSHAKE_ERROR", e.message ?: "Unknown error")
|
|
1243
1253
|
}
|
|
1244
1254
|
}
|
|
@@ -1700,12 +1710,20 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1700
1710
|
}
|
|
1701
1711
|
|
|
1702
1712
|
private fun initiateHandshakeInternal(peerId: String) {
|
|
1703
|
-
|
|
1713
|
+
Log.d(TAG, "Initiating handshake with $peerId")
|
|
1714
|
+
val publicKey = privateKey?.public?.encoded
|
|
1715
|
+
if (publicKey == null) {
|
|
1716
|
+
Log.e(TAG, "Cannot initiate handshake: no private key")
|
|
1717
|
+
return
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
Log.d(TAG, "Public key size: ${publicKey.size} bytes")
|
|
1704
1721
|
val packet = createPacket(
|
|
1705
1722
|
type = MessageType.NOISE_HANDSHAKE.value,
|
|
1706
1723
|
payload = publicKey,
|
|
1707
1724
|
recipientId = hexStringToByteArray(peerId)
|
|
1708
1725
|
)
|
|
1726
|
+
Log.d(TAG, "Broadcasting handshake packet to $peerId (${connectedDevices.size} devices, ${gattConnections.size} connections)")
|
|
1709
1727
|
broadcastPacket(packet)
|
|
1710
1728
|
}
|
|
1711
1729
|
|
package/ios/BleMesh.swift
CHANGED
|
@@ -817,13 +817,20 @@ class BleMesh: RCTEventEmitter {
|
|
|
817
817
|
}
|
|
818
818
|
|
|
819
819
|
private func initiateHandshakeInternal(with peerId: String) {
|
|
820
|
-
|
|
821
|
-
|
|
820
|
+
NSLog("[BleMesh] Initiating handshake with \(peerId)")
|
|
821
|
+
|
|
822
|
+
guard let publicKey = privateKey?.publicKey.rawRepresentation else {
|
|
823
|
+
NSLog("[BleMesh] Cannot initiate handshake: no private key")
|
|
824
|
+
return
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
NSLog("[BleMesh] Public key size: \(publicKey.count) bytes")
|
|
822
828
|
let packet = createPacket(
|
|
823
829
|
type: MessageType.noiseHandshake.rawValue,
|
|
824
830
|
payload: publicKey,
|
|
825
831
|
recipientID: Data(hexString: peerId)
|
|
826
832
|
)
|
|
833
|
+
NSLog("[BleMesh] Broadcasting handshake packet to \(peerId) (\(subscribedCentrals.count) centrals, \(peripherals.count) peripherals)")
|
|
827
834
|
broadcastPacket(packet)
|
|
828
835
|
}
|
|
829
836
|
|
|
@@ -992,10 +999,19 @@ class BleMesh: RCTEventEmitter {
|
|
|
992
999
|
}
|
|
993
1000
|
|
|
994
1001
|
private func handleNoiseHandshake(_ packet: BitchatPacket, from senderID: String) {
|
|
1002
|
+
NSLog("[BleMesh] Received handshake from \(senderID), payload size: \(packet.payload.count)")
|
|
1003
|
+
|
|
995
1004
|
// Store peer's public key and derive shared secret
|
|
996
|
-
guard packet.payload.count == 32
|
|
997
|
-
|
|
998
|
-
|
|
1005
|
+
guard packet.payload.count == 32 else {
|
|
1006
|
+
NSLog("[BleMesh] Invalid handshake payload size: \(packet.payload.count), expected 32")
|
|
1007
|
+
return
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
guard let peerPublicKey = try? Curve25519.KeyAgreement.PublicKey(rawRepresentation: packet.payload),
|
|
1011
|
+
let pk = privateKey else {
|
|
1012
|
+
NSLog("[BleMesh] Failed to parse peer public key or missing private key")
|
|
1013
|
+
return
|
|
1014
|
+
}
|
|
999
1015
|
|
|
1000
1016
|
do {
|
|
1001
1017
|
let sharedSecret = try pk.sharedSecretFromKeyAgreement(with: peerPublicKey)
|
|
@@ -1006,6 +1022,7 @@ class BleMesh: RCTEventEmitter {
|
|
|
1006
1022
|
outputByteCount: 32
|
|
1007
1023
|
)
|
|
1008
1024
|
sessions[senderID] = symmetricKey.withUnsafeBytes { Data($0) }
|
|
1025
|
+
NSLog("[BleMesh] ✅ Encrypted session established with \(senderID)")
|
|
1009
1026
|
|
|
1010
1027
|
// Update peer's noise public key
|
|
1011
1028
|
if var peer = peers[senderID] {
|
|
@@ -1015,9 +1032,13 @@ class BleMesh: RCTEventEmitter {
|
|
|
1015
1032
|
|
|
1016
1033
|
// Send response handshake if this is an incoming request
|
|
1017
1034
|
if packet.recipientID == nil || packet.recipientID == myPeerIDData {
|
|
1035
|
+
NSLog("[BleMesh] Sending handshake response to \(senderID)")
|
|
1018
1036
|
initiateHandshakeInternal(with: senderID)
|
|
1037
|
+
} else {
|
|
1038
|
+
NSLog("[BleMesh] Handshake not for us, recipient: \(packet.recipientID?.hexString ?? "none")")
|
|
1019
1039
|
}
|
|
1020
1040
|
} catch {
|
|
1041
|
+
NSLog("[BleMesh] Handshake failed: \(error.localizedDescription)")
|
|
1021
1042
|
sendEvent(withName: "onError", body: ["code": "HANDSHAKE_ERROR", "message": error.localizedDescription])
|
|
1022
1043
|
}
|
|
1023
1044
|
}
|