Zum Inhalt springen

Die Entwickler-Doku gibt es nur auf Englisch.

C SDK

The C SDK is a stable C interface over the Rust SDK (crates/sdk-ffi). It has the same calls, states and error codes, and speaks protocol version 1. The C++ SDK, the C# SDK, the Python SDK, the Java SDK and later SDKs wrap it.

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

  • Header: sdks/c/include/license_sdk.h, generated from the Rust code with cbindgen. C99 or newer, also usable from C++.
  • Library: one shared library, liblicense_sdk.so (Linux), liblicense_sdk.dylib (macOS), license_sdk.dll with import library license_sdk.dll.lib (Windows). Prebuilt packages for the three systems come from the workflow SDK C and C++; the Linux library is built against glibc 2.17 and runs on distributions from 2014 on (CentOS 7, Ubuntu 14.04 and newer). Signed releases come as one archive per platform with an SBOM, the same layout as -DLSDK_PREBUILT_DIR expects.
  • CMake: sdks/c/CMakeLists.txt defines license_sdk::c and license_sdk::cpp. It builds the library with cargo, or uses a prebuilt package with -DLSDK_PREBUILT_DIR=<folder> (include/, lib/, bin/).
add_subdirectory(third_party/license_sdk/sdks/c license_sdk)
target_link_libraries(my_app PRIVATE license_sdk::c)
license_sdk_copy_runtime(my_app)  # puts the shared library next to the app

vcpkg: the port license-sdk installs the library and both headers from the signed release archives and checks each archive's SHA-512 before it unpacks it. Until the package is listed in the official vcpkg registry, use it as an overlay port from sdks/c/packaging/vcpkg/ports (copy the folder into your project or point to a checkout), for example in vcpkg-configuration.json:

{ "overlay-ports": ["third_party/license_sdk/sdks/c/packaging/vcpkg/ports"] }
{ "dependencies": ["license-sdk"] }
find_package(license-sdk CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE license_sdk::c)

Supported triplets: x64-windows, x64-linux, arm64-linux, x64-osx, arm64-osx (and their static variants; the library is always a shared library). The C++ wrapper is the default feature cpp; license-sdk[core] installs only the C header. On Windows vcpkg copies the DLL next to the app; license_sdk_copy_runtime(my_app) is available here too.

Conan: the recipe license-sdk in sdks/c/packaging/conan (Conan 2) installs the same signed release archives and checks each archive's SHA-256. Until the package is on ConanCenter, add it to your local cache or your own remote once:

conan create third_party/license_sdk/sdks/c/packaging/conan --version 0.1.0-alpha.1
conan upload license-sdk/0.1.0-alpha.1 -r my-remote   # optional, for your team and CI
[requires]
license-sdk/0.1.0-alpha.1

[generators]
CMakeDeps
CMakeToolchain
find_package(license-sdk CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE license_sdk::c)

Profiles: Windows x64, Linux x64 and arm64 (armv8), macOS x64 and arm64. The option cpp (default True) adds the C++ header and the target license_sdk::cpp. Conan's targets carry no license_sdk_copy_runtime; on Windows run the app from the conanrun environment or copy license_sdk.dll next to it.

Without CMake: add include/ to the include path, link the library, ship it next to the app. On Windows define LSDK_STATIC only if you link the static library license_sdk.lib yourself (it then also needs the system libraries Rust links on Windows).

Quickstart

#include "license_sdk.h"

lsdk_config *config = NULL;
lsdk_error *e = lsdk_config_new("prod_01J...", LSDK_ENVIRONMENT_LIVE,
                                "https://...",   /* your Client API base URL */
                                "1.4.0", &config);
if (!e) e = lsdk_config_add_public_key(config, "k4.public...."); /* from the dashboard */

lsdk_client *client = NULL;
if (!e) e = lsdk_client_new(config, &client);
lsdk_config_free(config);
if (e) { log_error(lsdk_error_message(e)); lsdk_error_free(e); return; }

/* At every start: check locally, no network needed. */
lsdk_status *status = NULL;
e = lsdk_client_check(client, &status);
if (e && strcmp(lsdk_error_code(e), "not_activated") == 0) {
  lsdk_error_free(e);
  e = lsdk_client_activate(client, key_from_user, NULL, &status);
}
if (e) {
  show_activation_screen(lsdk_error_code(e));
  lsdk_error_free(e);
} else {
  bool pro = lsdk_status_has_flag(status, "pro");
  lsdk_status_free(status);
}
lsdk_client_free(client);

