// M10.9c (ADR-0097) session protocol v4 fuzz target. Any input: // - decoding never crashes, and an accepted message has a stable canonical form // (decode, encode, decode, encode gives the same bytes: no field is silently dropped); // - an accepted snapshot chunk reaches the client's assembler without crashing; // - grant and ticket verification refuse it (no claim byte is trusted before the // signature: a fuzzer cannot forge ECDSA), also for the grant slot of a decoded Hello. // Built as a libFuzzer target with EVO_BUILD_FUZZER (Linux Clang) and as a seeded smoke // test everywhere (tests/fuzz/session_fuzz_smoke.cpp). #include "evo/network/handoff_ticket.hpp" #include "evo/network/replication.hpp" #include "evo/network/session_grant.hpp" #include "evo/network/session_protocol.hpp" #include #include #include #include #include #include #include #include namespace { using namespace evo::network; constexpr evo::world::WorldIdentity world{9, 2}; constexpr std::uint64_t region = 21; constexpr std::uint64_t now = 1'000'000; // Verifiers holding one fixed, valid key each (the fuzzer never has its private half). struct Verifiers { std::optional grants; std::optional tickets; Verifiers() { std::array scalar{}; scalar.back() = 0x2A; const auto issuer = GrantSigningKey::import(DeploymentEnvironment::dev, 1, scalar); auto g = GrantVerifier::create(DeploymentEnvironment::dev); if (!issuer || !g || !g->add_key(1, *issuer->public_key())) std::abort(); grants.emplace(std::move(*g)); const auto source = HandoffSigningKey::import(DeploymentEnvironment::dev, 4, scalar); auto t = HandoffVerifier::create(DeploymentEnvironment::dev, world, region); if (!source || !t || !t->add_key(4, 4, *source->public_key())) std::abort(); tickets.emplace(std::move(*t)); } }; const Verifiers& verifiers() { static const Verifiers v; return v; } void refused(std::span bytes) { const auto& v = verifiers(); if (!v.grants || !v.tickets || v.grants->verify(bytes) || v.tickets->verify(bytes, now)) std::abort(); (void)looks_like_handoff_ticket(bytes); } } // namespace extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) { const std::span bytes{data, size}; refused(bytes); const auto decoded = decode_session(bytes); if (!decoded) return 0; const auto canonical = encode_session(*decoded); const auto again = decode_session(canonical); if (!again || encode_session(*again) != canonical) std::abort(); if (const auto* hello = std::get_if(&*decoded)) refused(hello->grant); if (const auto* chunk = std::get_if(&*decoded)) { SnapshotAssembler client{world, chunk->epoch}; if (const auto accepted = client.accept(*chunk); accepted && *accepted && client.latest() == nullptr) std::abort(); // A completed snapshot must be applied. } return 0; }