Harden ESP32 identity entropy handling
This commit is contained in:
1 parent
ea3843e0b4
commit
a65769c96a
15 files changed
+414
-51
No files matched your search
@@ -43,6 +43,7 @@ does not reflect the GoogleTest count -- run the built binary directly
|
||||
| `test_flood_filter_policy` | `src/helpers/FloodFilterPolicy.h` | unordered blacklist matching; ordered 1/2/3-byte pbyte rule prefixes; original incoming scope classes and canonical region-name identity; channel-authentication cache key comparison; priority ordering and terminal stop masks; bridge-bucket and regionless channel-target selector encoding; `require=region` and per-channel scope-gate truth tables; fast/slow timing; adding, replacing, and preserving packet scope |
|
||||
| `test_logical_message_cache` | `src/helpers/LogicalMessageCache.h` | bounded logical-message mapping; stable retry timestamps; exact older retries after newer messages; stale and same-timestamp mismatch rejection |
|
||||
| `test_cli_command_utils` | `src/helpers/CLICommandUtils.h`, `src/helpers/ContactListOrder.h`, `src/helpers/TerminalCommandTracker.h`, `src/helpers/TerminalDisplayFilter.h` | terminal verb/argument/path parsing; routed receive labels; quiet display defaults and independent emergency filtering; favorite-first contact ordering; single-command reply matching, round-trip timing, and rollover-safe expiration |
|
||||
| `test_identity_generation` | `src/helpers/IdentityGeneration.h` | reserved-prefix rejection; bounded retries; final provisioned attempt; fail-closed exhaustion |
|
||||
| `test_remote_cli_reply_cache` | `src/helpers/RemoteCliReplyCache.h`, `src/helpers/RemoteCliRequest.h`, `src/helpers/RemoteCliTimeout.h` | authenticated logical-request matching; bounded recent-reply history; backward-compatible retry identity; 300% response timeout; empty-response completion; on-air truncation and clearing |
|
||||
| `test_companion_frame_queue` | `src/helpers/CompanionFrameQueue.h` | response/required/best-effort classification; reserved capacity; stable priority; safe eviction; message-waiting coalescing |
|
||||
| `test_serial_mode_switch` | `src/helpers/ArduinoSerialInterface.cpp`, `src/helpers/MultiSerialInterface.h` | independent terminal/seeder control-sequence recognition across reads and binary-frame boundaries; passthrough ownership of USB input and suppression of binary output; Bluetooth-only connection and pairing-request routing |
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "helpers/IdentityGeneration.h"
|
||||
|
||||
namespace {
|
||||
|
||||
mesh::LocalIdentity identityWithPrefix(uint8_t prefix) {
|
||||
mesh::LocalIdentity identity;
|
||||
memset(identity.pub_key, 0x5A, sizeof(identity.pub_key));
|
||||
identity.pub_key[0] = prefix;
|
||||
return identity;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(IdentityGeneration, AcceptsFirstUsableIdentity) {
|
||||
mesh::LocalIdentity identity;
|
||||
size_t calls = 0;
|
||||
|
||||
const bool generated = mesh::generateUsableLocalIdentity(
|
||||
identity, [&calls]() {
|
||||
++calls;
|
||||
return identityWithPrefix(0x42);
|
||||
});
|
||||
|
||||
EXPECT_TRUE(generated);
|
||||
EXPECT_EQ(1U, calls);
|
||||
EXPECT_EQ(0x42, identity.pub_key[0]);
|
||||
}
|
||||
|
||||
TEST(IdentityGeneration, RetriesBothReservedPrefixes) {
|
||||
mesh::LocalIdentity identity;
|
||||
size_t calls = 0;
|
||||
|
||||
const bool generated = mesh::generateUsableLocalIdentity(
|
||||
identity, [&calls]() {
|
||||
const uint8_t prefixes[] = {0x00, 0xFF, 0x7E};
|
||||
return identityWithPrefix(prefixes[calls++]);
|
||||
});
|
||||
|
||||
EXPECT_TRUE(generated);
|
||||
EXPECT_EQ(3U, calls);
|
||||
EXPECT_EQ(0x7E, identity.pub_key[0]);
|
||||
}
|
||||
|
||||
TEST(IdentityGeneration, AcceptsFinalProvisionedAttempt) {
|
||||
mesh::LocalIdentity identity;
|
||||
size_t calls = 0;
|
||||
|
||||
const bool generated = mesh::generateUsableLocalIdentity(
|
||||
identity, [&calls]() {
|
||||
++calls;
|
||||
return identityWithPrefix(
|
||||
calls == mesh::MAX_LOCAL_IDENTITY_GENERATION_ATTEMPTS ? 0x23 : 0x00);
|
||||
});
|
||||
|
||||
EXPECT_TRUE(generated);
|
||||
EXPECT_EQ(mesh::MAX_LOCAL_IDENTITY_GENERATION_ATTEMPTS, calls);
|
||||
EXPECT_EQ(0x23, identity.pub_key[0]);
|
||||
}
|
||||
|
||||
TEST(IdentityGeneration, FailsClosedAfterProvisionedAttempts) {
|
||||
mesh::LocalIdentity identity;
|
||||
size_t calls = 0;
|
||||
|
||||
const bool generated = mesh::generateUsableLocalIdentity(
|
||||
identity, [&calls]() {
|
||||
++calls;
|
||||
return identityWithPrefix(0xFF);
|
||||
});
|
||||
|
||||
EXPECT_FALSE(generated);
|
||||
EXPECT_EQ(mesh::MAX_LOCAL_IDENTITY_GENERATION_ATTEMPTS, calls);
|
||||
EXPECT_TRUE(mesh::hasReservedIdentityPrefix(identity));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in new issue
Block a user