@magicred-1/ble-mesh 1.3.5 → 1.3.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.
|
@@ -1096,17 +1096,19 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1096
1096
|
return
|
|
1097
1097
|
}
|
|
1098
1098
|
|
|
1099
|
-
// Deduplication
|
|
1100
|
-
val messageId = "$senderId-${packet.timestamp}-${packet.type}"
|
|
1101
|
-
if (processedMessages.contains(messageId)) {
|
|
1102
|
-
Log.d(TAG, "Duplicate packet, skipping")
|
|
1103
|
-
return
|
|
1104
|
-
}
|
|
1105
|
-
processedMessages.add(messageId)
|
|
1106
|
-
|
|
1107
1099
|
val messageType = MessageType.fromValue(packet.type)
|
|
1108
1100
|
Log.d(TAG, "Processing packet type: $messageType")
|
|
1109
1101
|
|
|
1102
|
+
// Deduplication (but NOT for handshakes - they arrive from multiple BLE addresses)
|
|
1103
|
+
if (messageType != MessageType.NOISE_HANDSHAKE) {
|
|
1104
|
+
val messageId = "$senderId-${packet.timestamp}-${packet.type}"
|
|
1105
|
+
if (processedMessages.contains(messageId)) {
|
|
1106
|
+
Log.d(TAG, "Duplicate packet, skipping")
|
|
1107
|
+
return
|
|
1108
|
+
}
|
|
1109
|
+
processedMessages.add(messageId)
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1110
1112
|
// Handle by type
|
|
1111
1113
|
when (messageType) {
|
|
1112
1114
|
MessageType.ANNOUNCE -> handleAnnounce(packet, senderId)
|
|
@@ -1213,20 +1215,10 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1213
1215
|
Log.d(TAG, "Received handshake from $senderId, payload size: ${packet.payload.size}")
|
|
1214
1216
|
Log.d(TAG, "Payload hex (first 100 bytes): ${packet.payload.take(100).joinToString("") { "%02x".format(it) }}")
|
|
1215
1217
|
|
|
1216
|
-
// Extract EC public key from payload (should be 65 bytes, but payload might include extra data)
|
|
1217
|
-
val publicKeySize = 65
|
|
1218
|
-
if (packet.payload.size < publicKeySize) {
|
|
1219
|
-
Log.e(TAG, "Invalid handshake payload size: ${packet.payload.size}, expected at least $publicKeySize")
|
|
1220
|
-
return
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
val publicKeyBytes = packet.payload.copyOfRange(0, publicKeySize)
|
|
1224
|
-
Log.d(TAG, "Extracted public key: ${publicKeyBytes.size} bytes")
|
|
1225
|
-
|
|
1226
1218
|
try {
|
|
1227
|
-
//
|
|
1219
|
+
// Parse X.509 encoded EC public key (entire payload is the key)
|
|
1228
1220
|
val keyFactory = java.security.KeyFactory.getInstance("EC")
|
|
1229
|
-
val keySpec = java.security.spec.X509EncodedKeySpec(
|
|
1221
|
+
val keySpec = java.security.spec.X509EncodedKeySpec(packet.payload)
|
|
1230
1222
|
val peerPublicKey = keyFactory.generatePublic(keySpec)
|
|
1231
1223
|
|
|
1232
1224
|
val keyAgreement = KeyAgreement.getInstance("ECDH")
|
|
@@ -1242,7 +1234,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1242
1234
|
|
|
1243
1235
|
// Update peer's noise public key
|
|
1244
1236
|
peers[senderId]?.let { peer ->
|
|
1245
|
-
peers[senderId] = peer.copy(noisePublicKey =
|
|
1237
|
+
peers[senderId] = peer.copy(noisePublicKey = packet.payload)
|
|
1246
1238
|
}
|
|
1247
1239
|
|
|
1248
1240
|
// Send response handshake
|
package/ios/BleMesh.swift
CHANGED
|
@@ -883,13 +883,17 @@ class BleMesh: RCTEventEmitter {
|
|
|
883
883
|
// Skip our own packets
|
|
884
884
|
if senderID == myPeerID { return }
|
|
885
885
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
886
|
+
let messageTypeEnum = MessageType(rawValue: packet.type)
|
|
887
|
+
|
|
888
|
+
// Deduplication (but NOT for handshakes - they arrive from multiple BLE addresses)
|
|
889
|
+
if messageTypeEnum != .noiseHandshake {
|
|
890
|
+
let messageID = "\(senderID)-\(packet.timestamp)-\(packet.type)"
|
|
891
|
+
if processedMessages.contains(messageID) { return }
|
|
892
|
+
processedMessages.insert(messageID)
|
|
893
|
+
}
|
|
890
894
|
|
|
891
895
|
// Handle by type
|
|
892
|
-
switch
|
|
896
|
+
switch messageTypeEnum {
|
|
893
897
|
case .announce:
|
|
894
898
|
handleAnnounce(packet, from: senderID)
|
|
895
899
|
case .message:
|