Skip to content

Commit f09f2b1

Browse files
authored
Gate the PKI-decrypt key on signer-proven, not the opportunistic cache (#11116)
1 parent 11c510f commit f09f2b1

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/mesh/NodeDB.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,6 +3783,22 @@ bool NodeDB::copyPublicKey(NodeNum n, meshtastic_NodeInfoLite_public_key_t &out)
37833783
return false;
37843784
}
37853785

3786+
bool NodeDB::copyPublicKeyForDecrypt(NodeNum n, meshtastic_NodeInfoLite_public_key_t &out)
3787+
{
3788+
if (copyPublicKeyAuthoritative(n, out))
3789+
return true;
3790+
#if HAS_TRAFFIC_MANAGEMENT
3791+
// A cold-tier cache key backs an authenticated decrypt only when signer-proven; unverified TOFU
3792+
// cache keys must not. Outbound encryption still uses the opportunistic copyPublicKey().
3793+
bool signerProven = false;
3794+
if (trafficManagementModule && trafficManagementModule->copyPublicKey(n, out.bytes, &signerProven) && signerProven) {
3795+
out.size = 32;
3796+
return true;
3797+
}
3798+
#endif
3799+
return false;
3800+
}
3801+
37863802
bool NodeDB::isVerifiedSignerForKey(NodeNum n, const uint8_t *key32)
37873803
{
37883804
if (!key32)

src/mesh/NodeDB.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ class NodeDB
364364
/// opportunistic caches) - the pin reference for caches that mirror NodeDB's key hygiene.
365365
bool copyPublicKeyAuthoritative(NodeNum n, meshtastic_NodeInfoLite_public_key_t &out);
366366

367+
/// Key for the inbound-decrypt path: authoritative (hot/warm), or a cold-tier cache key only when
368+
/// it is signer-proven. Keeps unverified TOFU cache keys from backing pki_encrypted attribution.
369+
bool copyPublicKeyForDecrypt(NodeNum n, meshtastic_NodeInfoLite_public_key_t &out);
370+
367371
/// True if n is a known XEdDSA signer for exactly `key32` (hot signed bitfield or warm
368372
/// signer bit); the key match stops a rotated key inheriting a stale signer verdict.
369373
bool isVerifiedSignerForKey(NodeNum n, const uint8_t *key32);

src/mesh/Router.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ DecodeState perhapsDecode(meshtastic_MeshPacket *p)
815815
(ourNode = nodeDB->getMeshNode(p->to)) != nullptr && ourNode->public_key.size > 0) {
816816
pkiAttempted = true;
817817
LOG_DEBUG("Attempt PKI decryption");
818-
// Resolve the sender's public key only for actual PKI-decrypt candidates: prefer NodeDB
819-
// (hot store or warm tier), else a not-yet-committed key held during an in-progress
820-
// key-verification handshake. On a full NodeDB miss, copyPublicKey() falls through to a
821-
// linear scan of TrafficManagement's large NodeInfo cache, so it must not run for every
822-
// encrypted channel packet from an unknown sender - only for packets we might decrypt.
818+
// Resolve the sender's key only for actual PKI-decrypt candidates, not every encrypted channel
819+
// packet: copyPublicKeyForDecrypt() can fall through to a linear scan of TrafficManagement's large
820+
// NodeInfo cache. It returns authoritative keys (hot/warm), or a cold-tier cache key only when it is
821+
// signer-proven - an unverified TOFU cache key must not back authenticated (pki_encrypted, p->from)
822+
// DM attribution.
823823
meshtastic_NodeInfoLite_public_key_t remotePublic = {0, {0}};
824-
bool haveRemoteKey = nodeDB->copyPublicKey(p->from, remotePublic);
824+
bool haveRemoteKey = nodeDB->copyPublicKeyForDecrypt(p->from, remotePublic);
825825
// A pending key is an unverified identity claim supplied by whoever opened the handshake, so it is
826826
// accepted only for the exchange itself (checked after decode). perhapsEncode applies the same rule.
827827
bool havePendingKey = false;

0 commit comments

Comments
 (0)