Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
reload_trust_policy.hpp
Go to the documentation of this file.
1#pragma once
2
3// Opt-in "require signed reloads" policy for the developer reload watcher. By
4// default the dev loop loads whatever dylib appears (zero friction, the whole point
5// of local iteration). A collaborative/open project that holds a signing key can
6// flip this on so a shared dev build refuses unsigned code — the same fail-closed
7// verification consumers get, applied in dev.
8//
9// This resolves the trust material for a watched logic path: it looks for a signed
10// sidecar manifest next to the logic (<logic>.manifest.json) and hands the caller a
11// SwapPackTrust to pass into gate_logic_image (which does verify-before-load). Pure
12// except for reading the sidecar file; no dlopen here.
13
16
17#include <cstdint>
18#include <filesystem>
19#include <fstream>
20#include <string>
21#include <variant>
22#include <vector>
23
24namespace pulp::format::reload {
25
27 bool require_signed = false;
28 std::vector<std::uint8_t> trusted_public_key;
29};
30
32inline std::filesystem::path reload_sidecar_manifest_path(const std::filesystem::path& logic) {
33 return logic.string() + ".manifest.json";
34}
35
40using ReloadTrustDecision = std::variant<std::monostate, SwapPackTrust, ReloadOutcome>;
41
42inline ReloadTrustDecision resolve_reload_trust(const std::filesystem::path& logic_path,
43 const ReloadTrustPolicy& policy) {
44 if (!policy.require_signed) return std::monostate{};
45
46 const std::filesystem::path sidecar = reload_sidecar_manifest_path(logic_path);
47 std::error_code ec;
48 if (!std::filesystem::exists(sidecar, ec) || ec) {
50 "require_signed: no signed pack manifest at " + sidecar.string()};
51 }
52 std::ifstream in(sidecar, std::ios::binary);
53 std::string json((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
54 std::string err;
55 auto manifest = parse_swap_pack_manifest(json, err);
56 if (!manifest) {
58 "require_signed: unreadable manifest " + sidecar.string() + ": " + err};
59 }
60 // The pack root is the logic's directory; gate_logic_image verifies the manifest
61 // signature + that logic_path is a member with matching bytes.
62 return SwapPackTrust{logic_path.parent_path(), std::move(*manifest),
63 policy.trusted_public_key, /*srl=*/nullptr};
64}
65
66} // namespace pulp::format::reload
Definition build_fingerprint.hpp:23
std::filesystem::path reload_sidecar_manifest_path(const std::filesystem::path &logic)
Sidecar manifest path for a watched logic file.
Definition reload_trust_policy.hpp:32
std::variant< std::monostate, SwapPackTrust, ReloadOutcome > ReloadTrustDecision
The three outcomes of applying the policy to logic_path:
Definition reload_trust_policy.hpp:40
std::optional< SwapPackManifest > parse_swap_pack_manifest(std::string_view json, std::string &error)
Parse a swap-pack manifest from JSON.
Definition swap_pack.hpp:124
ReloadTrustDecision resolve_reload_trust(const std::filesystem::path &logic_path, const ReloadTrustPolicy &policy)
Definition reload_trust_policy.hpp:42
The verify-before-commit reload transaction — ties the Phase-0 primitives into one operation: load a ...
Definition reload_transaction.hpp:63
@ RejectedSignature
Swap-pack Ed25519 signature/signer verification failed, rejected before the image is loaded.
Definition reload_transaction.hpp:66
Definition reload_trust_policy.hpp:26
std::vector< std::uint8_t > trusted_public_key
the pinned signer, when required
Definition reload_trust_policy.hpp:28
bool require_signed
default OFF (unsigned dev loop)
Definition reload_trust_policy.hpp:27
Trust material for verifying a swap-pack-delivered logic image BEFORE it is loaded.
Definition reload_transaction.hpp:107
Sealed swap-pack manifest + per-file integrity.