@magicred-1/ble-mesh 1.3.3 → 1.3.5
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.
|
@@ -1211,16 +1211,22 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
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
|
+
Log.d(TAG, "Payload hex (first 100 bytes): ${packet.payload.take(100).joinToString("") { "%02x".format(it) }}")
|
|
1214
1215
|
|
|
1215
|
-
|
|
1216
|
-
|
|
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")
|
|
1217
1220
|
return
|
|
1218
1221
|
}
|
|
1222
|
+
|
|
1223
|
+
val publicKeyBytes = packet.payload.copyOfRange(0, publicKeySize)
|
|
1224
|
+
Log.d(TAG, "Extracted public key: ${publicKeyBytes.size} bytes")
|
|
1219
1225
|
|
|
1220
1226
|
try {
|
|
1221
1227
|
// Derive shared secret
|
|
1222
1228
|
val keyFactory = java.security.KeyFactory.getInstance("EC")
|
|
1223
|
-
val keySpec = java.security.spec.X509EncodedKeySpec(
|
|
1229
|
+
val keySpec = java.security.spec.X509EncodedKeySpec(publicKeyBytes)
|
|
1224
1230
|
val peerPublicKey = keyFactory.generatePublic(keySpec)
|
|
1225
1231
|
|
|
1226
1232
|
val keyAgreement = KeyAgreement.getInstance("ECDH")
|
|
@@ -1236,7 +1242,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1236
1242
|
|
|
1237
1243
|
// Update peer's noise public key
|
|
1238
1244
|
peers[senderId]?.let { peer ->
|
|
1239
|
-
peers[senderId] = peer.copy(noisePublicKey =
|
|
1245
|
+
peers[senderId] = peer.copy(noisePublicKey = publicKeyBytes)
|
|
1240
1246
|
}
|
|
1241
1247
|
|
|
1242
1248
|
// Send response handshake
|
package/ios/BleMesh.swift
CHANGED
|
@@ -1000,14 +1000,20 @@ class BleMesh: RCTEventEmitter {
|
|
|
1000
1000
|
|
|
1001
1001
|
private func handleNoiseHandshake(_ packet: BitchatPacket, from senderID: String) {
|
|
1002
1002
|
NSLog("[BleMesh] Received handshake from \(senderID), payload size: \(packet.payload.count)")
|
|
1003
|
+
NSLog("[BleMesh] Payload hex (first 100 bytes): \(packet.payload.prefix(100).map { String(format: "%02x", $0) }.joined())")
|
|
1003
1004
|
|
|
1004
|
-
//
|
|
1005
|
-
|
|
1006
|
-
|
|
1005
|
+
// Extract Curve25519 public key from payload (should be 32 bytes, but payload might include extra data)
|
|
1006
|
+
let publicKeySize = 32
|
|
1007
|
+
guard packet.payload.count >= publicKeySize else {
|
|
1008
|
+
NSLog("[BleMesh] Invalid handshake payload size: \(packet.payload.count), expected at least \(publicKeySize)")
|
|
1007
1009
|
return
|
|
1008
1010
|
}
|
|
1009
1011
|
|
|
1010
|
-
|
|
1012
|
+
let publicKeyBytes = packet.payload.prefix(publicKeySize)
|
|
1013
|
+
NSLog("[BleMesh] Extracted public key: \(publicKeyBytes.count) bytes")
|
|
1014
|
+
|
|
1015
|
+
// Store peer's public key and derive shared secret
|
|
1016
|
+
guard let peerPublicKey = try? Curve25519.KeyAgreement.PublicKey(rawRepresentation: publicKeyBytes),
|
|
1011
1017
|
let pk = privateKey else {
|
|
1012
1018
|
NSLog("[BleMesh] Failed to parse peer public key or missing private key")
|
|
1013
1019
|
return
|
|
@@ -1026,7 +1032,7 @@ class BleMesh: RCTEventEmitter {
|
|
|
1026
1032
|
|
|
1027
1033
|
// Update peer's noise public key
|
|
1028
1034
|
if var peer = peers[senderID] {
|
|
1029
|
-
peer.noisePublicKey =
|
|
1035
|
+
peer.noisePublicKey = Data(publicKeyBytes)
|
|
1030
1036
|
peers[senderID] = peer
|
|
1031
1037
|
}
|
|
1032
1038
|
|