Implement M9.6 narrow secure dev-session protocol
Add protocol v1: versioned, bounded frames (Hello, Welcome, Intent, IntentResult, environment/organism views, Close) carrying session, epoch and commit watermark, with an explicit little-endian canonical codec, a header-first FrameReader, seeded mutation tests and a libFuzzer target. SessionAdmission enforces world/region scope, grant lifetime and skew, single-use grants, one session per subject, epoch, replay, tick window and per-session rate. Dev identity is a 108-byte HMAC-SHA256 grant (PSA) that cannot be created or verified outside the dev environment. Transport security is TLS 1.3 only via pinned Mbed TLS 4.1.1 LTS with TLS 1.2, DTLS, tickets and PSK compiled out, AEAD suites, ECDHE groups and a pinned dev CA. Opt-in EVO_BUILD_NETWORK, new network CI suite. Sockets and region integration follow in M9.7. ADR-0082 records the decision. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#include "evo/network/protocol.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
// Any input: decoding never crashes, and an accepted message re-encodes to the same
|
||||
// bytes (no field is trusted or silently dropped). Also streams through FrameReader.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
|
||||
using namespace evo::network;
|
||||
const std::span<const std::uint8_t> bytes{data, size};
|
||||
FrameReader reader;
|
||||
for (std::size_t at = 0; at < size;) {
|
||||
const auto taken = reader.feed(bytes.subspan(at, std::min<std::size_t>(7, size - at)));
|
||||
if (!taken)
|
||||
break;
|
||||
at += *taken;
|
||||
if (*taken == 0 && !reader.take())
|
||||
std::abort();
|
||||
(void)reader.take();
|
||||
}
|
||||
const auto frame = decode_frame(bytes);
|
||||
if (!frame)
|
||||
return 0;
|
||||
std::vector<std::uint8_t> again;
|
||||
switch (frame->type) {
|
||||
case MessageType::hello:
|
||||
if (const auto m = decode_hello(*frame))
|
||||
again = *encode(*m);
|
||||
break;
|
||||
case MessageType::welcome:
|
||||
if (const auto m = decode_welcome(*frame))
|
||||
again = encode(*m);
|
||||
break;
|
||||
case MessageType::intent:
|
||||
if (const auto m = decode_intent(*frame))
|
||||
again = encode(*m);
|
||||
break;
|
||||
case MessageType::intent_result:
|
||||
if (const auto m = decode_intent_result(*frame))
|
||||
again = encode(*m);
|
||||
break;
|
||||
case MessageType::close:
|
||||
if (const auto m = decode_close(*frame))
|
||||
again = encode(*m);
|
||||
break;
|
||||
case MessageType::environment_view:
|
||||
if (const auto m = decode_environment_view(*frame))
|
||||
again = encode(m->first, m->second);
|
||||
break;
|
||||
case MessageType::organism_view:
|
||||
if (const auto m = decode_organism_view(*frame))
|
||||
again = encode(m->first, m->second);
|
||||
break;
|
||||
}
|
||||
if (!again.empty() && !std::equal(again.begin(), again.end(), bytes.begin(), bytes.end()))
|
||||
std::abort();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user