Support public-key prefixes and lists in signed fleet commands

This commit is contained in:
mikecarper committed 2026-10-08 17:32:05 -07:00
1 parent 39394a255a
commit a91ec9407a
12 files changed
+756 -52

No files matched your search

+23
View File
@@ -26,6 +26,9 @@ public:
static constexpr size_t SignatureSize = 64;
static constexpr size_t MaxCommandLength = 72;
static constexpr size_t HeaderSize = 29;
static constexpr size_t MinHeaderSize = 14;
static constexpr size_t MaxTargetBytes = 86;
static constexpr size_t MaxTargetCount = 17;
static constexpr size_t MaxPayloadLength = 165;
static constexpr uint32_t MinEpoch = 1735689600UL; // 2025-01-01 UTC
static constexpr uint32_t MaxLifetime = 600;
@@ -34,13 +37,25 @@ public:
struct Decoded {
uint32_t sequence;
uint32_t expires;
bool broadcast;
char command[MaxCommandLength + 1];
};
struct Targets {
uint8_t length;
uint8_t count;
// Each record is a length/type byte (4, 6, or 16) followed by that many
// bytes. Prefixes are raw public-key bytes; complete keys are SHA-256/128.
uint8_t data[MaxTargetBytes];
};
static bool privateKeyAllowed(const uint8_t* key);
// "all" becomes the reserved zero target; otherwise require one complete
// public key and derive the first 16 bytes of SHA-256, not a short node ID.
static bool parseTarget(const char* text, uint8_t* target);
// Parse one bounded token containing comma-separated 8-, 12-, or 64-digit
// public keys. "all" is accepted only alone and produces zero records.
static bool parseTargets(const char* text, size_t length, Targets& targets);
static bool commandAllowed(const char* command);
// Return the exact envelope size, or zero on invalid input. The signature
@@ -50,6 +65,14 @@ public:
const uint8_t* target, const char* command,
uint8_t* output, size_t capacity);
// Prefix/list requests use FMC2. "all" and a single complete key retain
// FMC1 compatibility. Targets and command share the packet budget, so valid
// lists can still be too large for a given command.
static size_t encode(const LocalIdentity& publisher, const uint8_t* key,
uint32_t sequence, uint32_t expires,
const Targets& targets, const char* command,
uint8_t* output, size_t capacity);
// Accept an exact envelope only: group framing owns padding validation.
// On success the caller must durably reject an old/repeated sequence before
// any mutation, and defer execution until the receive stack has unwound.