Giving modules to a licence
This page is for a vendor that sells a module of its own. The customer's licence is held by the company's licensing service. The vendor gives a module id to that licence with a call to the vendor API. The licence gets a newer version. The vendor is told the new version number and nothing about whom the licence is for or which installation. The customer's gateway gets the new version when it asks, or the customer gets it on the company's website with the installation id. How the module itself is declared and signed is in Licensing a module.
A vendor is registered by the company that makes Scadex. No sign-up exists. The company registers the vendor, makes its keys and, separately, certifies its package key. The vendor API is the only part a vendor calls.
Who a vendor is
A registered vendor has:
- An id: 3 to 40 characters, lowercase letters, digits and dashes.
scadexandcoreare taken. - A namespace: one or more prefixes that end in a dot, such as
com.acme., and optionally bundle names of its own. - A status,
activeorsuspended. The company suspends a vendor, and the vendor's keys stop working at once. - One or more keys.
The vendor id is the giver of every entitlement the vendor adds: a licence lists <module id> as given by that id. A gateway honours it only for a module signed with a package certificate whose subject is the same id, so the id of the registration and the subject of the package certificate have to be the same.
The key
A vendor key is scxv_<key id>_<secret>, sent as Authorization: Bearer <key>. The service keeps only a hash of the secret. The key is shown once, in the answer to the company that makes it, and cannot be shown again: a lost key is replaced by a new one and the old one is revoked. A key can carry a label and an end date.
A key that is missing, wrong, revoked or expired, or whose vendor is suspended, gets the same 401. After 10 wrong keys in a row from one address, that address waits 30 seconds, then twice as long each time, up to 15 minutes. A gateway's own API keys (scx_...) are not vendor keys, and the other way around.
What a vendor may give
- A module id inside its registered namespace, which is an id that starts with one of the vendor's prefixes, or a bundle name registered to the vendor.
- Never
io.scadex.*orcore. They are not a vendor's to register or to give, and the service answers403. - An id is 1 to 128 characters, lowercase letters, digits, dots, dashes and underscores, starting with a letter or digit.
A vendor sees only what it gave. It never sees the licence, whom it is for, or which installation, and no answer of the vendor API contains the licence file, which names the customer and the installation. A vendor needs the licence id, which the customer gives it: the gateway lists it for each licence file as licenseId in files of GET /api/v1/licensing. A licence id is 128 random bits and is what makes a call about a licence the holder's.
The routes
All routes are under /api/v1/modules/io.scadex.licensing on the company's gateway, in this page <base>. JSON goes in and comes out, Content-Type: application/json, a body of at most 64 KB, and no field the route does not know. Answers are never cached.
| Route | What |
|---|---|
PUT <base>/vendor/v1/licences/{licenceId}/grants/{moduleId} | Gives the licence a module or bundle of the vendor's |
DELETE <base>/vendor/v1/licences/{licenceId}/grants/{moduleId} | Takes it back |
GET <base>/vendor/v1/licences/{licenceId}/grants/{moduleId} | What the vendor gave there |
GET <base>/vendor/v1/grants?reference=&limit= | The vendor's own grants |
GET <base>/vendor/v1/me | The vendor, its namespace and its status |
Each change that does something makes a new version of the licence, a higher serial, and a gateway takes the highest. The service composes and signs the file when the record changes, never on a read. A change that cannot be signed (no issuing key, a certificate that has lapsed) does not happen.
Give a module
PUT takes an optional body:
| Field | Meaning |
|---|---|
expiresAt | When the grant ends. A date and time such as ISO 8601 with Z; a date alone is the start of that day in UTC. It has to be in the future. Without it the grant is for good |
features | Up to 16 strings of 1 to 40 characters, which the module can read as Features of its LicenseStatus |
reference | Up to 128 characters, your own reference for the sale. GET /vendor/v1/grants?reference= finds grants by it |
The answer is 200 with:
| Field | Meaning |
|---|---|
licenceId, moduleId | As given |
serial | The licence's version after this call. This is all a vendor is told about the new version |
changed | true when this call made a new version |
grantedAt | When the grant was first made |
expiresAt, features, reference | As sent |
Giving a module again with the same expiresAt, features and reference changes nothing: changed is false and serial stays. Giving it with a different value makes a new version. Giving it again after a withdrawal makes a new grant.
curl -X PUT "<base>/vendor/v1/licences/<licence id>/grants/<module id>" \
-H "Authorization: Bearer <key>" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: <a value that is unique to this request>" \
-d '{"expiresAt": "<end, ISO 8601>", "features": ["<feature>"], "reference": "<your reference>"}'
Idempotency
Idempotency-Key (at most 128 characters) makes a retry safe. The service keeps the answer to the first request with a key, for that vendor, and sends it back for any later request with the same key, without doing anything again. It does not compare the requests, so a key must not be reused for a different one. Only answers that succeeded are kept.
The answer never holds the licence file. The customer's gateway gets the new version when it asks the service, as described in Licensing. A customer whose gateway cannot reach the internet gets it on the company's website with the installation id, a function of the licence page that is being built and is not live yet, and imports the file as described in Licensing; a newer version replaces an older one.
Take a module back
DELETE takes no body. The answer is 200 with licenceId, moduleId, serial and changed. A module the vendor never gave, or already withdrew, is not an error: changed is false and nothing happens. Idempotency-Key works as for PUT.
curl -X DELETE "<base>/vendor/v1/licences/<licence id>/grants/<module id>" \
-H "Authorization: Bearer <key>"
Read one grant and list
GET .../grants/{moduleId} answers licenceId, moduleId, expiresAt, features, reference, grantedAt and withdrawnAt (null unless it was withdrawn). It answers 404 when the vendor never gave that module on that licence.
GET /vendor/v1/grants answers {"grants": [...]}, the vendor's own grants, newest first, withdrawn ones included. Each has licenceId, moduleId, expiresAt, reference, grantedAt and withdrawnAt. reference keeps the grants with exactly that reference, and limit is 1 to 500, default 100.
GET /vendor/v1/me answers id, name, prefixes, bundles and status. It is a way to check a key.
curl "<base>/vendor/v1/me" -H "Authorization: Bearer <key>"
Errors
An error is {"error": {"code": "...", "message": "..."}}, with fields (a list of {"field", "message"}) for validation_error and retryAfterSeconds for rate_limited. A 429 also carries a Retry-After header.
| Status | code | When |
|---|---|---|
| 400 | validation_error | A field is wrong or unknown, the module id is not an id, the end is not in the future, or the Idempotency-Key is over 128 characters. fields says which field |
| 400 | invalid_json | The body is not JSON |
| 401 | unauthenticated | The key is missing, unknown, revoked or expired, or its vendor is suspended |
| 403 | forbidden | The module id is io.scadex.* or core, or is outside the vendor's namespace and bundles |
| 404 | not_found | The licence does not exist, or the vendor never gave that module there (GET) |
| 413 | too_large | The body is over 64 KB |
| 415 | unsupported_media_type | The body is not application/json |
| 429 | rate_limited | A limit below was reached |
| 503 | issuing_unavailable | The service cannot sign a new version now. Nothing changed |
| 500 | internal_error | Something went wrong on the service's side |
The gateway's own limits sit in front of the service and answer in the gateway's format.
What taking a module back does
A gateway that is online loses the module the next time it asks the service for newer versions: every 6 hours when call home is on, or when its administrator presses the button. The module then shows the state unlicensed.
A gateway that is offline keeps the file it has. A withdrawal changes nothing there, and the service cannot take a file back. A vendor that sells a subscription gives the entitlement an expiresAt instead of relying on a withdrawal: the gateway checks the date when the module loads, and lets the module run for 14 days past it. A newer version of the licence moves the date.
If a vendor is withdrawn
Three things can be withdrawn from a vendor, and each does something different:
| What | What it stops | Where it takes effect |
|---|---|---|
A vendor key (scxv_...), revoked by the company | Calls to the vendor API made with that key | At once, in the licensing service |
The vendor, set to suspended in the registry | Every key of the vendor | At once, in the licensing service |
| The vendor's package key or the vendor itself, on a revocation list that a root signed | The vendor's modules, on every gateway that has the list | When a gateway takes the list |
The third is not a vendor API matter: a root key signs the list on the company's offline machine and the company puts it up on the licensing service. A gateway that can reach the service takes it with its next request for its licence, every 6 hours with call home on or when its administrator checks for a newer licence. It acts at once. The vendor's modules stop and show the state tampered, with an error that says the vendor or the key has been revoked. A gateway never gives a withdrawal back, because lists only add up. A gateway that cannot reach the service has the list that came with its build and gets newer ones with its next update. See Licensing.
Limits
| Limit | Value |
|---|---|
| Requests to the vendor routes, from the gateway | 120 a minute per address and 1,200 a minute for all callers together, for each route |
Writes (PUT and DELETE) per vendor | A burst of 60, then one a second |
| Writes per vendor in 24 hours | 5,000. Past it the answer is 429 with retryAfterSeconds of 3600 |
| Wrong keys | 10 in a row from one address, then a wait of 30 seconds that doubles up to 15 minutes |
Body, features, reference, Idempotency-Key | 64 KB; 16 items of 40 characters; 128 characters; 128 characters |
The service's own allowances are kept in memory, so a restart of the service forgets them.
The ledger
The service writes a ledger row for every write a vendor makes and for every one it refuses: the time, the actor (vendor:<vendor id>), the key id, the licence id, the module id, the action (grant or withdraw), the reference, the address the call came from, the serial that resulted, and the outcome: ok, unchanged, or refused with the error code as its detail. Reads and wrong keys are not in it.
A vendor cannot read the ledger. The company's administrators read it, for one vendor or all. What a vendor can read of its own is GET /vendor/v1/grants.
What is not built
- There is no sign-up. Registering a vendor, making and revoking its keys, and certifying its package key are done by the company.
- The service cannot take a licence file back from a gateway that is offline.
- The vendor routes have been tried in one test process, and not against the company's own collector.