Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ if(NOT MOONBASE_JUCE_MODULE_ONLY)
tests/inventory_tests.cpp
tests/licensing_tests.cpp
tests/process_dedup_tests.cpp
tests/release_access_tests.cpp
tests/store_tests.cpp
tests/sub_product_tests.cpp
tests/validator_tests.cpp
Expand All @@ -191,7 +192,8 @@ if(NOT MOONBASE_JUCE_MODULE_ONLY)
# generator puts the binary. CMAKE_CURRENT_SOURCE_DIR is forward-slashed on
# every platform, so this needs no escaping.
target_compile_definitions(moonbase_tests PRIVATE
MOONBASE_FINGERPRINT_VECTORS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/tests/vectors/fingerprint-vectors.json")
MOONBASE_FINGERPRINT_VECTORS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/tests/vectors/fingerprint-vectors.json"
MOONBASE_RELEASE_ACCESS_VECTORS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/tests/vectors/release-access-vectors.json")
moonbase_apply_sanitizer(moonbase_tests)
include(doctest)
doctest_discover_tests(moonbase_tests)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ matching script and commit its output in the same change.
| Path | Source of truth | Refresh with |
| --- | --- | --- |
| `modules/moonbase_licensing/moonbase/` | `include/moonbase/` | `scripts/sync-juce-module.sh` |
| `FINGERPRINT_SPEC.md`, `tests/vectors/fingerprint-vectors.json` | `@moonbase.sh/licensing` | `scripts/sync-fingerprint-vectors.sh` |
| `FINGERPRINT_SPEC.md`, `tests/vectors/fingerprint-vectors.json`, `tests/vectors/release-access-vectors.json` | `@moonbase.sh/licensing` | `scripts/sync-fingerprint-vectors.sh` |

`sync-juce-module.sh` is a byte-exact mirror with `--delete`, so **never hand-edit
anything under `modules/moonbase_licensing/moonbase/`**; the next sync reverts it. Any
Expand Down
87 changes: 85 additions & 2 deletions docs/core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,87 @@ even when calling `validate_token_online` — the SDK never contacts the API for
them. Use `validate_token_local` directly when you want the local-only check
explicitly.

## Licenses that cover some versions

A license bought outright can cover only some versions of your app: the releases
published while its updates lasted ("12 months of updates"), or every version up to
a major ("versions up to 2.x"). It never expires because of it; it just doesn't cover
the versions after that. `license::release_access` says what it covers, and is empty
for a license that covers every version:

- `updates_until`: releases published until then are covered, and every version while
it has not passed.
- `up_to_major`: every version whose major is at most this is covered.
- `up_to_version`: once updates have ended, the last version published before they
did, covered along with every older one. Empty while updates last, and when nothing
was published before they ended (then every version is covered).

The limits add up: a license with both covers a version that either one covers.

Set `application_version` to the version that has to be covered. A license that
doesn't cover it throws `release_not_covered_error` (`error_type::release_not_covered`).
For an online license, `validate_token_online` leaves that to Moonbase when it asks
it, since Moonbase knows of an upgrade bought since the token was issued. The device
judges it by its own clock when Moonbase isn't asked: for an offline license, within
`online_validation_min_interval`, and when Moonbase can't be reached within the grace
period. `validate_token_local` and `read_offline_license` check it too, but
`get_requested_activation` does not: Moonbase activates only a license that covers the
version the request named, and the seat is taken by then. Set
`enforce_release_access = false` to turn the check on the device off; Moonbase checks
either way. A version that can't be read is not checked. `parse_app_version` reads one
the way Moonbase does: an optional leading `v`, then two to four numbers (a fourth is
ignored), with any `-beta` or `+build` suffix dropped, so `3.0.0-beta.2` is judged as
3.0.0.

An offline license is never checked online, so it is judged by what its token said when
the license file was made. A version limit ("up to 2.x") holds for good, and so does a
time limit in a file made after updates ended, which names the last version covered. A
file made while updates last can't name it, so once they end it keeps covering later
versions until the customer downloads a new license file, which does. Downloading a
later release is still refused when the product's downloads are limited to owners.

`release_not_covered_error` derives from `license_invalid_error`, so code that refuses
to run on an invalid license refuses here too. But don't delete the stored license for
it: it still covers the versions it did, so the customer can go back to one of them,
or upgrade and keep going. Catch it first and offer the upgrade:

```cpp
try {
auto validated = licensing.validate_token_online(local->token);
// unlock
} catch (const moonbase::release_not_covered_error& ex) {
// Keep the license. validate_token_online already stored the copy Moonbase
// sent along with the refusal (ex.license()).
offer_upgrade(ex.app_version(), ex.release_access(), ex.upgrade_url());
} catch (const moonbase::license_invalid_error&) {
licensing.store().delete_local_license(); // revoked, or not for this device
}
```

`upgrade_url()` is where the customer buys the upgrade or renewal. Only Moonbase knows
it, so it is empty when the device refused, and when the store sells none. Moonbase's
browser activation page offers the upgrade as well, to a signed-in customer, and then
activates the device, so starting a `request_activation` works without a link.

To check another version, such as an update before offering to download it, use
`covers_version`:

```cpp
if (!moonbase::covers_version(license, latest_version)) {
// offer the upgrade along with the update
}
```

`covers_version(license, version, now)` applies the same rule as Moonbase and every
other Moonbase SDK. The vendored
[`release-access-vectors.json`](../tests/vectors/release-access-vectors.json) pins it
down case by case. For downloads, `inventory_client::get_release` says whether the
customer's licenses cover a release (`release_covered`, with `release_access` and
`upgrade_url`), `can_download` takes that into account, and `get_download_url` throws
`release_not_covered_error` for a release they don't cover. `revoke_activation` and
the add-on calls never judge the version, so a license can always be deactivated and
its add-ons managed.