A runnable version is sdks/c/examples/check.c (example_c <api_base> <license_key> after the CMake build).

Rules

  • Every function that can fail returns lsdk_error *: NULL on success, otherwise an error you free with lsdk_error_free. Out pointers are NULL after a failure.
  • Every object has one *_free function, and *_free(NULL) does nothing. Strings from accessors belong to their object and stay valid until it is freed.
  • All strings are UTF-8 and NUL-terminated.
  • A client is thread-safe; calls on one client run one after another.
  • A panic in the SDK never crosses the interface. It becomes internal_error.

Calls

Call Network What it does
lsdk_client_check No Verifies the stored license token: signature, product, environment, clock, offline end, device. Use it at every start and before gated features
lsdk_client_start Background check now, then validate on a background thread at a random point in the token's window, with retries (when the SDK renews). Usually let it run with lsdk_renewal_free; lsdk_renewal_wait can wait for hours. lsdk_client_free ends a waiting renewal and waits at most 5 seconds for one with a request or storage call in flight
lsdk_client_activate Yes Activates this device. The only call that reads hardware features for the first time. The device name comes from the user or is NULL
lsdk_client_sign_in Yes Signs the end customer in with their account at your company, for products with identity mode account or both (protocol section 6.3). Your app asks for email and password; the SDK sends them once and keeps neither. Returns an account valid for 10 minutes, kept in memory only. Error code totp_required: ask for the six digits of the authenticator app and call again with the code. Wrong email, password or code give invalid_credentials, five failures in a row rate_limited. Reads no hardware. Writes an lsdk_account *; lsdk_account_expires_at gives its end in Unix seconds, lsdk_account_free frees it
lsdk_client_activate_with_account Yes Activates this device with the account's license for this product, like activate with a key. invalid_credentials means the account expired or the password changed: sign in again
lsdk_client_activate_with_user_token Yes Activates this device for a user of your own account system, with a user token your backend signed. It sends the token once and keeps it nowhere; invalid_credentials means the token expired or does not verify, ask your backend for a new one. How your backend signs it: protocol section 6.5
lsdk_client_validate Yes Renews the token. Due when the state is LSDK_TOKEN_STATE_GRACE, and at least once a day
lsdk_client_heartbeat Yes Reports a running session, gives the seconds until the next heartbeat
lsdk_client_deactivate Yes Frees this device's activation and deletes the stored token
lsdk_client_offline_request No Starts an offline activation. Writes the request code to show as text or QR code; free it with lsdk_string_free. Reads hardware features like activate
lsdk_client_import_offline No Imports the license file issued for the pending request and stores its token
lsdk_client_revocations_seq No Sequence number of the revocation list this device holds; known is false if none
lsdk_client_remote_config Yes Fetches the remote config of the license and keeps the values the schema of lsdk_config_set_config_schema allows. Free it with lsdk_remote_config_free
lsdk_client_cached_remote_config No The last remote config answer while the stored token passes the check; NULL if none

A status gives the state, lsdk_status_expires_at, lsdk_status_offline_until, lsdk_status_license_expires_at (false for perpetual licenses), lsdk_status_license_grace_until (true and the end of the grace period once the term has ended, see concepts), license and activation ID, the release channel (lsdk_status_channel, for example beta, NULL if the token names none), entitlements (lsdk_status_has_flag, lsdk_status_limit, lsdk_status_variant) and all claims as JSON (lsdk_status_claims_json).

Token check for backends

lsdk_verify_license(product_id, environment, public_keys, public_key_count, license_token, now, last_server_time, &status) checks a license token that an app sent to your backend, without a client, storage or network: structure, key, signature, schema, product, environment, clock and offline end. The device check is skipped, because a backend cannot measure the app's device. now is the current time in Unix seconds, last_server_time is NULL or the latest server time you have seen. A malformed key gives kind LSDK_ERROR_CONFIG, a failed check kind LSDK_ERROR_VERIFY with the code of protocol section 7.2. The function holds no state and may be called from any thread.

Remote config

Set the product's schema from GET /v1/products/{id}/config-schema on the configuration, then fetch the values of the license (protocol section 6.6):

lsdk_config_set_config_schema(config, schema_json); /* before lsdk_client_new */

lsdk_remote_config *rc = NULL;
lsdk_error *e = lsdk_client_remote_config(client, &rc); /* or lsdk_client_cached_remote_config offline */
bool dark = false;
lsdk_remote_config_bool(rc, "dark_mode", &dark);
int64_t max_projects = 5;
lsdk_remote_config_integer(rc, "max_projects", &max_projects);
const char *banner = lsdk_remote_config_text(rc, "banner"); /* NULL if absent */
lsdk_remote_config_free(rc);

