refactor: Improve node public key handling and security (#2395)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-07-09 14:43:10 +00:00 committed by GitHub
parent 93dc691625
commit 9259e21aed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 800 additions and 35 deletions

View file

@ -29,6 +29,8 @@ import com.geeksville.mesh.database.entity.NodeEntity
import com.geeksville.mesh.util.GPSFormat
import com.geeksville.mesh.util.latLongToMeter
import com.geeksville.mesh.util.toDistanceString
import com.google.protobuf.ByteString
import com.google.protobuf.kotlin.isNotEmpty
@Suppress("MagicNumber")
data class Node(
@ -48,6 +50,7 @@ data class Node(
val environmentMetrics: EnvironmentMetrics = EnvironmentMetrics.getDefaultInstance(),
val powerMetrics: PowerMetrics = PowerMetrics.getDefaultInstance(),
val paxcounter: PaxcountProtos.Paxcount = PaxcountProtos.Paxcount.getDefaultInstance(),
val publicKey: ByteString? = null,
) {
val colors: Pair<Int, Int>
get() { // returns foreground and background @ColorInt for each 'num'
@ -59,8 +62,8 @@ data class Node(
}
val isUnknownUser get() = user.hwModel == MeshProtos.HardwareModel.UNSET
val hasPKC get() = !user.publicKey.isEmpty
val mismatchKey get() = user.publicKey == NodeEntity.ERROR_BYTE_STRING
val hasPKC get() = (publicKey ?: user.publicKey).isNotEmpty()
val mismatchKey get() = (publicKey ?: user.publicKey) == NodeEntity.ERROR_BYTE_STRING
val hasEnvironmentMetrics: Boolean
get() = environmentMetrics != EnvironmentMetrics.getDefaultInstance()