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>
51 lines
2.0 KiB
C++
51 lines
2.0 KiB
C++
#pragma once
|
|
#include "evo/network/admission.hpp"
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <span>
|
|
|
|
// Dev-only session grants for the M9 engineering client (ADR-0082). A grant is a
|
|
// fixed 108-byte record ("EVO-DEV-ONLY" marker, version, environment byte, claims)
|
|
// authenticated with HMAC-SHA256 from Mbed TLS PSA. It is not an account system,
|
|
// cannot be created or verified outside DeploymentEnvironment::dev, and never
|
|
// appears in logs. Production identity remains the M10.3 identity-provider adapter.
|
|
namespace evo::network {
|
|
inline constexpr std::size_t dev_grant_bytes = 108;
|
|
inline constexpr std::size_t dev_key_bytes = 32;
|
|
using DevGrant = std::array<std::uint8_t, dev_grant_bytes>;
|
|
enum class GrantError : std::uint8_t {
|
|
not_dev_environment,
|
|
invalid_key,
|
|
invalid_claims,
|
|
malformed,
|
|
wrong_marker,
|
|
unsupported_version,
|
|
wrong_environment,
|
|
bad_tag,
|
|
crypto
|
|
};
|
|
// Owns an imported PSA HMAC key (non-exportable). Move-only; destroys the key.
|
|
class DevGrantKey {
|
|
public:
|
|
[[nodiscard]] static std::expected<DevGrantKey, GrantError>
|
|
import(DeploymentEnvironment environment, std::span<const std::uint8_t> secret);
|
|
DevGrantKey(DevGrantKey&& other) noexcept;
|
|
DevGrantKey& operator=(DevGrantKey&& other) noexcept;
|
|
DevGrantKey(const DevGrantKey&) = delete;
|
|
DevGrantKey& operator=(const DevGrantKey&) = delete;
|
|
~DevGrantKey();
|
|
// Structural claim checks only (nonzero ids/scope, ordered times); admission
|
|
// applies the clock, lifetime, world/region and single-use rules.
|
|
[[nodiscard]] std::expected<DevGrant, GrantError> issue(const DevGrantClaims& claims) const;
|
|
// Constant-time tag check before any claim is trusted.
|
|
[[nodiscard]] std::expected<VerifiedGrant, GrantError>
|
|
verify(std::span<const std::uint8_t> grant) const;
|
|
|
|
private:
|
|
explicit DevGrantKey(std::uint32_t key) : key_{key} {}
|
|
std::uint32_t key_; // PSA key id; zero when moved-from.
|
|
};
|
|
} // namespace evo::network
|