lsdk_remote_config_number reads any number, lsdk_remote_config_json all kept values as a JSON object. lsdk_remote_config_dropped and lsdk_remote_config_omitted give keys separated by commas. Offline, lsdk_client_cached_remote_config writes NULL if nothing is stored. 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:

uint8_t digest[32];
lsdk_error *e = lsdk_build_digest(NULL, digest); /* NULL: the running executable */
if (!e) e = lsdk_config_set_build(cfg, digest);

lsdk_build_digest(path, digest) hashes another file, for example a bundle; it gives config_invalid if the file cannot be read. Call lsdk_config_set_build before lsdk_client_new.

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.

Your own chip key

Where the app reaches the device's security chip itself, as on Android through the Android Keystore, pass the key as callbacks before lsdk_client_new. The SDK then binds by chip with it instead of the chip it finds on its own (security chip):

lsdk_chip chip = {
    .user_data = my_keys,
    .key = my_public_key,      // SubjectPublicKeyInfo DER of the product's P-256 key, or LSDK_STORE_NOT_FOUND
    .sign = my_sign,           // ECDSA P-256 with SHA-256, DER or r || s
    .integrity = my_play,      // optional: Play Integrity token for the nonce, or LSDK_STORE_NOT_FOUND
    .release = my_release,     // optional
};
lsdk_error *e = lsdk_config_set_chip(cfg, &chip);

integrity is asked only for the call that creates the activation, with the SHA-256 of the signed request in base64url as nonce. Return a token only where the vendor set up Play Integrity for the product; a negative value fails the activation without a call.

App Attest

On iOS, for products whose vendor set up App Attest, pass App Attest as callbacks instead of a chip. It replaces a chip set before, and lsdk_config_set_chip replaces it:

lsdk_app_attest attest = {
    .user_data = my_service,
    .key_id = my_key_id,           // 32 bytes: the decoded key ID of generateKey, or LSDK_STORE_NOT_FOUND
    .attestation = my_attest_key,  // attestKey with the 32 bytes of client_data_hash
    .assertion = my_assertion,     // generateAssertion with the 32 bytes of client_data_hash
    .release = my_release,         // optional
};
lsdk_error *e = lsdk_config_set_app_attest(cfg, &attest);

The key ID becomes the device ID. The call that creates the activation asks attestation once, every later signed call assertion, both with the SHA-256 of the signed request as client_data_hash (protocol, section 6.7, "Chip key"). The SDK asks key_id before every call, so the app can start a new key after a deactivation or a refused attestation: Apple attests a key only once. The Swift SDK does all of this with DCAppAttestService.

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) before lsdk_client_new:

lsdk_error *e = lsdk_config_set_device_certificate(cfg, der, der_len);

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). len 0 removes it.

Updates

lsdk_client_check_update(client, language, &update) asks whether a newer release is published for this device's channel and platform (protocol, section 6.4). It writes NULL when the app is current:

lsdk_update *u = NULL;
lsdk_error *e = lsdk_client_check_update(client, "en", &u); /* language NULL: English */
if (!e && u) {
    printf("Version %s is available.\n", lsdk_update_version(u));
    const char *notes = lsdk_update_notes(u); /* NULL if the release has none */
    if (notes) puts(notes);                   /* plain text, never HTML */
    lsdk_update_free(u);
}

lsdk_update_channel, lsdk_update_published_at (Unix seconds), lsdk_update_notes_language, lsdk_update_notes_truncated and lsdk_update_required complete the object. 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 (u && lsdk_update_file_name(u)) {
    lsdk_download *d = NULL;
    e = lsdk_client_request_download(client, lsdk_update_version(u), &d);
    if (!e && d) {
        e = lsdk_download_fetch(d, "/tmp/app-update.msi"); /* checks size and SHA-256 */
        lsdk_download_free(d);
        /* Hand the file to your updater. The SDK never runs it. */
    }
}

