#pragma once #include "evo/network/admission.hpp" #include #include #include #include #include // 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; 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 import(DeploymentEnvironment environment, std::span 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 issue(const DevGrantClaims& claims) const; // Constant-time tag check before any claim is trusted. [[nodiscard]] std::expected verify(std::span 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