## Revoking an Activation

To free up the activation seat for the current device — typically wired to a
Expand Down Expand Up @@ -319,6 +400,7 @@ trying again can help:
| --- | --- | --- |
| `api_error` | No definitive answer. The API was unreachable (`status_code()` is 0), rate limited (429), failing (5xx, including the gateway's own 502 and 504), or something other than the API answered, such as a captive portal | Retry later; `retry_after()` says when, if the server did |
| `license_invalid_error` | The API refused the license for good: a bad signature or product, or a revoked license or activation | Lock, and offer to activate again |
| `release_not_covered_error` | The license is valid, but doesn't cover `application_version`. A `license_invalid_error` | Lock, keep the license, and [offer the upgrade](#licenses-that-cover-some-versions) |
| `license_expired_error` | The license has expired: a trial ended, or a subscription lapsed | Lock, and offer to buy |
| `store_closed_error` | The merchant closed their Moonbase account. No verdict on the license | Treat it like being offline |
| `activation_request_error` | A browser activation request can never complete | Start a new request |
Expand All @@ -334,13 +416,14 @@ How each call maps what the API returns:
| | 404 (no such product or account) | `api_error` |
| `get_requested_activation` | 204 or 404 | `std::nullopt` |
| | 400 | `activation_request_error` |
| `validate_token_online`, `revoke_activation` | 400 | `license_invalid_error` (`license_expired_error` when `errorType` is `LicenseExpired`) |
| `validate_token_online`, `revoke_activation` | 400 | `license_invalid_error` (`license_expired_error` when `errorType` is `LicenseExpired`, `release_not_covered_error` when it is `ReleaseNotCovered`) |
| | 403 or 404 | `api_error`, covered by the grace period |
| `activate_sub_product`, `request_sub_product_trial`, `list_sub_products` | 400 with `errorType` `LicenseInvalid`, `LicenseRevoked` or `LicenseActivationRevoked` | `license_invalid_error` (`license_expired_error` for `LicenseExpired`) |
| | 400 with `errorType: NoEligibleLicense` | `no_eligible_license_error` |
| | any other 400 | `operation_not_supported_error` with the server's reason |
| | 404 | `api_error` |
| `inventory_client` | any failure but a closed store | `api_error` with the status; these endpoints never judge the license |
| `inventory_client` | 403 with `errorType: ReleaseNotCovered` | `release_not_covered_error` with the upgrade link: the customer's licenses don't cover the release |
| | any other failure but a closed store | `api_error` with the status; these endpoints never judge the license |
| any | 410 with `errorType: StoreClosed` | `store_closed_error`, read before the status |
| any | 429, 5xx, a transport failure | `api_error` |

Expand Down
50 changes: 48 additions & 2 deletions docs/juce-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ The screens:
- **Add-ons** (opt-in): the product's add-ons, each with where it stands on this
computer and a Try free, Buy or Activate action. See [Add-ons](#add-ons).
- **Trial expired** — a locked "trial has ended" screen with Unlock / Activate offline.
- **Upgrade needed.** A locked screen for a license that doesn't cover this version of
the app, such as one whose updates ended before it came out. It says what the license
covers and offers the upgrade, and the license stays stored; see
[Licenses that cover some versions](#licenses-that-cover-some-versions).
- **Update available.** Shown when a validated license reports a released version
(the `current_release_version` / `p:rel` claim) newer than the app version. Loads the
release notes from the inventory endpoints and downloads the new installer for the
Expand Down Expand Up @@ -271,7 +275,8 @@ you add hidden with `addChildComponent` shows when it is needed.
subscription or offline license reached its end date), `Invalid` (Moonbase no longer
accepts it: revoked, or bound to another device) or `Unverified` (not
checked online within `onlineGracePeriod`). A trial that ends gets the **Trial
expired** screen instead. The copy is in `config.strings` (`deactivatedTitle`,
expired** screen instead, and a license that doesn't cover this version of the app
the **Upgrade needed** screen (`NotCovered`). The copy is in `config.strings` (`deactivatedTitle`,
`licenseExpiredBody`, and so on), and `lockReason()` goes back to `None` once a
license is loaded. A custom UI can read it from `onLicenseChanged(false)`.
- **It steps back when the license returns.** If the overlay only opened for the lock
Expand Down Expand Up @@ -680,7 +685,10 @@ Details / Trial screen (it never interrupts the locked Expired screen). It then:
applies it: a full (non-trial) license owns the product and can download; a trial cannot
download from an owners-only product (the default). When the license isn't entitled, the
screen swaps the Download button for an **Unlock full version** CTA and a short note, so
the user never hits a 403 (`updateInfo().canDownload`).
the user never hits a 403 (`updateInfo().canDownload`). When Moonbase says the customer's
licenses don't cover the new version, the screen offers the upgrade instead and says what
they cover (`updateInfo().covered`, `releaseAccess` and `upgradeUrl`; see
[Licenses that cover some versions](#licenses-that-cover-some-versions)).

Both inventory requests authenticate with the license token via the
`Authorization: LicenseToken <jwt>` scheme (`moonbase::inventory_client`). Observe
Expand Down Expand Up @@ -713,6 +721,44 @@ beside the license (`<license>.state.json`); that file (`ActivationState`) is th
place for client state that should survive restarts, so future cached/remembered values
live there too.

## Licenses that cover some versions

A license bought outright can cover only some versions of the plugin: those released
while its updates lasted ("12 months of updates"), or every version up to a major
("versions up to 2.x"). Moonbase checks the running version against it on every online
validation, and the module checks it on this computer when Moonbase isn't asked, so set
`config.applicationVersion` (or rely on `JucePlugin_VersionString`) to the version that
has to be covered.

A license that doesn't cover the running version locks the plugin, like a trial that
ended, but stays stored: it still covers the versions it did, so the customer can go
back to one of them. The **Upgrade needed** screen names the version, says what the
license covers, and offers:

- **Upgrade license**, or **Renew updates** for a license whose updates ended
(`controller().upgradeLicense()`). It opens the upgrade page Moonbase named for the
license. Without one (the license was judged on this computer, offline or moments
after a check), it starts an online activation instead: Moonbase's activation page
offers the upgrade to a signed-in customer where the store sells one, then activates
this computer on it.
- **Already upgraded? Check again** (`controller().refreshLicense()`), which unlocks once
the upgrade has gone through. An offline license is never checked online, so it gets a
link to load the upgraded license file instead.

An offline license is judged by its license file alone. A version limit holds either way,
but a time limit in a file made while updates lasted can't say which version came last,
so once the updates end that file keeps covering later versions until the customer loads
a new one (see [the core SDK guide](core-sdk.md#licenses-that-cover-some-versions)).

Instances share the license file, so this works both ways: an upgrade another instance
picks up unlocks this one, and a refusal another instance gets from Moonbase locks it.

For a custom UI, `controller().notCovered()` holds the license, the version it doesn't
cover, what it covers (`releaseAccess`) and the upgrade link (`upgradeUrl`, empty when
Moonbase didn't name one), and `lockReason()` is `LockReason::NotCovered`.
`config.notCoveredTitleText()` and `config.notCoveredBodyText()` give the built-in copy,
which `config.strings.notCoveredTitle` and `notCoveredBody` override.

## Telemetry / analytics

Off by default. One flag attaches JUCE system + host metadata to every activation and
Expand Down
22 changes: 19 additions & 3 deletions examples/juce/MoonbaseJuceBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,12 @@ class MoonbaseUnlockStatus : public juce::OnlineUnlockStatus
std::move(onComplete));
return;
}
local = licensing_->validate_token_local(stored->token);
// Whether an online license covers this app version is Moonbase's
// call in step 2: it knows of an upgrade bought since the token was
// issued. Only an offline license is judged here.
local = licensing_->validator().validate_token_ignoring_release_access(stored->token);
if (local->method == moonbase::activation_method::offline)
licensing_->validator().ensure_covers_application_version(*local);
}
catch (const std::exception&)
{
Expand All @@ -393,8 +398,19 @@ class MoonbaseUnlockStatus : public juce::OnlineUnlockStatus

// Optimistic unlock from the local check, marshalled to the message
// thread (no callback yet). The final state may override this once
// the online check resolves.
deliver({AsyncValidationOutcome::Refreshed, *local}, {});
// the online check resolves. Not for a version the license doesn't
// cover on this computer: that waits for Moonbase's answer.
bool coveredHere = true;
try
{
licensing_->validator().ensure_covers_application_version(*local);
}
catch (const moonbase::release_not_covered_error&)
{
coveredHere = false;
}
if (coveredHere)
deliver({AsyncValidationOutcome::Refreshed, *local}, {});

// Step 2: online check on a background thread.
auto licensingHandle = licensing_;
Expand Down
Loading
Loading