Zum Inhalt springen

Die Entwickler-Doku gibt es nur auf Englisch.

C++ SDK

The C++ SDK is a header-only C++17 wrapper around the C SDK: sdks/cpp/include/license_sdk.hpp, namespace lsdk. Objects free themselves (RAII), errors are thrown as lsdk::Error.

Pre-release. Versions 0.x.y-alpha.n are test versions and not meant for production. lsdk::is_prerelease() returns true for them.

Get it

Link the CMake target license_sdk::cpp from sdks/c/CMakeLists.txt; it brings the C library along. Setup and prebuilt packages as in the C SDK.

With vcpkg, add the port license-sdk (overlay port from sdks/c/packaging/vcpkg/ports until it is in the official registry, see the C SDK) and link the same target:

{ "dependencies": ["license-sdk"] }
find_package(license-sdk CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE license_sdk::cpp)

With Conan, require license-sdk/<version> in conanfile.txt with the generators CMakeDeps and CMakeToolchain (recipe in sdks/c/packaging/conan until it is on ConanCenter, see the C SDK) and link the same target. Your profile needs compiler.cppstd=17 or newer.

Quickstart

#include "license_sdk.hpp"

lsdk::Config config("prod_01J...", lsdk::Environment::Live, "https://...", "1.4.0");
config.add_public_key("k4.public....");  // from the dashboard
lsdk::Client client(config);

auto started = client.start();  // local check now, renewal in the background
try {
  lsdk::Status status = started.status ? std::move(*started.status)
                      : started.error->code() == "not_activated"
                          ? client.activate(key_from_user)
                          : throw *started.error;
  bool pro = status.has_flag("pro");
  std::optional<int64_t> seats = status.limit("seats");
} catch (const lsdk::Error& e) {
  show_activation_screen(e.code());
}

A runnable version is sdks/cpp/examples/check.cpp (example_cpp <api_base> <license_key>).

Classes

Class What it is
Config Product, environment, Client API base URL, app version, public keys. Optional set_store, set_transport and set_config_schema
Client check, start, activate, sign_in, activate_with_account, activate_with_user_token, validate, heartbeat, deactivate, offline_request, import_offline, revocations_seq, remote_config, cached_remote_config. Thread-safe, not copyable
Account A signed-in account from sign_in (protocol section 6.3), in memory only: expires_at. Error code totp_required from sign_in: call again with the code
Status State, expiry, offline end, license term, end of the grace period (license_grace_until), IDs, release channel (channel()), entitlements, claims as JSON
RemoteConfig Values the schema allows: get_bool, number, integer, text, json, plus dropped, omitted, server_time
Started Result of start: status or error, and the renewal
Renewal Background renewal at a random point in the token's window, with retries (when the SDK renews). Usually let the destructor detach it; wait() can wait for hours. Destroying the Client ends a waiting renewal
Error kind(), code(), retry_after_s(), what() for logs
Store, Transport Interfaces for your own storage and HTTP, passed as std::shared_ptr

Remote config

config.set_config_schema(schema_json);  // from GET /v1/products/{id}/config-schema
lsdk::Client client(config);
lsdk::RemoteConfig rc = client.remote_config();  // or cached_remote_config() offline
bool dark = rc.get_bool("dark_mode").value_or(false);
int64_t max_projects = rc.integer("max_projects").value_or(5);

number, text, json(), dropped(), omitted() and server_time() complete the class. Only values the schema allows reach the app; the keys of the others are listed as dropped. Keys the server left out because the answer would have been too large are listed as omitted. What the schema may contain and how the cache works is explained in the Rust SDK.

Approved builds

If your product checks builds (build_check in the product settings), tell the client the SHA-256 of the program you ship:

config.set_build(lsdk::current_build_digest());

lsdk::build_digest(path) hashes another file; both throw config_invalid if the file cannot be read.

The SDK then sends it as build with validate, heartbeat, update checks, remote config and downloads (protocol, section 6.8). In your build pipeline, register the digest of the same file for its release and platform with POST /v1/releases/{id}/builds (sha256sum of the shipped file). With build_check set to deny, a build the server does not know gets an empty remote config and no updates; with flag it is only recorded. The license keeps working either way. The digest is what the device reports: it catches a patched program that still runs the SDK unchanged, not one whose author also patches the digest.

Devices from your own production

On hardware you build yourself, with the device's factory certificate uploaded to the product, pass the certificate (X.509, DER):

config.set_device_certificate(der);   // std::vector<std::uint8_t>

It goes beside the chip key with the call that creates the activation, and only where the device has a security chip (devices from your own production).

Updates

check_update(language) asks whether a newer release is published for this device's channel and platform (protocol, section 6.4) and returns std::nullopt when the app is current:

if (auto update = client.check_update("en")) {
  std::cout << "Version " << update->version << " is available.\n";
  if (update->notes) std::cout << *update->notes << "\n"; // plain text, never HTML
}

