From 0b5e72cd43fb930343dd173dbff46fcf7cd4fb76 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 14 Aug 2024 20:52:47 -0700 Subject: [PATCH] Public key mismatch warning --- Localizable.xcstrings | 6 ++++++ Meshtastic/Helpers/MeshPackets.swift | 2 ++ .../contents | 1 + .../Views/Nodes/Helpers/NodeDetail.swift | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 1656a3f4..11662cbc 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -10784,6 +10784,9 @@ }, "Key" : { + }, + "Key does not match the public key that was used previously, delete the node and let it negotatiate keys again." : { + }, "Key Mapping" : { @@ -16659,6 +16662,9 @@ }, "Public Key" : { + }, + "Public Key Mismatch" : { + }, "PWD" : { diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 44538947..952899dd 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -630,6 +630,7 @@ func routingPacket (packet: MeshPacket, connectedNodeNum: Int64, context: NSMana fetchedMessage[0].ackError = Int32(routingMessage.errorReason.rawValue) if routingError == RoutingError.pkiFailed { fetchedMessage[0].toUser?.keyMatch = false + fetchedMessage[0].toUser?.newPublicKey = fetchedMessage[0].publicKey } if routingMessage.errorReason == Routing.Error.none { @@ -854,6 +855,7 @@ func textMessageAppPacket( /// We have a key, check if it matches if newMessage.fromUser?.publicKey != newMessage.publicKey { newMessage.fromUser?.keyMatch = false + newMessage.fromUser?.newPublicKey = newMessage.publicKey } } else { /// We have no key, set it diff --git a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 42.xcdatamodel/contents b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 42.xcdatamodel/contents index b92f33f6..ac5d631b 100644 --- a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 42.xcdatamodel/contents +++ b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 42.xcdatamodel/contents @@ -436,6 +436,7 @@ + diff --git a/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift b/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift index 68769280..0d9897c7 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift @@ -44,6 +44,24 @@ struct NodeDetail: View { NodeInfoItem(node: node) } Section("Node") { + if let user = node.user { + if user.keyMatch { + Label { + VStack(alignment: .leading) { + Text("Public Key Mismatch") + .font(.title3) + .foregroundStyle(.red) + Text("Key does not match the public key that was used previously, delete the node and let it negotatiate keys again.") + .font(.caption) + .foregroundStyle(.red) + } + } icon: { + Image(systemName: "key.slash.fill") + .symbolRenderingMode(.multicolor) + .foregroundStyle(.red) + } + } + } HStack { Label { Text("Node Number")