Licensing¶
The platform is gated by an offline, asymmetrically-signed license file checked at startup. There is no license server and no online phone-home: the binary embeds an Ed25519 public key (XOR-scrambled at compile time), validates the signature on the configured .lic file, and refuses to initialise any module if validation fails. A 32-bit feature mask in the license enables or disables individual subsystems independently of the TOML [modules] table.
License File Layout¶
The on-disk file is Base64-encoded. Decoded, it is a packed 181-byte binary blob defined identically in usr/include/security/license_validator.hpp and usr/src/licensing.cpp:
#pragma pack(push, 1)
struct LicensePayload {
char magic[4]; // "MBSS"
uint8_t version; // 1
char customer_id[36]; // UUID, e.g. "550e8400-e29b-41d4-..."
int64_t expires_at; // Unix timestamp (UTC) of expiry midnight
uint32_t feature_mask; // 32-bit FEATURE_* bitmask
char hardware_id[64]; // /etc/machine-id, null-padded
}; // 117 bytes
#pragma pack(pop)
// followed by 64 bytes of Ed25519 signature → 181 bytes total
Field semantics:
magicdistinguishes a license from random base64 garbage.customer_idis logged at startup for traceability.expires_atis enforced inclusive — the license is valid until the start of the listed UTC day.feature_maskis the per-module gate. See Feature Mask.hardware_idbinds the license to a specific machine. The validator reads/etc/machine-id(falling back to/var/lib/dbus/machine-id) on Linux, or theIOPlatformUUIDon macOS (development hosts), and compares.
Validation Pipeline¶
LicenseValidator::load() runs every check in order; any failure causes startup to abort.
sequenceDiagram
participant Main as main.cpp
participant Utils as UTILS::setup
participant LV as LicenseValidator
participant Disk as platform.lic
participant Mach as /etc/machine-id
participant LKGT as var/lib/license/.lkgt
Main->>Utils: setup(argc, argv)
Utils->>LV: new LicenseValidator(lkgt_path)
Main->>LV: load()
LV->>Disk: read base64 file
LV->>LV: base64Decode → 181 bytes
LV->>LV: check magic == "MBSS", version == 1
LV->>LV: deobfuscatePublicKey() (XOR with KEY_SCRAMBLE)
LV->>LV: Ed25519 verify(payload, sig, pub)
alt invalid signature
LV-->>Main: false → process exits
end
LV->>Mach: read /etc/machine-id
LV->>LV: compare against payload.hardware_id
alt mismatch
LV-->>Main: false → process exits
end
LV->>LV: now() < expires_at?
alt expired
LV-->>Main: false → process exits
end
LV->>LKGT: read prior LKGT
LV->>LV: now() >= prior LKGT timestamp?
alt rollback detected
LV-->>Main: false → process exits
end
LV->>LKGT: write current timestamp + HMAC
LV-->>Main: true (also logs days_left and feature list)
Last-Known-Good-Time (LKGT)¶
The LKGT mechanism defends against clock-rollback attacks. After every successful validation the validator writes the current UTC time, with an HMAC-SHA256 trailer keyed off material derived from the public key, into a state file ([license] lkgt_path, shipped as ${BSS_HOME}/var/lib/license/.lkgt). On subsequent starts, the validator refuses to load if now() < stored_LKGT — the system clock has gone backwards since the last successful boot. The HMAC trailer prevents trivial tampering with the state file.
Public-key obfuscation¶
The Ed25519 public key is embedded as a 32-byte XOR-scrambled constant. deobfuscatePublicKey() un-scrambles it at runtime against KEY_SCRAMBLE (a 32-byte ASCII string also baked into the binary). This is not encryption — anyone with the binary and a debugger can recover the key — but it raises the bar for trivial binary patching that swaps in an attacker-controlled key.
Feature Mask¶
// include/security/license_validator.hpp
static constexpr uint32_t FEATURE_PREPAID = (1U << 0);
static constexpr uint32_t FEATURE_CDR_LOADER = (1U << 1);
static constexpr uint32_t FEATURE_STATS = (1U << 2);
static constexpr uint32_t FEATURE_BILLING = (1U << 3);
static constexpr uint32_t FEATURE_BILL_FMT = (1U << 4);
static constexpr uint32_t FEATURE_CRM = (1U << 5);
static constexpr uint32_t FEATURE_DIAMETER = (1U << 6);
static constexpr uint32_t FEATURE_ALL = 0x7FFFFFFFU;
Bits 7–30 are reserved for future modules. requireFeature(bit, name) returns true if the bit is set and writes an LM_ERROR log line if not. Modules that depend on a feature must call requireFeature before initialising; the TOML [modules] table is therefore advisory, with the license being the authoritative gate.
featureMaskToString(mask) produces a comma-separated, human-readable list for startup logs. A typical line looks like:
[main | 2026-04-30 12:00:00] License valid — customer=550e8400-... days_left=42 features=[PREPAID,CDR_LOADER,STATS,BILLING,BILL_FMT,CRM,DIAMETER]
License Generator¶
bin/licensing is a standalone tool used by the operator vendor, not by deployed customers. Its signing key must never be on a customer machine. The signing step is pluggable behind a LicenseSigner interface with two backends:
- Software (
PemFileSigner) — an Ed25519 PEM on disk. The dev/test path, and the historical behaviour: byte-for-byte identical output. - Hardware (
Pkcs11Signer) — a YubiKey (PIV slot 9c) reached over PKCS#11. The production path: the key is generated on-device and never leaves it.
The on-disk license format and the server-side validator are unchanged by which backend signs — the signature is the same pure Ed25519 either way.
bin/licensing --issue --customer UUID --expires YYYY-MM-DD --features HEX
(--hwid ID | --localhost)
[--privkey FILE | env MBSS_LICENSE_KEY=FILE] # software backend
[--yubikey [--module PATH] [--key-id HEX]
[--key-label STR] [--token-label STR]] # hardware backend
[--out FILE]
bin/licensing --pubkey-snippet (--pubkey FILE.pem | --yubikey [pkcs11 opts])
bin/licensing --pkcs11-list [--module PATH]
bin/licensing --keygen [--out-priv FILE] [--out-pub FILE] # dev / tests only
bin/licensing --inspect FILE.lic
bin/licensing --verify FILE.lic
The step-by-step operator runbook for signing a customer license on the YubiKey is in Operations → Issuing a License; the reference below covers the tool's surface.
--issue composes the LicensePayload, signs it through the chosen backend, and writes the Base64-encoded .lic. --yubikey and --privkey/MBSS_LICENSE_KEY are mutually exclusive. Two safety checks run on every issue (decision D8): the fresh signature is self-verified against the signing key before the file is written (a wrong slot or corrupt signature aborts the issue), and the tool warns — without failing — when the signing key does not match this build's compiled EMBEDDED_PUB_KEY, since such a license will not validate on the current binaries (expected during a key rotation).
For the hardware backend the PKCS#11 module is resolved from --module, then MBSS_PKCS11_MODULE, then the default libykcs11 locations; the user PIN comes from MBSS_YK_PIN or an interactive no-echo prompt — never from the command line. The default --key-id 02 is PIV slot 9c as exposed by ykcs11.
--pubkey-snippet prints the XOR-scrambled EMBEDDED_PUB_KEY C array (from a PEM or straight from the token) for pasting into both licensing.cpp and license_validator.cpp. --pkcs11-list enumerates tokens and their objects for diagnostics. --keygen still produces a software keypair for development and tests only — production keys are generated on the YubiKey (see Provisioning below). --inspect decodes a .lic without checking the signature; --verify runs the full signature/expiry check against the tool's embedded public key.
Key Custody (YubiKey)¶
Production licenses are signed by a YubiKey 5 (firmware ≥ 5.7.0, which added Ed25519 to the PIV applet) using PIV slot 9c (Digital Signature). ykcs11 exposes that slot as CKA_ID 0x02. The signing key is generated on-device and is non-exportable; PIV attestation proves it was generated on the hardware. The key policy is PIN once per session (so batch issuance stays usable) and touch always (so malware that has the PIN still cannot sign silently — every signature needs a physical touch).
| Threat | Software PEM | YubiKey (on-device key) |
|---|---|---|
| Key exfiltrated from the vendor machine | copy one file | impossible — non-exportable; attestation proves on-device generation |
| Malware signs licenses silently | yes, if it can read the PEM | no — a physical touch is required per signature |
| Stolen token | n/a | PIN-gated (3 tries → blocked); revoke by rotating the key |
Attestation artifacts for a provisioned key are written to var/lib/license/attestation/ (gitignored).
Provisioning¶
sbin/yubikey_license_provision.sh is the single, auditable place ykman is used to take a YubiKey to a ready-to-sign token:
sbin/yubikey_license_provision.sh generate [--slot 9c] [--touch always|cached] [--force]
sbin/yubikey_license_provision.sh import <private.pem> [--slot 9c] [--force]
sbin/yubikey_license_provision.sh status [--slot 9c]
generate (recommended) creates the non-exportable Ed25519 key on-device, a self-signed certificate, and the exported attestation chain, then prints the EMBEDDED_PUB_KEY snippet and the rotation checklist. import is the transitional mode for adopting the workflow with an existing PEM — EMBEDDED_PUB_KEY is unchanged so no rebuild is needed, but attestation then proves only device presence, not on-device generation; it offers to securely delete the PEM after you have verified issuance. status reports the PIV state and the slot-9c certificate. Preflight refuses to overwrite an occupied slot without --force and warns loudly if the PIV PIN/PUK/management key are still at factory defaults. For dry-runs, provision a retired slot (--slot 82, CKA_ID 05) so touching the real 9c stays a deliberate action.
On Linux, PC/SC must be running (pcscd + the ccid driver); on macOS it is built in. Installation prerequisites (ykman, and softhsm/opensc for the test ring) live in operations/installation.md; they are not duplicated here.
Key Rotation¶
Rotating the signing key (Mode B) rides a platform release:
sbin/yubikey_license_provision.sh generate→ new key in slot 9c, attestation exported.bin/licensing --pubkey-snippet --yubikey→ the new scrambled 32-byte array.- Paste it into
EMBEDDED_PUB_KEYin bothusr/src/licensing.cppandusr/src/security/license_validator.cpp, then rebuild and ship. - New licenses validate only on binaries built at/after step 3. Until the fleet is upgraded, keep re-issuing old-key licenses with the retained previous key — the tool's mismatch warning is the guard rail.
- Once every deployment runs the new binary, decommission (shred) the old key.
Testing the Licensing Tool¶
The licensing tests live in usr/share/tests/backend/tests/licensing/ in three rings, selected by pytest marker:
license— software path (SoftHSM/hardware not needed): byte-compatibility with the pre-refactor tool, keygen/issue/verify, the snippet helpers. Runs on every suite pass.pkcs11— the fullPkcs11Signerpath against a SoftHSM2 token; auto-skips unlesssofthsm/openscare installed.yubikey— real-device issue/verify; auto-skips when no YubiKey is present. Never runs in CI.
cd usr/share/tests/backend && source ../../../../sbin/dev_env.sh
.venv/bin/pytest tests/licensing -m "license or pkcs11"
Configuration¶
Reference: every TOML role file ships the same [license] section.
[license]
license_key = "${BSS_HOME}/var/lib/license/platform.lic"
lkgt_path = "${BSS_HOME}/var/lib/license/.lkgt"
Permissions: when an archive carries a pre-issued license, unpack.sh creates var/lib/license/ with mode 700 and installs platform.lic with mode 600 (TLS private keys in etc/certs/ likewise get 600). Signing keys never ship in an archive.
Failure Modes and Logging¶
Each failure path emits a critical log entry and the process exits with code -1:
- Missing or unreadable
.licfile →License validation failed. Shutting down. - Bad magic / version → same critical log; common after a malformed file or wrong format version.
- Signature mismatch → most common after a tampered file or after the platform's public key was rotated without a re-issued license.
- Hardware mismatch →
/etc/machine-iddiffers from the signed value; surfaces when a license is moved between machines. - Expiry → days remaining is negative; the startup line
days_left=Nwill show this with a negativeN. - LKGT rollback → the system clock has moved backward; can also surface after a virtual-machine snapshot revert.
There is no soft-fail, no grace period, and no retry. License is checked once at startup, not periodically; a license that expires while the process is running does not cause termination — it will be caught at the next restart.