Go SDK
github.com/szymonwilczek/lota/sdk/server (sdk/server) verifies
tokens and boot evidence for a relying party written in Go. It applies the
checks of Server SDK, reads the same wire formats and uses the standard
library alone; it talks to no agent, TPM or verifier. It has no registry
digest, so a server that rebuilds the registry of a protected process uses
liblotaserver.so.
go get github.com/szymonwilczek/lota/sdk/server
The package is server. Its API is the one public Go surface of the
repository (Public API and ABI surface).
Verifying a token
aik, err := server.ParseRSAPublicKey(aikDER)
if err != nil {
return err
}
claims, err := server.VerifyToken(token, aik, issuedNonce[:])
if err != nil {
return reject(err)
}
if claims.Flags&flagAttested == 0 {
return untrusted()
}
aikDER is the host's AIK as a DER SubjectPublicKeyInfo, from the relying
party's own record of the host, never from the client (Server SDK).
ParseRSAPublicKey() refuses a key that is not RSA or has fewer than 2048
bits. VerifyToken() takes the key as given, so a caller that builds an
*rsa.PublicKey some other way checks its size itself.
The package declares no LOTA_FLAG_* constants; the bits and their meaning
are in Gaming SDK, and flagAttested above stands for
LOTA_FLAG_ATTESTED.
VerifyToken() checks, and the first that fails returns:
a 32-byte
expectedNonceand a non-nil key;the header: magic,
TokenVersion, sizes, runtime protect version 1, at mostMaxProtectPIDsPIDs;a
TPMS_ATTESTand a signature present;the PID list in strictly increasing order;
the runtime protect digest, recomputed from the PID list and the registry digests the token carries;
the RSASSA or RSAPSS signature over the
TPMS_ATTEST, with SHA-256, SHA-384 or SHA-512 as the header names;the
TPMS_ATTESTitself, whose PCR selection is the SHA-256 bank only;the quoted PCR mask against the header's;
extraDataagainstComputeTokenQuoteNonce()over the header;the token's nonce against
expectedNonce;the expiry: not passed, and at most
DefaultMaxTokenAge(300) plusMaxClockSkew(60) seconds ahead of the server's clock.
An expiry of 0 is not refused as expired. The window is fixed. With
ErrExpired or ErrFutureToken the verified claims come back with the
error; with any other error the claims are nil. Nonces, replay and the
token's age work as in Server SDK.
Claims
Field |
Content |
|---|---|
|
The expiry as |
|
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. |
|
Milliseconds a thread of the caller's instance stood stopped. |
|
The digest of the quoted PCR values; empty when the attestation is no quote. |
|
The |
|
The expiry is nonzero and has passed. |
From VerifyToken() every field but Expired is covered by the AIK
signature. Which of them the TPM vouches for and which the agent states is
the same as for the C claims (Server SDK).
ParseToken() decodes a token without checking the signature or the
nonce, for logs and debugging, and its claims prove nothing. It fills
PCRDigest when the quote parses and returns an error only for a header
that does not parse or an expiry out of range.
Boot evidence
VerifyBootEvidence(claims, evidence) takes the claims of a verified
token and the boot evidence the agent returned with it, and reports whether
the host booted with Secure Boot. The evidence is accepted when its version
is BootEvidenceVersion, its PCR mask equals the token's and covers
PCR 7, the token's PCR digest is SHA-256, the PCR values hash to that digest
and the events replay to the PCR 7 value. Anything else returns
ErrBadEvidence, and nil claims ErrInvalidArg; secureBoot is
false on any error.
Secure Boot is on when the separator is present, at least one
SecureBoot event before it holds the value 1 and none before it holds
another value. An event without data is replayed and not read. The function
does not enforce BootEvidenceMaxSize; a server that reads evidence from
the network bounds it before the call. The layout is in Server SDK.
Building tokens
SerializeToken() encodes a token from its fields, as
lota_token_serialize() does in C, for tests and for tools that relay
tokens. It refuses lists and buffers over the limits, a PID list that is not
strictly increasing, and a registry digest count other than the PID count.
It does not check runtimeProtectDigest, which the caller computes with
ComputeRuntimeProtectDigest(pids, registryDigests).
ComputeTokenQuoteNonce() returns the extraData a token's quote
carries:
SHA256(valid_until || flags || pcr_mask || nonce ||
policy_digest || runtime_protect_digest || stopped_ms)
with the integers little-endian. It is another value than the binding nonce of an attestation report to the verifier.
Constants
Name |
Value |
|---|---|
|
|
|
|
|
1024, 512. |
|
181, |
|
32, per protected PID. |
|
A token with every list and buffer full. |
|
300 and 60 seconds. |
|
8 bytes of PCR selection, of which a bit past PCR 23 is refused; 64 bytes of PCR digest. |
|
|
|
8, 34 (digest and |
Errors
The functions return the sentinels below, mostly wrapped with detail, so a
caller tests them with errors.Is. SerializeToken() and
ParseRSAPublicKey() return plain errors.
Error |
Cause |
|---|---|
|
A |
|
The header or a size does not parse, the PID list is not strictly increasing, or the expiry is out of range. |
|
Another |
|
The token carries no |
|
The PID list and registry digests do not hash to the signed runtime protect digest. |
|
The signature does not verify, or names an algorithm the package does not take. |
|
The |
|
The PCR mask, |
|
The expiry has passed. |
|
The expiry lies beyond the window. |
|
Boot evidence that is malformed or not of the boot the token quotes. |