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:
James Rich 2025-03-27 15:58:43 -05:00 committed by GitHub
parent 53c240198c
commit a28dc377ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 47 additions and 12 deletions

View file

@ -184,6 +184,8 @@ internal fun MessageScreen(
DataPacket.ID_BROADCAST -> channelName
else -> viewModel.getUser(nodeId).longName
}
val mismatchKey =
DataPacket.PKC_CHANNEL_INDEX == channelIndex && viewModel.getNode(nodeId).mismatchKey
// if (channelIndex != DataPacket.PKC_CHANNEL_INDEX && nodeId != DataPacket.ID_BROADCAST) {
// subtitle = "(ch: $channelIndex - $channelName)"
@ -242,7 +244,7 @@ internal fun MessageScreen(
}
}
} else {
MessageTopBar(title, channelIndex, onNavigateBack)
MessageTopBar(title, channelIndex, mismatchKey, onNavigateBack)
}
},
bottomBar = {
@ -368,6 +370,7 @@ private fun ActionModeTopBar(
private fun MessageTopBar(
title: String,
channelIndex: Int?,
mismatchKey: Boolean = false,
onNavigateBack: () -> Unit
) = TopAppBar(
title = { Text(text = title) },
@ -381,7 +384,7 @@ private fun MessageTopBar(
},
actions = {
if (channelIndex == DataPacket.PKC_CHANNEL_INDEX) {
NodeKeyStatusIcon(hasPKC = true, mismatchKey = false)
NodeKeyStatusIcon(hasPKC = true, mismatchKey = mismatchKey)
}
}
)