brinkhaustools/licence/mod.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//! Offline-verifiable, hardware-bound licences (feature `licence`).
//!
//! A licence is a signed text block the operator pastes into the product. It names
//! a product (and optionally a variant), the hardware identifiers it binds to
//! (**all** must be present), a validity window (open end = lifetime), and
//! product-defined features and quotas. Several licences add up: features are the
//! union, quotas the sum, over the valid ones. Without any valid licence a product
//! may run a trial ([`TrialRecord`]).
//!
//! What the crate does **not** decide: what a feature or quota means, which
//! durations enforce the licence (trial length, grace period, clock guard — keep
//! them out of user-editable settings), or where licences are stored. Those are
//! product decisions.
//!
//! The issuing side (FleetManager) holds the Ed25519 seed; products only embed
//! public keys. The Python variant (`brinkhaustools.licence`) implements the same
//! format; both are pinned by `test-fixtures/licence-vectors.json`.
//!
//! Protection limits, stated plainly: the binding stops a data directory from being
//! carried to another machine. It does not stop root on the host from copying a
//! machine-id or setting a MAC address.
mod codec;
mod evaluate;
mod format;
mod hardware;
mod trial;
#[cfg(test)]
mod vectors;
pub use codec::{base32_decode, base32_encode, canonical_json};
pub use evaluate::{
evaluate, evaluate_licence, EvaluationContext, Grant, GrantMode, LicenceEvaluation,
LicenceState, RejectReason,
};
pub use format::{
key_id, LicencePayload, LicenceRequest, Licensee, SignedLicence, SigningKey, TrustedKeys,
FORMAT_VERSION, LICENCE_PREFIX, REQUEST_PREFIX,
};
pub use hardware::{
identifier_hash, in_container, parse_cpuinfo_serial, parse_netadapter_json,
parse_reg_query_value, parse_source_spec, Binding, ExplicitSource, HardwareIdentifier,
HardwareProfile, HardwareSources, IdentifierKind, ProfileProblem, DEFAULT_HOST_ROOT,
};
pub use trial::{
installation_id, random_uuid, ClockMark, ClockStatus, TrialEnd, TrialPolicy, TrialRecord,
TrialStatus,
};
/// Name of the fleet command that delivers a licence to an instance.
/// Payload: `{"licence": "<text block>"}`.
pub const FLEET_COMMAND_INSTALL_LICENCE: &str = "install-licence";
/// Errors of the licence format and state files.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum LicenceError {
#[error("text block does not start with {0}")]
Prefix(String),
#[error("text block is not valid Base32: {0}")]
Encoding(String),
#[error("text block is incomplete or mistyped (check bytes do not match)")]
Incomplete,
#[error("payload invalid: {0}")]
Payload(String),
#[error("unsupported format version {0}")]
UnsupportedVersion(u32),
#[error("signed with unknown key {0}")]
UnknownKey(String),
#[error("signature invalid")]
Signature,
#[error("key: {0}")]
Key(String),
#[error("state file: {0}")]
State(String),
}