Expand description
§Moonbase licensing for Rust
License activation for desktop apps and audio plugins, against Moonbase: browser and offline activation, local RS256 validation with an offline grace period, revocation, add-ons, licenses that cover only some versions, pluggable storage and HTTP, and the cross-SDK device fingerprint, so a license activated by any Moonbase SDK validates here too.
The Rust port of moonbase-cpp.
use std::{thread, time::Duration};
use moonbase::{ActivationMethod, FileLicenseStore, Licensing, LicensingOptions};
let options = LicensingOptions::new(
"https://your-tenant.moonbase.sh",
"your-product",
"-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----",
);
let licensing = Licensing::builder(options)
.store(FileLicenseStore::new("license.mb"))
.build()?;
// On startup: validate what is stored, re-checking online when it is due.
if let Some(license) = licensing.load_and_validate()? {
println!("Licensed to {}", license.issued_to.email);
return Ok(());
}
// Otherwise activate through the browser; the license is stored once it lands.
let request = licensing.request_activation(ActivationMethod::Online)?;
println!("Open {}", request.browser_url);
let license = loop {
thread::sleep(Duration::from_secs(2));
if let Some(license) = licensing.complete_activation(&request)? {
break license;
}
};
println!("Activated for {}", license.issued_to.email);§What the SDK guarantees, and what it leaves to you
It answers one question soundly: is this license valid, for this product, on
this machine, right now? Tokens are RS256 JWTs verified against the public key
you embed with the algorithm pinned, bound to your product by audience, and to
this machine by a device id recomputed from hardware on every validation. It
ships no anti-debugging, obfuscation or tamper detection: hardening only works
when it is specific to your binary. See docs/security.md.
Modules§
- fingerprint_
spec - The Moonbase device fingerprint specification, version 2.
- serde_
iso8601 - Serde adapters for a
SystemTimeas the license file writes one:YYYY-MM-DDTHH:MM:SSZ, in UTC. For types of your own that carry a license’s times, as#[serde(with = "moonbase::serde_iso8601")], ormoonbase::serde_iso8601::optionfor anOption<SystemTime>. - version
- Just enough Semantic Versioning to decide whether the license’s released
version (
p:rel) is newer than the running app.
Structs§
- Activation
Request - A browser activation in progress. Send the user to
browser_url, then poll withLicensing::get_requested_activation. - ApiError
- A request that got no definitive answer.
- Device
IdDescription - A device id plus the provenance needed to reason about it: safe to log, show in an about box, or attach to a support ticket.
- Device
Identity - What a single read of the machine produced.
- Download
Target - A ready-to-fetch installer URL. The link is presigned and short-lived (the backend expires it after about 15 minutes).
- File
License Store - Persists the validated license as JSON in a file, in the same format as the C++
SDK’s
file_license_store. - Http
Request - Http
Response - Inventory
Client - Client for the inventory endpoints.
- License
- A validated license.
- License
Client - The raw client API. Most apps use
Licensing, which wraps this with storage, throttling and the offline grace period. - License
Validator - Validates license tokens locally: signature, audience, issuer, claims, expiry and device binding.
- Licensing
- The SDK’s entry point: activation, validation, offline licenses, revocation, add-ons and storage, for one product.
- Licensing
Builder - Builds a
Licensingwith a custom store, device id resolver or transport. - Licensing
Options - Connection and validation settings.
- Memory
License Store - Keeps the license in memory for the life of the process. The default, so nothing is persisted unless you choose a store.
- Migrating
Device IdResolver - Binds the current fingerprint while still recognising ids this device was bound to before: the migration path off an older algorithm without a flag day.
- Moonbase
Device IdResolver - The cross-SDK device id: what every Moonbase SDK computes on this machine.
- Moonbase
Device IdResolver Options - Product
- The licensed product, from the token’s
p:*claims. - Release
Access - Which versions of the app a license covers, when it doesn’t cover every one.
- Release
Info - A release’s plain-text notes, plus enough to know an installer exists and who may download it.
- Release
NotCovered - A license that is valid, but doesn’t cover the version of the app that runs: it
covers only the releases published while its updates lasted, or versions up to
some major. Carried by
Error::ReleaseNotCovered. - Static
Device IdResolver - A fixed identity. Useful in tests, and for apps that source the device id from somewhere else entirely.
- Storage
Error - Reading or writing the stored license failed, or its lock: a
LicenseStore’s own trouble, which says nothing about the license. The I/O failure behind it, when there was one, is itssource, andio_errorhands it over for a look at its kind. - Store
Lock Guard - Exclusive access to a store for as long as it is held, across processes when
the store is backed by something shared, such as a file. Returned by
LicenseStore::lock_for_update. - SubProduct
- One of the product’s add-ons that the merchant includes in its license, as the
license reports it for this device. To decide whether to unlock it, use
License::has_sub_product, which also checksexpires_at. - SubProduct
Catalog - The product’s add-ons that the customer can do something with: those they own or subscribe to, those on sale, and those whose trial can be started or is running on this device.
- SubProduct
Catalog Entry - One of the product’s add-ons as
Licensing::list_sub_productsreports it for this device. - SubProduct
Catalog Product - The add-on, with its prices when it is for sale, and whether the customer has it.
- SubProduct
Pricing - One way an add-on is sold.
- SubProduct
Recurrence - How a price recurs:
"OneOff", or"Recurring"with how often it renews ("Daily","Weekly","Monthly","Quarterly"or"Yearly"). - SubProduct
Seats - Seats across all of the customer’s licenses for an add-on.
- SubProduct
Trial Offer - An add-on’s trial on this device, or whether one can be started.
- Ureq
Transport - The bundled blocking transport: ureq with rustls, honouring the system proxy environment variables.
- User
- The customer the license was issued to, from the token’s
u:*claims.
Enums§
- Activation
Method - How a license was activated.
- Device
IdFallback - What to do when no hardware identity is readable.
- Error
- Everything the SDK can fail with.
- Error
Type - What kind of failure an
Erroris, as a plain value that can be persisted, logged or compared. - Method
- Platform
- The platform reported to Moonbase with each request, for analytics and platform-specific downloads.
- SubProduct
Trial Status - Where an add-on’s trial stands on this device.
Constants§
- VERSION
- This SDK’s version, as sent in the
User-Agent.
Traits§
- Device
IdResolver - Identifies this machine to Moonbase.
- Http
Transport - Performs one HTTP exchange.
- License
Store - Persists the validated license.
Functions§
- can_
download - May
licensedownload the installer for a release with these access flags?
Type Aliases§
- Device
Identity Reader - Overrides how the resolver reads the machine. Primarily for testing.
- Result
- The SDK’s result type.