Server SDK
liblotaserver.so checks, on the relying party's side, the token a game
process fetched with lota_get_token() and serialized with
lota_token_serialize(). It verifies the TPM signature against an AIK
public key the caller supplies, the nonce the caller issued and the expiry,
and returns the signed claims. The header is lota_server.h
(include/lota_server.h), which includes the wire formats of
lota_token.h (include/lota_token.h); the implementation is
src/sdk/lota_server.c and the pkg-config module lota-server:
cc $(pkg-config --cflags lota-server) -o backend backend.c \
$(pkg-config --libs lota-server)
The library uses OpenSSL and talks to no agent, TPM or verifier. A server
written in Go uses the sdk/server module (Go SDK), which verifies
tokens and boot evidence by the same rules and has no registry digest.
The AIK
A token is only as good as the key it is checked against. The library takes the AIK as a DER SubjectPublicKeyInfo and checks the signature with it, and nothing else: it does not know which host or account the key belongs to. The relying party keeps that record, for example from the host's enrolment, and looks up the key by the account the token arrived on. A key the client sends with its token proves nothing, because any key verifies the tokens it signed itself.
The key is RSA of at least 2048 bits and at most 512 bytes of DER. The signature is RSASSA or RSAPSS over SHA-256, SHA-384 or SHA-512, as the token header names.
Verifying a token
lota_server_verify_token() takes the serialized token, the AIK and the
32-byte nonce the server issued for this attempt, and fills
struct lota_server_claims:
#include <lota/lota_gaming.h>
#include <lota/lota_server.h>
struct lota_server_claims claims;
int ret;
ret = lota_server_verify_token(buf, len, aik_der, aik_len,
issued_nonce, &claims);
if (ret != LOTA_SERVER_OK) {
log_refusal(lota_server_strerror(ret));
return REJECT;
}
if (!(claims.flags & LOTA_FLAG_ATTESTED))
return UNTRUSTED;
LOTA_FLAG_* is declared in lota_gaming.h, with the meaning of each
bit in Gaming SDK. The checks run in this order, and the first that fails
returns:
The header: magic,
LOTA_TOKEN_VERSION, sizes, a known hash algorithm,runtime_protect_version1, at mostLOTA_TOKEN_MAX_PROTECT_PIDSPIDs, in strictly increasing order.runtime_protect_digest, recomputed from the PID list and the registry digests the token carries.The signature over the TPM's
TPMS_ATTEST.The structure of
TPMS_ATTEST.The quoted PCR mask against the header's
pcr_mask.extraDataof the quote against the hash of the header fields (below).The token's nonce against
expected_nonce.The length of the quoted PCR digest against the hash algorithm.
valid_untilat mostLOTA_SERVER_MAX_TOKEN_AGE_SEC(300) plusLOTA_SERVER_MAX_CLOCK_SKEW_SEC(60) seconds ahead of the server's clock.valid_untilnot passed.
claims is zeroed once the arguments are valid and filled once the nonce
matches, so LOTA_SERVER_ERR_FUTURE and LOTA_SERVER_ERR_EXPIRED still
report valid_until. On any other failure the claims are zero or partial
and the caller ignores them.
The token has an expiry and no issue time. The window above is what bounds
its age. A relying party that wants a shorter window
compares claims.valid_until with its own clock. A valid_until of 0 is
not refused as expired. Replay is the nonce's job: the server issues one per
attempt, accepts it once, and passes it as expected_nonce.
The claims
Member |
Content |
|---|---|
|
Unix time the token expires. |
|
The |
|
The nonce the token answers. |
|
The PCRs the quote covers. |
|
SHA-256 over the agent's enforcement policy at startup. |
|
SHA-256 over the protected PIDs and the registry digest of each. |
|
How many protected processes the token lists. |
|
The digest of the quoted PCR values, in the quote's hash. |
|
1 when |
|
Milliseconds a thread of the caller's instance stood stopped, suspend aside. |
A successful verification proves the AIK signed these fields. pcr_mask
and pcr_digest come from the TPM itself; the others are what the agent
stated, and a local root can sign its own. What that leaves a relying party
is in LOTA Threat Model.
lota_server_parse_token() fills the same structure without checking the
signature or the nonce, for logs and debugging. Its claims are not evidence
of anything.
The registry
The token carries a 32-byte digest for each protected PID, and
runtime_protect_digest covers them; the list itself travels outside the
token, as lota_get_registry() returned it on the client. The server
rebuilds each entry as struct lota_server_registry_module and
struct lota_server_registry_actor, with every field in the order listed,
and calls lota_server_registry_digest() with the registry's flags. The
result equals the token's protected_registry_digests entry for that PID
only for the list that round measured: an entry missing, added, reordered or
changed gives another digest. A registry is at most
LOTA_SERVER_REGISTRY_MAX_OBJECTS (1024) objects and
LOTA_SERVER_REGISTRY_MAX_ACTORS (256) actors; more, or an unknown flag,
returns LOTA_SERVER_ERR_INVALID_ARG.
Boot evidence
A token quotes PCR values by their digest alone. A server with no verifier
that wants to know whether the host booted with Secure Boot takes the bytes
lota_get_boot_evidence() returned with the token and calls
lota_server_verify_boot_evidence() with the claims of a verified token.
The evidence is accepted only when:
its version is
LOTA_BOOT_EVIDENCE_VERSIONand its PCR mask is the token's and includes PCR 7;the token's PCR digest is SHA-256;
its PCR values hash to that digest;
its PCR 7 events replay to the PCR 7 value.
secure_boot is then 1 when at least one SecureBoot measurement comes
before the firmware's separator and every one before it holds the single byte
1, and 0 otherwise, including evidence with no separator. A failure returns
LOTA_SERVER_ERR_BAD_EVIDENCE and leaves secure_boot at 0. Evidence
fetched after the PCRs changed does not match the token and fails the same
way. How the agent builds it is in Boot evidence.
Token wire format
All integers are little-endian. The fixed part is struct lota_token_wire,
LOTA_TOKEN_HEADER_SIZE (144) bytes:
Offset |
Size |
Field |
Content |
|---|---|---|---|
0 |
4 |
|
|
4 |
2 |
|
|
6 |
2 |
|
Header and variable data. |
8 |
8 |
|
Unix time. |
16 |
4 |
|
|
20 |
32 |
|
The server's nonce. |
52 |
2 |
|
TPM signature algorithm. |
54 |
2 |
|
TPM hash algorithm. |
56 |
4 |
|
Quoted PCRs. |
60 |
32 |
|
Startup policy. |
92 |
32 |
|
Protected PIDs and their registry digests. |
124 |
4 |
|
Number of PIDs. |
128 |
2 |
|
|
130 |
2 |
|
|
132 |
2 |
|
Signature size, at most 512. |
134 |
2 |
|
|
136 |
8 |
|
Time the instance stood stopped. |
The header is followed by protected_pids (uint32_t each),
protected_registry_digests (32 bytes each), attest_data and
signature. LOTA_TOKEN_MAX_SIZE holds the largest token.
The quote signs one 32-byte value, its extraData, and that value ties the
header to the signature:
extraData = SHA256(valid_until || flags || pcr_mask || nonce ||
policy_digest || runtime_protect_digest ||
stopped_ms)
sig_alg, hash_alg, the sizes and the PID and digest lists are outside
it: the first two are checked by the signature they select, the lists by
runtime_protect_digest.
Boot evidence starts with an 8-byte header (version, event_count,
pcr_mask), then 32 bytes per set bit of pcr_mask, lowest first, then
the events in log order: a 32-byte SHA-256 digest, a 2-byte data_size and
the data, present only for a SecureBoot measurement. It is at most
LOTA_BOOT_EVIDENCE_MAX_SIZE (8192) bytes.
Errors
Value |
Code |
Meaning |
|---|---|---|
0 |
|
Verified. |
-1 |
|
A |
-2 |
|
The header or a size does not parse, or the PID list is not in strictly increasing order. |
-3 |
|
Another |
-4 |
|
The signature does not verify, or names an algorithm the library does not take. |
-5 |
|
The PCR mask, |
-6 |
|
|
-7 |
|
The |
-8 |
|
The key does not decode or is not RSA of 2048 bits or more, or OpenSSL failed. |
-9 |
|
Reserved; no function of the header returns it. |
-10 |
|
|
-11 |
|
The PID list and registry digests do not hash to the signed
|
-12 |
|
Boot evidence that is malformed or not of the boot the token quotes. |
Functions
-
int lota_server_verify_token(const uint8_t *token_data, size_t token_len, const uint8_t *aik_pub_der, size_t aik_pub_len, const uint8_t *expected_nonce, struct lota_server_claims *claims)
Verify a serialized attestation token.
Parameters
const uint8_t *token_datatoken from
lota_token_serialize().size_t token_lensize of
token_data.const uint8_t *aik_pub_derAIK public key in DER (PKIX/SPKI) format.
size_t aik_pub_lensize of
aik_pub_der.const uint8_t *expected_nonce32-byte nonce the server issued for this attempt.
struct lota_server_claims *claimszeroed unless an argument is invalid, filled once the signature, extraData and nonce check out, so LOTA_SERVER_ERR_FUTURE and LOTA_SERVER_ERR_EXPIRED still report valid_until.
Recomputes the runtime digest from the PID list and registry digests, then checks the TPM signature over attest_data, the quoted PCR mask against the header, and extraData against
lota_compute_token_quote_nonce()over the header, so every field the caller acts on is inside the signature. Then the token nonce and the expiry.A relying party that wants a tighter freshness window applies it to claims.valid_until itself.
Return
LOTA_SERVER_OK on success, LOTA_SERVER_ERR_EXPIRED if a nonzero valid_until has passed, LOTA_SERVER_ERR_FUTURE if valid_until is too far ahead, LOTA_SERVER_ERR_NONCE_FAIL if the mask, extraData or nonce differ, LOTA_SERVER_ERR_RUNTIME_IMAGE if the digest recomputed from the PID list and registry digests differs from the signed one, another negative code otherwise.
-
int lota_server_parse_token(const uint8_t *token_data, size_t token_len, struct lota_server_claims *claims)
Extract claims without verifying the signature.
Parameters
const uint8_t *token_datatoken from
lota_token_serialize().size_t token_lensize of
token_data.struct lota_server_claims *claimsreceives the claims.
Claims from this function are untrusted.
Return
LOTA_SERVER_OK on success, a negative code on a parse failure.
-
const char *lota_server_strerror(int error)
Word an error code.
Parameters
int errorLOTA_SERVER_* code.
Return
a static string.
-
const char *lota_server_sdk_version(void)
Identify the build this library came from.
Opaque: match it, do not parse it. Binary compatibility is the soname and the ABI version pkg-config reports, see Documentation/userspace-api/stability.rst.
Return
the static string
lota_sdk_version()reports for the same release.
-
int lota_server_registry_digest(uint32_t flags, const struct lota_server_registry_module *mods, size_t count, const struct lota_server_registry_actor *actors, size_t actor_count, uint8_t out[32])
Hash a registry the way the agent does.
Parameters
uint32_t flagsthe registry's LOTA_REGISTRY_* flags.
const struct lota_server_registry_module *modsobjects of one process, in the order listed.
size_t countentries in
mods.const struct lota_server_registry_actor *actorsactors of the process, in the order listed.
size_t actor_countentries in
actors.uint8_t out[32]receives the digest.
outequals the token's protected_registry_digests entry for the process when the registry is the one that round measured. Anything else, reordered, short of an entry or with one rewritten, is not the list behind the token.Return
LOTA_SERVER_OK, LOTA_SERVER_ERR_INVALID_ARG for a malformed entry, an unknown flag or too many entries, or LOTA_SERVER_ERR_CRYPTO.
-
int lota_server_verify_boot_evidence(const struct lota_server_claims *claims, const uint8_t *evidence, size_t len, int *secure_boot)
Read Secure Boot from a token's PCRs.
Parameters
const struct lota_server_claims *claimsfrom
lota_server_verify_token();lota_server_parse_token()claims prove nothing.const uint8_t *evidencebytes
lota_get_boot_evidence()returned with the token.size_t lensize of
evidence.int *secure_boot1 when the firmware measured Secure Boot on before it handed over to the boot loader, 0 otherwise.
Accepts the evidence only when its PCR values hash to the signed PCR digest and its PCR 7 events replay to the PCR 7 value. A SecureBoot measurement that is absent, carries any value but 1 or follows the firmware's separator leaves
secure_bootat 0, as does evidence with no separator.Return
LOTA_SERVER_OK, LOTA_SERVER_ERR_INVALID_ARG, LOTA_SERVER_ERR_BAD_EVIDENCE or LOTA_SERVER_ERR_CRYPTO.