mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-14 03:46:25 -04:00
fix: Handle node public key mismatch and show warning (#1720)
* Handle node public key mismatch and show warning - Add a mismatchKey flag to Node and MessageTopBar to indicate a public key mismatch. - Set the public key to a default error value (all zeros) when a node's public key changes. - Display a warning in the MessageTopBar when a key mismatch is detected in PKC. - Only clear all nodes when a different mynode number is present. * feat: Add key mismatch detection to NodeInfoDao This commit introduces a new feature to the `NodeInfoDao` that detects and handles public key mismatches for existing nodes. - A new function `upsertCheckKeyMatch` is added to `NodeInfoDao` that checks for public key changes when upserting a node. If a mismatch is detected, the public key is set to `ERROR_BYTE_STRING`, and a warning is logged. - The function `upsertCheckKeyMatch` is used instead of `upsert` in `NodeRepository` and in `putAll` inside of `NodeInfoDao`. - A new test `testPkcMismatch` is added to `NodeInfoDaoTest` to verify the key mismatch detection. - Changed `testNodes` to have unique public keys. - Added `mismatchKey` state to the node model. * detekt spacing * Refactor: Correctly handle different node installations in NodeRepository The logic for detecting different node installations in `NodeRepository.kt` was inverted, this commit fixes the logic to use `!=` instead of `==` to detect if the node number has changed.
This commit is contained in:
@@ -26,6 +26,7 @@ import com.geeksville.mesh.database.entity.MyNodeEntity
|
||||
import com.geeksville.mesh.database.entity.NodeEntity
|
||||
import com.geeksville.mesh.model.Node
|
||||
import com.geeksville.mesh.model.NodeSortOption
|
||||
import com.google.protobuf.ByteString
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.runBlocking
|
||||
@@ -92,7 +93,6 @@ class NodeInfoDaoTest {
|
||||
41.878113 to -87.629799, // Chicago
|
||||
39.952583 to -75.165222, // Philadelphia
|
||||
)
|
||||
|
||||
private val testNodes = listOf(ourNode, unknownNode) + testPositions.mapIndexed { index, pos ->
|
||||
NodeEntity(
|
||||
num = 9 + index,
|
||||
@@ -102,6 +102,7 @@ class NodeInfoDaoTest {
|
||||
shortName = "KM$index"
|
||||
hwModel = MeshProtos.HardwareModel.ANDROID_SIM
|
||||
isLicensed = false
|
||||
publicKey = ByteString.copyFrom(ByteArray(32) { index.toByte() })
|
||||
},
|
||||
longName = "Kevin Mester$index", shortName = "KM$index",
|
||||
latitude = pos.first, longitude = pos.second,
|
||||
@@ -203,4 +204,15 @@ class NodeInfoDaoTest {
|
||||
val containsUnsetNode = nodes.any { it.isUnknownUser }
|
||||
assertTrue(containsUnsetNode)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPkcMismatch() = runBlocking {
|
||||
val newNode = testNodes[1].copy(user = testNodes[1].user.copy {
|
||||
publicKey = ByteString.copyFrom(ByteArray(32) { 99 })
|
||||
})
|
||||
nodeInfoDao.putAll(listOf(newNode))
|
||||
val nodes = getNodes()
|
||||
val containsMismatchNode = nodes.any { it.mismatchKey }
|
||||
assertTrue(containsMismatchNode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user