@magicred-1/ble-mesh 1.3.4 → 1.3.6
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 encrypted messages which may contain transactions)
|
|
1103
|
+
if (messageType != MessageType.NOISE_ENCRYPTED) {
|
|
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,23 +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
|
-
val publicKeyBytes = packet.payload.copyOfRange(0, publicKeySize)
|
|
1227
|
-
Log.d(TAG, "Extracted public key: ${publicKeyBytes.size} bytes")
|
|
1228
|
-
|
|
1229
1218
|
try {
|
|
1230
|
-
//
|
|
1219
|
+
// Parse X.509 encoded EC public key (entire payload is the key)
|
|
1231
1220
|
val keyFactory = java.security.KeyFactory.getInstance("EC")
|
|
1232
|
-
val keySpec = java.security.spec.X509EncodedKeySpec(
|
|
1221
|
+
val keySpec = java.security.spec.X509EncodedKeySpec(packet.payload)
|
|
1233
1222
|
val peerPublicKey = keyFactory.generatePublic(keySpec)
|
|
1234
1223
|
|
|
1235
1224
|
val keyAgreement = KeyAgreement.getInstance("ECDH")
|
|
@@ -1245,7 +1234,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1245
1234
|
|
|
1246
1235
|
// Update peer's noise public key
|
|
1247
1236
|
peers[senderId]?.let { peer ->
|
|
1248
|
-
peers[senderId] = peer.copy(noisePublicKey =
|
|
1237
|
+
peers[senderId] = peer.copy(noisePublicKey = packet.payload)
|
|
1249
1238
|
}
|
|
1250
1239
|
|
|
1251
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 encrypted messages which may contain transactions)
|
|
889
|
+
if messageTypeEnum != .noiseEncrypted {
|
|
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:
|
|
@@ -1000,14 +1004,20 @@ class BleMesh: RCTEventEmitter {
|
|
|
1000
1004
|
|
|
1001
1005
|
private func handleNoiseHandshake(_ packet: BitchatPacket, from senderID: String) {
|
|
1002
1006
|
NSLog("[BleMesh] Received handshake from \(senderID), payload size: \(packet.payload.count)")
|
|
1007
|
+
NSLog("[BleMesh] Payload hex (first 100 bytes): \(packet.payload.prefix(100).map { String(format: "%02x", $0) }.joined())")
|
|
1003
1008
|
|
|
1004
|
-
//
|
|
1005
|
-
|
|
1006
|
-
|
|
1009
|
+
// Extract Curve25519 public key from payload (should be 32 bytes, but payload might include extra data)
|
|
1010
|
+
let publicKeySize = 32
|
|
1011
|
+
guard packet.payload.count >= publicKeySize else {
|
|
1012
|
+
NSLog("[BleMesh] Invalid handshake payload size: \(packet.payload.count), expected at least \(publicKeySize)")
|
|
1007
1013
|
return
|
|
1008
1014
|
}
|
|
1009
1015
|
|
|
1010
|
-
|
|
1016
|
+
let publicKeyBytes = packet.payload.prefix(publicKeySize)
|
|
1017
|
+
NSLog("[BleMesh] Extracted public key: \(publicKeyBytes.count) bytes")
|
|
1018
|
+
|
|
1019
|
+
// Store peer's public key and derive shared secret
|
|
1020
|
+
guard let peerPublicKey = try? Curve25519.KeyAgreement.PublicKey(rawRepresentation: publicKeyBytes),
|
|
1011
1021
|
let pk = privateKey else {
|
|
1012
1022
|
NSLog("[BleMesh] Failed to parse peer public key or missing private key")
|
|
1013
1023
|
return
|
|
@@ -1026,7 +1036,7 @@ class BleMesh: RCTEventEmitter {
|
|
|
1026
1036
|
|
|
1027
1037
|
// Update peer's noise public key
|
|
1028
1038
|
if var peer = peers[senderID] {
|
|
1029
|
-
peer.noisePublicKey =
|
|
1039
|
+
peer.noisePublicKey = Data(publicKeyBytes)
|
|
1030
1040
|
peers[senderID] = peer
|
|
1031
1041
|
}
|
|
1032
1042
|
|