lsdk::UpdateInfo also holds channel, published_at (Unix seconds), notes_language, notes_truncated and required. The stored token stays as it is.

If the release has a file for this platform, ask for a short-lived link and fetch it (protocol, section 6.9):

if (update && update->file) {
  if (auto download = client.request_download(update->version)) {
    download->fetch("/tmp/" + download->file().name);  // checks size and SHA-256
    // Hand the file to your updater. The SDK never runs it.
  }
}

Download::fetch saves the bytes to a temporary file next to the destination and gives the file its final name only once size and SHA-256 match; an encrypted file (Rust SDK) is decrypted first. It fails with file_mismatch (kind verify) if the file does not match, server_unreachable if the link fails or has expired (ask for a new one), and storage_failed if the destination cannot be written. request_download gives std::nullopt if the server offers no file of that version to this device; with release keys, only files your signed list names are accepted. Fetching the file yourself is possible with the link (url()) and the size and SHA-256 of the file, but not for encrypted files.

  • Installing, checking the installation and rolling back are the job of your updater. The SDK never runs anything it gets.
  • required is true when the running version was blocked or is below the minimum version: install that release before the app carries on. validate then refuses with version_outdated; the update check still works.
  • After installing, report the outcome from the version that runs then: client.report_update(version, false) when the new version started, true when your updater went back to the earlier one. A rolled-back release is not offered to this device again, and too many rollbacks pause the rollout for every device (protocol, section 6.10).

To make sure not even a compromised server can offer a foreign, older or revoked version, sign your release lists in your pipeline as described in the Rust SDK and embed both public keys:

config.add_release_key("k4.public.…active…").add_release_key("k4.public.…reserve…");

From then on the update check accepts only versions the newest list names and does not revoke, never one older than the running app, and fails with token_mismatch otherwise (key_unknown while no list has arrived yet). release_list_seq() gives the sequence number of the newest list the client accepted.

Assets

Files outside releases, such as models or content packs: client.list_assets(language) returns std::vector<AssetInfo>, client.request_asset_download(name) an std::optional<AssetDownload> whose fetch(dest) saves and checks the file. See Assets for visibility, groups and an example.

Usage quotas

An entitlement of the plan with an integer value, such as "exports": 1000, is a quota for the whole term of the license. client.report_usage("exports", 1, report_id) reports what this device used and returns a UsageGrant with counted, used, limit and remaining (protocol, section 6.15). The same report_id counts once, so send it again with the same ID when an answer got lost; counted is then false. A report past the quota fails with quota_exhausted (kind server), counts nothing and keeps the stored license token. Vendors grant more units through the Management API.

Proxy calls

client.call_proxy("weather", R"({"city":"Berlin"})") calls an endpoint of yours through the platform, so its URL and credentials never ship in your app (protocol, section 6.16). It returns std::optional<ProxyResult>: empty if the license may not call a target of that name, else target, status and body_json (JSON text) of the endpoint's answer, or failure (timeout, unreachable, response_too_large, response_invalid). The body is optional. Set up the target in the Management API; your endpoint gets license, activation and plan with each call, signed like a webhook. A target name the SDK refuses (1 to 100 of a-z, 0-9, ., _, -) or a body that is not a JSON object or array of at most 8 KiB fails with config_invalid before anything is sent. The call needs an activation and keeps the stored license token.

Remote actions

config.set_action_schema(schema) takes the action definitions your app accepts, the answer of GET /v1/products/{id}/remote-action-types. client.remote_actions() then returns the actions sent to this device as std::vector<RemoteAction> with id, name, params_json (JSON text), sent_by (vendor or customer), issued_at and expires_at (Unix seconds) (protocol, section 6.17). Each action comes once and the list holds up to 20, oldest first; call again until it is empty. The SDK drops actions with an unknown name, parameters that do not fit your definitions or an expiry in the past. Without an action schema the call fails with config_invalid, and a schema the SDK cannot use fails when the client is created. The call needs an activation and keeps the stored license token. See Remote actions.

Crash reports

lsdk::CrashReporter queues crash and error reports on disk, Client::send_crash_reports sends them, and CrashReporter::install_terminate_handler turns uncaught exceptions into crash reports. Off until your app creates a reporter. See Crash and error reports.

Modules

lsdk::ModuleRuntime runs WebAssembly modules you signed with your release key, in a sandbox without files, network or processes, so you can change logic such as a quote without a release. See Modules.

Devices without internet

std::string request = client.offline_request("Lab PC 3");  // show as text and QR code
// Later, with the content of the license file (.lic):
lsdk::Status status = client.import_offline(file_content);
// From now on check() works without network, until the file's end.

The file works only on the device that made the request and only for that request. A changed file fails with signature_invalid, a file from another device with device_mismatch or nonce_mismatch. What offline licenses mean for revocation and refunds is explained in the Rust SDK.

Codes and offline behavior are those of the C SDK. Exceptions thrown in your Store or Transport never cross into the SDK; they count as a failed callback (storage_failed or server_unreachable).