On this page
Verify signatures
Every entry in a lookup answer is signed with your organization’s private key. Your software checks it with the matching public key, so a tampered, copied or invented entry is rejected. The public key is safe to build into your software; the private key never leaves LaaSio.
What is signed
Section titled “What is signed”For each entry:
-
Remove
keyfrom the entry. -
Encode the rest as JSON:
- object keys sorted by byte value at every level, including inside
limits; - no whitespace;
/and non-ASCII characters not escaped;nullvalues kept.
For example,
{"a":{"c":"x/ü","d":null},"b":1}. - object keys sorted by byte value at every level, including inside
-
Check the base64-decoded
keyas an Ed25519 detached signature of those UTF-8 bytes, using the public key for the entry’skeyVersion.
Then check that clientId equals the client you looked up.
Your organization ID and public key are in LaaSio → Settings in the console.
These examples are the same ones the console’s Develop tab shows with your values filled in. Each one looks up a client, keeps only entries with a valid signature for that client, and prints the active ones. They are tested against LaaSio.
// Node.js 18+ (built-in fetch and Ed25519), save as licenses.mjsimport { createPublicKey, verify } from "node:crypto";
const LAASIO_URL = "https://laasio.functual.com";const ORG_ID = "lzo_YOUR_ORG_ID";// Your organization's public key, wrapped in the standard 12-byte Ed25519 header Node expectsconst PUBLIC_KEY = createPublicKey({ key: Buffer.concat([Buffer.from("302a300506032b6570032100", "hex"), Buffer.from("YOUR_PUBLIC_KEY_BASE64", "base64")]), format: "der", type: "spki",});
// Keys sorted at every level; JSON.stringify adds no whitespace and leaves "/" and Unicode as-isfunction canonical(value) { if (Array.isArray(value)) return value.map(canonical); if (value && typeof value === "object") { return Object.fromEntries(Object.keys(value).sort().map((k) => [k, canonical(value[k])])); } return value;}
/** Return the client's licenses whose signature is valid. */export async function getLicenses(clientId) { const url = `${LAASIO_URL}/api/v1/lookup?${new URLSearchParams({ org: ORG_ID, client: clientId })}`; const response = await fetch(url, { headers: { Accept: "application/json" } }); if (!response.ok) throw new Error(`LaaSio ${response.status}`);
const { data } = await response.json(); return data.filter(({ key, ...signed }) => signed.clientId === clientId && verify(null, Buffer.from(JSON.stringify(canonical(signed))), PUBLIC_KEY, Buffer.from(key, "base64")));}
/** A license is active from its start until its end (end null = never expires). */export function isActive(license, now = new Date()) { return new Date(license.start) <= now && (license.end === null || now < new Date(license.end));}
const licenses = await getLicenses("PC-123");for (const license of licenses.filter((l) => isActive(l))) { console.log(license.name, license.type, license.limits);}# pip install requests cryptographyimport base64import jsonfrom datetime import datetime, timezone
import requestsfrom cryptography.exceptions import InvalidSignaturefrom cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
LAASIO_URL = "https://laasio.functual.com"ORG_ID = "lzo_YOUR_ORG_ID"PUBLIC_KEY = Ed25519PublicKey.from_public_bytes(base64.b64decode("YOUR_PUBLIC_KEY_BASE64"))
def canonical(entry): # Keys sorted at every level, no whitespace, "/" and Unicode unescaped return json.dumps(entry, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode()
def get_licenses(client_id): """Return the client's licenses whose signature is valid.""" response = requests.get( f"{LAASIO_URL}/api/v1/lookup", params={"org": ORG_ID, "client": client_id}, headers={"Accept": "application/json"}, timeout=10, ) response.raise_for_status()
licenses = [] for entry in response.json()["data"]: signed = {k: v for k, v in entry.items() if k != "key"} try: PUBLIC_KEY.verify(base64.b64decode(entry["key"]), canonical(signed)) except InvalidSignature: continue if entry["clientId"] == client_id: licenses.append(entry) return licenses
def is_active(license): """A license is active from its start until its end (end None = never expires).""" now = datetime.now(timezone.utc) start = datetime.fromisoformat(license["start"].replace("Z", "+00:00")) end = license["end"] and datetime.fromisoformat(license["end"].replace("Z", "+00:00")) return start <= now and (end is None or now < end)
for license in get_licenses("PC-123"): if is_active(license): print(license["name"], license["type"], license["limits"])// .NET 8+ with NSec for Ed25519: dotnet add package NSec.Cryptography// (on .NET 8 add --version 24.4.0; newer NSec versions need .NET 9+)using System.Net.Http.Json;using System.Text;using System.Text.Encodings.Web;using System.Text.Json;using System.Text.Json.Nodes;using NSec.Cryptography;
foreach (var license in await Laasio.GetLicensesAsync("PC-123")){ if (Laasio.IsActive(license)) Console.WriteLine($"{license["name"]} {license["type"]} {license["limits"]!.ToJsonString()}");}
public static class Laasio{ const string LaasioUrl = "https://laasio.functual.com"; const string OrgId = "lzo_YOUR_ORG_ID";
static readonly PublicKey Key = PublicKey.Import(SignatureAlgorithm.Ed25519, Convert.FromBase64String("YOUR_PUBLIC_KEY_BASE64"), KeyBlobFormat.RawPublicKey); static readonly HttpClient Http = new(); // No whitespace, and "/" and Unicode left unescaped static readonly JsonSerializerOptions Canonical = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
/// <summary>Return the client's licenses whose signature is valid.</summary> public static async Task<List<JsonObject>> GetLicensesAsync(string clientId) { var url = $"{LaasioUrl}/api/v1/lookup?org={Uri.EscapeDataString(OrgId)}&client={Uri.EscapeDataString(clientId)}"; var response = await Http.GetFromJsonAsync<JsonObject>(url) ?? throw new Exception("Empty LaaSio response");
var licenses = new List<JsonObject>(); foreach (var node in response["data"]!.AsArray()) { var entry = node!.AsObject(); var signature = Convert.FromBase64String((string)entry["key"]!); var signed = Encoding.UTF8.GetBytes(Sorted(entry, skip: "key")!.ToJsonString(Canonical));
if ((string?)entry["clientId"] == clientId && SignatureAlgorithm.Ed25519.Verify(Key, signed, signature)) licenses.Add(entry); } return licenses; }
/// <summary>A license is active from its start until its end (end null = never expires).</summary> public static bool IsActive(JsonObject license) { var now = DateTimeOffset.UtcNow; var start = DateTimeOffset.Parse((string)license["start"]!); var end = license["end"] is null ? (DateTimeOffset?)null : DateTimeOffset.Parse((string)license["end"]!); return start <= now && (end is null || now < end); }
// Copy of a JSON value with object keys sorted (ordinal) at every level static JsonNode? Sorted(JsonNode? node, string? skip = null) => node switch { JsonObject o => new JsonObject(o.Where(p => p.Key != skip).OrderBy(p => p.Key, StringComparer.Ordinal) .Select(p => KeyValuePair.Create(p.Key, Sorted(p.Value)))), JsonArray a => new JsonArray(a.Select(n => Sorted(n)).ToArray()), _ => node?.DeepClone(), };}package main
import ( "bytes" "crypto/ed25519" "encoding/base64" "encoding/json" "fmt" "net/http" "net/url" "time")
const ( laasioURL = "https://laasio.functual.com" orgID = "lzo_YOUR_ORG_ID" publicKey = "YOUR_PUBLIC_KEY_BASE64")
type License struct { ClientID string `json:"clientId"` Name string `json:"name"` DisplayName string `json:"displayName"` Type string `json:"type"` Start time.Time `json:"start"` End *time.Time `json:"end"` // nil = never expires Limits map[string]*int64 `json:"limits"` // nil = not set Issued time.Time `json:"issued"`}
// Active reports whether the license is in force: from its start until its end.func (l License) Active(now time.Time) bool { return !now.Before(l.Start) && (l.End == nil || now.Before(*l.End))}
// canonical encodes an entry the way it is signed. Go sorts map keys; HTML escaping is turned off// so "<", ">" and "&" stay as-is, and the encoder's trailing newline is dropped.func canonical(entry map[string]any) []byte { var buf bytes.Buffer enc := json.NewEncoder(&buf) enc.SetEscapeHTML(false) enc.Encode(entry) return bytes.TrimRight(buf.Bytes(), "\n")}
// GetLicenses returns the client's licenses whose signature is valid.func GetLicenses(clientID string) ([]License, error) { pub, err := base64.StdEncoding.DecodeString(publicKey) if err != nil { return nil, err }
req, _ := http.NewRequest("GET", laasioURL+"/api/v1/lookup?"+url.Values{"org": {orgID}, "client": {clientID}}.Encode(), nil) req.Header.Set("Accept", "application/json") resp, err := http.DefaultClient.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("LaaSio %d", resp.StatusCode) }
var body struct { Data []json.RawMessage `json:"data"` } if err := json.NewDecoder(resp.Body).Decode(&body); err != nil { return nil, err }
var licenses []License for _, raw := range body.Data { var entry map[string]any dec := json.NewDecoder(bytes.NewReader(raw)) dec.UseNumber() // keep numbers exactly as sent if err := dec.Decode(&entry); err != nil { continue } key, _ := entry["key"].(string) signature, err := base64.StdEncoding.DecodeString(key) delete(entry, "key") if err != nil || !ed25519.Verify(pub, canonical(entry), signature) { continue }
var license License if json.Unmarshal(raw, &license) == nil && license.ClientID == clientID { licenses = append(licenses, license) } } return licenses, nil}
func main() { licenses, err := GetLicenses("PC-123") if err != nil { panic(err) } for _, l := range licenses { if !l.Active(time.Now()) { continue } devices := "not set" if d := l.Limits["devices"]; d != nil { devices = fmt.Sprint(*d) } fmt.Println(l.Name, l.Type, "devices:", devices) }}<?php// PHP 8+ (sodium is built in)const LAASIO_URL = "https://laasio.functual.com";const ORG_ID = "lzo_YOUR_ORG_ID";const PUBLIC_KEY = "YOUR_PUBLIC_KEY_BASE64";
/** Copy of an entry with keys sorted at every level. */function canonical(array $value): array{ ksort($value, SORT_STRING); return array_map(fn ($v) => is_array($v) ? canonical($v) : $v, $value);}
/** Return the client's licenses whose signature is valid. */function getLicenses(string $clientId): array{ $url = LAASIO_URL . "/api/v1/lookup?" . http_build_query(["org" => ORG_ID, "client" => $clientId]); $body = file_get_contents($url, false, stream_context_create([ "http" => ["header" => "Accept: application/json\r\n", "timeout" => 10], ])); if ($body === false) { throw new RuntimeException("LaaSio lookup failed"); }
$licenses = []; foreach (json_decode($body, true)["data"] as $entry) { $signature = base64_decode($entry["key"]); unset($entry["key"]); // json_decode(..., true) turns an empty limits object into []; restore the object that was signed if ($entry["limits"] === []) { $entry["limits"] = new stdClass(); } $signed = json_encode(canonical($entry), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
if ($entry["clientId"] === $clientId && sodium_crypto_sign_verify_detached($signature, $signed, base64_decode(PUBLIC_KEY))) { $licenses[] = $entry; } } return $licenses;}
/** A license is active from its start until its end (end null = never expires). */function isActive(array $license): bool{ $now = new DateTimeImmutable(); return new DateTimeImmutable($license["start"]) <= $now && ($license["end"] === null || $now < new DateTimeImmutable($license["end"]));}
foreach (getLicenses("PC-123") as $license) { if (isActive($license)) { echo $license["name"], " ", $license["type"], " ", json_encode($license["limits"]), "\n"; }}Common mistakes
Section titled “Common mistakes”- Sorting only the top level. Keys inside
limitsmust be sorted too. - Escaped characters. Many encoders escape
/(PHP) or<,>and&(Go) by default. Turn that off, as the examples do. - Empty
limitsin PHP.json_decode($body, true)turns{}into[]. Put back an object before encoding, or the bytes differ. - Re-serializing numbers. Keep limit values as the integers you received.
- Skipping the
clientIdcheck. A valid entry for another client is still valid; make sure it’s for yours.