Reference

Licensing integration

Activate a device, verify the signed grant, enforce features and trial terms, and pass the release licensing checklist.

Every Acruz family application enforces a signed device entitlement before it offers licensed operations. Montju is authoritative for plans, purchases, trials, renewals, expiry, revocation and device limits; the application verifies the signed grant locally. A successful installation or a renderer flag is never a licence.

This page describes the contract an application implements. The shared primitives are in sdk/core/rust/src/licensing.rs (acruz-runtime::licensing); Acruz One uses the same server endpoints and grant format.

Prerequisites

  • The application is registered with Montju and has an approved package name (com.example.app). The grant audience is exactly that package name.
  • A license plan exists for the application. Its duration_days, device_limit, offline_hours (1–72) and features are frozen into the customer's licence at purchase.
  • The application signs the customer in with the platform's OAuth/OIDC flow and calls the licensing endpoints with that bearer token. Never ship a client secret.

Device identity

At first run the application generates an Ed25519 key pair for this installation and keeps the private key in OS-protected storage (Windows Credential Manager, DPAPI or an equivalent). The server never receives a raw hardware serial.

The hardware digest binds the activation to this machine and this key:

use acruz_runtime::licensing::hardware_hash;

let public = device_key.verifying_key().to_bytes();
let hardware = hardware_hash(machine_guid, volume_serial, &public);

machine_guid and volume_serial are collected locally; the mixing rule is published so every family application produces the same digest for the same machine. Treat drive serials as a secondary signal: they can be absent or replaced. Recovery is an explicit customer action (deactivate the old device, then activate the new one), not a silent rebind.

Activation flow

Step Endpoint (bearer required) Purpose
1 POST /api/v1/licenses/{license}/challenge Bind a short-lived nonce to the licence, device key and hardware digest
2 local Sign the canonical challenge JSON with the device key
3 POST /api/v1/licenses/{license}/activate Prove possession; the server locks the licence row, checks the device quota and returns the signed grant
4 local Verify the grant and cache it for offline use

Challenge request body:

{"device_public_key": "<canonical base64>", "hardware_hash": "<64 lowercase hex>"}

Challenge response: challenge_id, nonce, license_id, device_public_key, hardware_hash, expires_at. The device signs exactly this canonical compact JSON with sorted keys:

{"challenge_id":"…","device_public_key":"…","hardware_hash":"…","license_id":"…","nonce":"…"}

Activation request: challenge_id, nonce, signature, label (1–120 printable characters) and renew. The response is a Grant:

{"payload": {"schema_version": 1, "issuer": "https://montju.com", "audience": "com.example.app",
  "license_id": "…", "activation_id": 9, "device_key_hash": "…", "hardware_hash": "…",
  "plan": "…", "features": ["…"], "issued_at": 0, "refresh_after": 0,
  "expires_at": 0, "offline_until": 0, "key_id": "…"},
 "signature": "<base64 Ed25519>"}

The SDK performs every check the server and client must agree on:

use acruz_runtime::licensing::{
    activation_request, challenge_proof, challenge_request, hardware_hash, parse_challenge,
    verify_activation, verify_challenge,
};

let hardware = hardware_hash(machine_guid, volume_serial, &public);
let request = challenge_request(&public, &hardware)?;                 // POST .../challenge
let challenge = parse_challenge(&response)?;
verify_challenge(&challenge, license_id, &public, &hardware, now)?;
let proof = challenge_proof(&challenge, &device_key)?;
let activate = activation_request(&challenge, &proof, "Office PC", renew)?; // POST .../activate
let grant = verify_activation(&response, &trusted_grant_keys, issuer, package_name,
    &public, &hardware, license_id, now, last_server_time)?;

verify_activation selects the trust key by the grant's key_id (SHA-256 of the key's SPKI), then verifies the signature, issuer, audience, device_key_hash, hardware_hash, lifetime and clock rollback. Pin the Montju grant public keys (primary plus overlap during rotation) in the application build; never accept a key from the response. The shared vector sdk/core/rust/fixtures/licensing-v1.json is signed and verified by both the Rust test and tests/Feature/LicensingContractTest.php, so the PHP and Rust canonical forms cannot drift.

Enforcement

  • Verify the grant in the native layer and authorize each protected operation against features. A renderer check alone is not a boundary.
  • Plan changes, renewal, cancellation and revocation take effect on the next refresh. refresh_after is the earliest sensible refresh time; expires_at is the hard limit.
  • Offline use is allowed only until offline_until for a cached, still-valid grant. Store the last trusted server time and refuse a clock that moves backwards by more than the documented tolerance.
  • A failed activation, a wrong-app grant, a copied device or a rolled-back clock is a refusal, not a silent fallback to an unlicensed mode.
  • Present activation, expiry and renewal states in Arabic and English, with a clear way to deactivate the current device and recover a replacement machine. Device management is customer-visible on the platform (/licenses/{uuid}).

Trial terms

A plan may carry trial_days. Starting a trial creates a normal device-bound licence marked as a trial with expires_at = now + trial_days, the plan's device limit, features and offline allowance. One customer can start one trial per application; the server refuses a second one.

The grant format does not change: read plan and expires_at to present the remaining trial time, and treat the grant exactly like a paid one until it expires. The platform does not auto-convert a trial into a paid licence — the customer buys a plan, which creates a separate licence. Do not block licensed operations on a client-side "trial" flag.

Storage

Keep the device private key, the cached grant and the last trusted server time in OS-protected storage (or an application database protected by it), never in localStorage, a renderer store or a log. The grant is not secret, but it is device-bound: do not upload it or share it between machines.

Verification checklist

  1. Activate on a clean profile, then launch the application directly (not through Acruz One) and confirm the licensed operation is enforced.
  2. Refresh after a plan change, renewal and cancellation; confirm the new terms are enforced no later than expires_at.
  3. Revoke the licence as an administrator; confirm no new grant is issued and the cached grant ends at its signed expiry.
  4. Copy the grant to another machine, change the hardware, and roll the clock back; each attempt must be refused.
  5. Fill the device quota, deactivate a device and activate a replacement.
  6. Go offline for the full offline_hours window; confirm licensed operations stop at offline_until.
  7. Start a trial, confirm the one-per-application rule and the displayed remaining days, then let it expire.

Record the results in the project's .tasks/ before a Release build. Missing or failed evidence blocks the release.