lsdk_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. lsdk_client_request_download gives NULL 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 (lsdk_download_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: lsdk_client_report_update(client, 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:

lsdk_config_add_release_key(cfg, "k4.public.…active…");
lsdk_config_add_release_key(cfg, "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). lsdk_client_release_list_seq(client, &seq, &known) gives the sequence number of the newest list the client accepted.

Assets

Files outside releases, such as models or content packs: lsdk_client_list_assets lists the ones this license may fetch (lsdk_asset_list_* read them by index), lsdk_client_request_asset_download gives a link for 5 minutes or NULL, and lsdk_asset_download_fetch saves and checks the file like lsdk_download_fetch. 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. Report what this device used (protocol, section 6.15):

lsdk_usage usage;
err = lsdk_client_report_usage(client, "exports", 1, "export-7f3a", &usage);
if (err == NULL) {
    printf("%lld of %lld left\n", (long long)usage.remaining, (long long)usage.limit);
} else if (strcmp(lsdk_error_code(err), "quota_exhausted") == 0) {
    /* Offer more units. */
}

amount is 1 to 10^9 and report_id your own ID of this use (1 to 100 characters). 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. out may be NULL.

Proxy calls

Call an endpoint of yours through the platform, so its URL and credentials never ship in your app (protocol, section 6.16):

lsdk_proxy *proxy = NULL;
err = lsdk_client_call_proxy(client, "weather", "{\"city\":\"Berlin\"}", &proxy);
if (err == NULL && proxy != NULL) {
    if (lsdk_proxy_failure(proxy) == NULL) {
        printf("%u %s\n", lsdk_proxy_status(proxy), lsdk_proxy_body_json(proxy));
    }
    lsdk_proxy_free(proxy);
}

body_json may be NULL. *out is NULL if the license may not call a target of that name. Otherwise lsdk_proxy_status is the endpoint's HTTP status and lsdk_proxy_body_json its JSON body, or lsdk_proxy_failure names why there is none (timeout, unreachable, response_too_large, response_invalid; status 0). 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

Fetch the actions you, your support or your customer sent to this device (protocol, section 6.17). Hand the client the action definitions your app accepts, the answer of GET /v1/products/{id}/remote-action-types:

lsdk_config_set_action_schema(config, action_schema_json);
/* ... lsdk_client_new, activate ... */
lsdk_remote_action_list *actions = NULL;
err = lsdk_client_remote_actions(client, &actions);
if (err == NULL) {
    for (size_t i = 0; i < lsdk_remote_action_list_count(actions); i++) {
        if (strcmp(lsdk_remote_action_list_name(actions, i), "open_project") == 0) {
            open_project(lsdk_remote_action_list_params_json(actions, i));
        }
    }
    lsdk_remote_action_list_free(actions);
}

Per action, lsdk_remote_action_list_id, _name, _params_json (a JSON object of strings, whole numbers and booleans, {} without parameters), _sent_by (vendor or customer), _issued_at and _expires_at (Unix seconds). 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.

Modules

The lsdk_module_* functions run 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

For machines that never reach the Client API, use an offline license (protocol section 6.2):

char *request = NULL;
lsdk_error *e = lsdk_client_offline_request(client, "Lab PC 3", &request);
/* Show request as text and QR code, then lsdk_string_free(request). */

/* Later: the customer brings back the license file (.lic). */
lsdk_status *status = NULL;
e = lsdk_client_import_offline(client, file_content, &status);
/* From now on lsdk_client_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.

Errors

lsdk_error_code returns the same codes as the Rust SDK, for example not_activated, license_revoked, token_expired, server_unreachable, storage_failed, config_invalid. Decide on the code, never on the message; the message is English text for logs. lsdk_error_get_kind groups the codes, lsdk_error_retry_after gives the wait time the server sent.

Two codes exist only in the C interface:

Code Meaning
invalid_argument A required pointer was NULL or a string was not UTF-8
internal_error A bug in the SDK. Please report it

Offline behavior is that of the Rust SDK: without a usable answer a call fails with server_unreachable, and the stored token keeps working until its offline end.

Storage and transport

By default the client uses the operating system's secure storage under <product_id>.<environment> and HTTPS with a 10 second timeout.

  • Own storage (headless Linux, containers): fill an lsdk_store with load, save, remove and an optional release, and pass it to lsdk_config_set_store. load copies the value with lsdk_buffer_set and returns LSDK_STORE_FOUND or LSDK_STORE_NOT_FOUND. Protect it like a password store: it holds the device secret.
  • Own transport (proxies, an HTTP stack you already use): fill an lsdk_transport with post and pass it to lsdk_config_set_transport. post sends a JSON POST and sets the answer with lsdk_reply_set. HTTP error statuses are answers; return a negative value only if no answer arrived.

The SDK copies the struct and calls release(user_data) once when the last client using it is gone (also when lsdk_config_set_* refuses the struct). Callbacks may run on any thread, never at the same time for the same client.

Security properties

As for the Rust SDK: public keys only, no secret in the app, no plain http:// except for localhost, no code from the server is ever run.