Anti-cheat SDK
liblota_anticheat.so carries both ends of an anti-cheat session. In the
game process the producer opens a session and builds heartbeats: small
packets that wrap a token whose nonce binds the session, the sequence number,
the time, the game and the process's own code. On the backend the verifier
checks a heartbeat with the token verification of Server SDK. The header
is lota_anticheat.h (include/lota_anticheat.h), the
implementation src/sdk/lota_anticheat.c and the pkg-config module
lota-anticheat:
cc $(pkg-config --cflags lota-anticheat) -o producer producer.c \
$(pkg-config --libs lota-anticheat)
The library links the gaming and server objects in, with their symbols
local (Public API and ABI surface), so a program that also calls lota_connect() or
lota_server_verify_token() itself links liblotagaming.so or
liblotaserver.so as well. A working producer and backend are in
examples/demo_anticheat and examples/demo_server.
Sessions
lota_ac_init() takes a struct lota_ac_config:
struct_sizesizeof(struct lota_ac_config). A value belowLOTA_AC_CONFIG_SIZE_MINis refused withLOTA_AC_ERR_CONFIG_SIZE.providerLOTA_AC_PROVIDER_EACorLOTA_AC_PROVIDER_BATTLEYE. The value goes into every heartbeat; the library attaches no other meaning to it.game_idThe title's identifier, 1 to 63 bytes.
required_flagsLOTA_FLAG_*bits the session requires besidesLOTA_FLAG_ATTESTEDbefore it reports itself trusted.direct1 to talk to the agent through the gaming SDK, 0 to read the files of the Wine hook.
token_dirFile mode: the hook's output directory.
NULLtakes a non-empty$LOTA_HOOK_TOKEN_DIRwhether or not the directory exists, and an empty string skips it. Otherwise the first of$XDG_RUNTIME_DIR/lota-hookand/tmp/lota-<uid>that is a directory is taken. With neither, it is$XDG_RUNTIME_DIR/lota-hook, and without that variable the session starts inLOTA_AC_STATE_ERRORwithLOTA_AC_ERR_TOKEN_DIR.socket_path,publisher_profileDirect mode: as in
struct lota_connect_opts(Gaming SDK). A host enrolled with several publishers refuses a session that names none.
At init the library draws a random 16-byte session id and computes the game
binding hash of the running executable (below). In direct mode it connects
to the agent; a session that finds no agent is returned in
LOTA_AC_STATE_ERROR with the reason in lota_ac_last_error(), and
never connects later, so the title opens another session once the host is
ready. NULL means a bad configuration, no memory, or a failed session id
or game binding hash.
lota_ac_tick() refreshes the state: in direct mode one status request and
one token request with no nonce, in file mode a read of the snapshot file. The
state is then:
LOTA_AC_STATE_TRUSTEDLOTA_FLAG_ATTESTEDand everyrequired_flagsbit are set.LOTA_AC_STATE_UNTRUSTEDA token, or a status with any flag set, arrived without those bits.
LOTA_AC_STATE_ERRORNothing to judge: no agent, no snapshot or one whose token has expired, a refused request, or neither a token nor any flag.
LOTA_AC_STATE_IDLE is a NULL session, and LOTA_AC_STATE_RUNNING
does not outlast lota_ac_init(). lota_ac_get_state() and
lota_ac_get_info() read this state out of the game's own memory, which
the player controls; they serve the title's interface, and a backend trusts
only a verified heartbeat. lota_ac_shutdown() closes the connection and
frees the session.
Heartbeats
lota_ac_heartbeat() builds one packet in direct mode. Each call measures
the process's loaded code, computes the heartbeat nonce and asks the agent
for a token over it, so a beat costs one token of the agent's rate limit
(Tokens). The token sets the state from its flags; a token
request that times out or fails with LOTA_ERR_PROTOCOL, as one to a lost
agent does, sets LOTA_AC_STATE_ERROR. The sequence number starts at 0 and
grows by one with each packet built. File mode returns
-EOPNOTSUPP: the hook's token was issued with no nonce, so it cannot carry
a heartbeat's.
#include <lota/lota_anticheat.h>
struct lota_ac_config cfg = {
.struct_size = sizeof(cfg),
.provider = LOTA_AC_PROVIDER_EAC,
.game_id = "example-title",
.direct = 1,
.publisher_profile = publisher_hex,
};
struct lota_ac_session *s = lota_ac_init(&cfg);
uint8_t pkt[LOTA_AC_MAX_HEARTBEAT];
size_t len;
if (!s)
return -1;
if (lota_ac_heartbeat(s, pkt, sizeof(pkt), &len) == 0)
send_to_backend(pkt, len);
else
show(lota_ac_strerror(lota_ac_last_error()));
The heartbeat nonce is
SHA256("lota-ac-heartbeat:v1\0" || session_id || provider ||
sequence || timestamp || game_id_hash || domain_version ||
runtime_measure)
with integers little-endian. The header's lota_flags are the token's,
which the TPM signs with the token, so the signature covers every header
field but magic, version, total_size and token_size.
domain_version selects the pair of domain strings used for the nonce and
the game binding; LOTA_AC_DOMAIN_VERSION_V1 is the only one.
lota_ac_boot_evidence() returns the boot evidence that goes with the
session's tokens, from the agent in direct mode or from the hook's
lota-boot-evidence.bin in file mode. A buffer of
LOTA_BOOT_EVIDENCE_MAX_SIZE holds it. The producer sends it with a
heartbeat.
Game binding and runtime measure
The game binding hash names the title and its executable on disk:
SHA256("lota-ac-game-binding:v1\0" || game_id || SHA256(executable))
The producer hashes /proc/self/exe at init. The backend computes the
value it expects with lota_ac_compute_game_binding_hash() from the
game_id and a copy of the executable it ships.
The runtime measure hashes the code the process has mapped at the time of the
beat: the executable PT_LOAD segments of every file-backed object
dl_iterate_phdr() lists, the vDSO left out. Each object's digest covers
its segments in ascending address; the combined digest folds the objects
sorted by file basename, so neither load order nor library path changes it.
The layout is in the header comment. lota_ac_list_runtime_objects() lists
the files it covers, and lota_ac_compute_expected_runtime_measure_set()
computes the same digest from those files on the backend. The live and the
file digests differ for an object with DT_TEXTREL. A process started by
running the dynamic loader on its executable cannot be measured
(-ENOTSUP), nor can more than 256 objects or 16 executable segments in
one (-E2BIG).
The measure is computed inside the game process, so a player who controls
that process controls the value. The nonce keeps it from changing between the
producer and the backend; it says nothing a cheat could not have prepared.
What the agent measured of the process is in the token's
runtime_protect_digest and the registry (Server SDK).
Verifying a heartbeat
lota_ac_verify_heartbeat() takes the packet, the client's AIK, the game
binding hash and the runtime measure the backend expects, and fills
struct lota_ac_info. It checks, in order:
magic,version, the sizes, the provider anddomain_version;game_id_hashagainst the expected one;runtime_measureagainst the expected one (LOTA_AC_ERR_RUNTIME_IMAGE);timestampwithin 120 seconds of the backend's clock;the token, with
lota_server_verify_token()and the heartbeat nonce recomputed from the header asexpected_nonce;the header's
lota_flagsagainst the token's.
info.state is LOTA_AC_STATE_TRUSTED when the signed flags carry
LOTA_FLAG_ATTESTED; the producer's required_flags are not in the
packet, and a backend that requires more bits reads info.lota_flags, the
token's word. info.pcr_mask and info.pcr_digest are the token's, for
lota_ac_verify_boot_evidence(), which applies the boot evidence rules of
Server SDK and returns LOTA_AC_ERR_BAD_EVIDENCE on a mismatch.
info.session_start is 0, as one packet does not carry it.
The backend issues no nonce: the producer derives it, so the freshness of a
packet rests on the 120-second timestamp window and the token's expiry.
The verifier keeps no state between calls. A backend that refuses a packet
seen before records the last sequence of each session_id and accepts
only a higher one.
The AIK is the one the backend holds on record for the account, as for
Server SDK. Without it the call returns LOTA_AC_ERR_INVALID_ARG.
Snapshot file
In file mode the session reads lota-attestation.bin
(LOTA_SNAPSHOT_FILE_NAME) in the token directory, which the
Wine hook writes. lota_snapshot.h
(include/lota_snapshot.h) gives its 16-byte header, little-endian,
followed by the token:
Offset |
Size |
Field |
Content |
|---|---|---|---|
0 |
4 |
|
|
4 |
2 |
|
|
6 |
2 |
|
|
8 |
4 |
|
The |
12 |
4 |
|
|
The file sits in a directory the player owns, so its flags are what the
session shows locally and nothing more.
Heartbeat wire format
struct lota_ac_heartbeat_wire is the LOTA_AC_HEADER_SIZE (110) byte
header, little-endian and packed, followed by the token. A packet is at most
LOTA_AC_MAX_HEARTBEAT bytes.
Offset |
Size |
Field |
Content |
|---|---|---|---|
0 |
4 |
|
|
4 |
1 |
|
|
5 |
1 |
|
|
6 |
2 |
|
Header and token. |
8 |
16 |
|
Random, per session. |
24 |
4 |
|
Packet number in the session. |
28 |
4 |
|
The token's |
32 |
8 |
|
Unix time the packet was built. |
40 |
32 |
|
The game binding hash. |
72 |
2 |
|
Bytes of token. |
74 |
4 |
|
|
78 |
32 |
|
The producer's runtime measure. |
Errors
The codes lie below LOTA_AC_ERR_BASE (-1000), so none collides with the
negative errno the hash and measure functions return. The producer functions
return a negative errno and leave the LOTA_AC_ERR_* reason in
lota_ac_last_error(), kept per thread; the verifiers return the
LOTA_AC_ERR_* code itself. lota_ac_strerror() words either kind.
Value |
Code |
Meaning |
|---|---|---|
-1001 |
|
A bad argument, a buffer too small, or no AIK. |
-1002 |
|
The packet does not parse, names another game, lies outside the timestamp window, or its flags differ from the token's. |
-1003 |
|
Another |
-1004 |
|
The token signature does not verify. |
-1005 |
|
The token does not answer the heartbeat nonce. |
-1006 |
|
The token expired or expires beyond the window. |
-1007 |
|
The key does not decode or is not RSA of 2048 bits or more, or OpenSSL failed. |
-1008 |
|
|
-1009 |
|
|
-1010 |
|
Neither EAC nor BattlEye. |
-1011 |
|
An allocation failed. |
-1012 |
|
The session id or the game binding hash failed. |
-1013 |
|
No agent answers, or file mode found no snapshot or one whose token has expired. |
-1014 |
|
Nobody on the host agreed to that publisher. |
-1015 |
|
The host is not enrolled with that publisher, or with several and none was named. |
-1016 |
|
The agent refused the caller. |
-1017 |
|
File mode found no hook directory. |
-1018 |
|
The host holds no verdict to issue a token on. |
-1019 |
|
Beating faster than the agent issues tokens. |
-1020 |
|
The agent refused a status request. |
-1021 |
|
The agent refused a token, or the request for one failed. |
-1022 |
|
The runtime measure failed. |
-1023 |
|
The token did not serialize. |
-1024 |
|
The runtime measure is not the expected one, or the token's PID and registry digests do not match its signed digest. |
-1025 |
|
The agent has no attestation-key slot left for that publisher. |
-1026 |
|
The TPM is in dictionary-attack lockout. |
-1027 |
|
No boot evidence to hand over. |
-1028 |
|
Boot evidence malformed or of another boot. |
Functions
-
struct lota_ac_session *lota_ac_init(const struct lota_ac_config *cfg)
Create an anti-cheat session.
Parameters
const struct lota_ac_config *cfgThe session's configuration; struct_size set by the caller.
Direct mode connects to the agent, file mode locates the Wine hook directory.
A direct-mode session that found no agent never connects later: a host that gets ready takes a new session.
Return
The session, in LOTA_AC_STATE_ERROR if it got no verdict. NULL on error.
lota_ac_last_error()holds the reason.
-
int lota_ac_last_error(void)
Why the last call on this thread failed.
Set by every call that returns a value to check, LOTA_AC_ERR_OK on success: errno for the measure helpers, LOTA_AC_ERR_* otherwise. The renderers,
lota_ac_get_state()andlota_ac_shutdown()leave it alone. Thread-local, as a title and its launcher can share a process.Return
The code the last such call left.
-
const char *lota_ac_strerror(int err)
The error code as a sentence.
Parameters
int errA LOTA_AC_ERR_* code or a negative errno.
Return
Stable English with no trailing punctuation, never NULL.
-
void lota_ac_shutdown(struct lota_ac_session *session)
Destroy a session.
Parameters
struct lota_ac_session *sessionFrom
lota_ac_init(), or NULL.
-
enum lota_ac_state lota_ac_get_state(const struct lota_ac_session *session)
Current session state.
Parameters
const struct lota_ac_session *sessionFrom
lota_ac_init(), or NULL.
Local telemetry: client memory can be hooked, so a server trusts only
lota_ac_verify_heartbeat().Return
The state, LOTA_AC_STATE_IDLE if
sessionis NULL.
-
int lota_ac_get_info(const struct lota_ac_session *session, struct lota_ac_info *info)
Local session telemetry.
Parameters
const struct lota_ac_session *sessionFrom
lota_ac_init().struct lota_ac_info *infoFilled on success.
Not authoritative, as with
lota_ac_get_state().Return
0 on success, -EINVAL if an argument is NULL.
-
int lota_ac_tick(struct lota_ac_session *session)
Refresh session state from the agent or the hook files.
Parameters
struct lota_ac_session *sessionFrom
lota_ac_init().
Return
0 on success, negative errno on failure.
-
int lota_ac_heartbeat(struct lota_ac_session *session, uint8_t *buf, size_t buflen, size_t *written)
Generate a heartbeat packet.
Parameters
struct lota_ac_session *sessionFrom
lota_ac_init().uint8_t *bufReceives the packet.
size_t buflenSize of
buf.size_t *writtenThe packet size, on success.
A token sets the state from its flags. A token request that times out or fails with LOTA_ERR_PROTOCOL, as one to a lost agent does, sets LOTA_AC_STATE_ERROR. The token nonce binds sequence, timestamp, session and game, which takes a live token, so file mode has no heartbeat.
Return
0 on success, -EINVAL for bad arguments, -ENOTCONN without an agent, -ENODATA if no token is available, -ENOSPC if
bufis too small, -EOPNOTSUPP in file mode, another negative errno on failure.
-
int lota_ac_boot_evidence(struct lota_ac_session *session, uint8_t *buf, size_t buflen, size_t *written)
Fetch the boot evidence for this session's tokens.
Parameters
struct lota_ac_session *sessionFrom
lota_ac_init().uint8_t *bufReceives the evidence.
size_t buflenSize of
buf.size_t *writtenThe evidence size, on success.
Layout in lota_token.h, from the agent in direct mode or the hook's lota-boot-evidence.bin in file mode. Send it with a heartbeat. A buffer of LOTA_BOOT_EVIDENCE_MAX_SIZE holds any.
Return
0 on success, -EINVAL for bad arguments, -ENOTCONN without an agent, -ENODATA if there is none to give, -ENOSPC if
bufis too small, -EIO when the agent refused.
-
int lota_ac_compute_game_binding_hash(const char *game_id, const char *exe_path, uint8_t out[LOTA_AC_GAME_HASH_SIZE])
Expected game hash for a server.
Parameters
const char *game_idThe title's game_id, as in lota_ac_config.
const char *exe_pathThe title's main executable.
uint8_t out[LOTA_AC_GAME_HASH_SIZE]Receives the hash.
- SHA-256("lota-ac-game-binding:v1\0" || game_id ||
SHA-256(executable-bytes))
Return
0 on success, negative errno on failure.
-
int lota_ac_compute_runtime_measure(uint8_t out[LOTA_AC_RUNTIME_MEASURE_SIZE])
Measure the calling process's live image.
Parameters
uint8_t out[LOTA_AC_RUNTIME_MEASURE_SIZE]Receives the digest.
Return
0 on success, -EINVAL on a NULL argument, -ENOMEM on allocation failure, -E2BIG with too many objects or segments in one, -EIO on a digest failure, -ENOENT if no file-backed executable object is found, -ENOTSUP if the process was started by running the dynamic loader on the executable.
-
int lota_ac_list_runtime_objects(lota_ac_runtime_object_fn fn, void *user)
Enumerate what the runtime measure covers.
Parameters
lota_ac_runtime_object_fn fnCalled with each object's path.
void *userPassed to
fn.
Use it to capture the trusted runtime manifest.
Return
0 on success or when
fnstops early, -EINVAL on a NULLfn, -ENOTSUP if the process was started by running the dynamic loader on the executable, negative errno if the main executable path cannot be resolved.
-
int lota_ac_compute_expected_runtime_measure_set(const char *const *paths, size_t count, uint8_t out[LOTA_AC_RUNTIME_MEASURE_SIZE])
Measure of ELF files.
Parameters
const char *const *pathsThe ELF files the image is made of.
size_t countNumber of
paths.uint8_t out[LOTA_AC_RUNTIME_MEASURE_SIZE]Receives the digest.
Objects are keyed by file basename and sorted, so the order of
pathsdoes not matter. A file with no executable PT_LOAD segment contributes nothing.Return
0 on success, -EINVAL on a NULL argument, -ENOENT if the set yields no executable object, -E2BIG if too many objects or segments, negative errno on an I/O or parse failure.
-
int lota_ac_compute_expected_runtime_measure(const char *exe_path, uint8_t out[LOTA_AC_RUNTIME_MEASURE_SIZE])
Runtime measure of a single ELF.
Parameters
const char *exe_pathThe ELF file.
uint8_t out[LOTA_AC_RUNTIME_MEASURE_SIZE]Receives the digest.
Same as lota_ac_compute_expected_runtime_measure_set(&exe_path, 1, out).
Return
-
int lota_ac_verify_heartbeat(const uint8_t *data, size_t len, const uint8_t *aik_pub_der, size_t aik_pub_len, const uint8_t expected_game_id_hash[LOTA_AC_GAME_HASH_SIZE], const uint8_t expected_runtime_measure[LOTA_AC_RUNTIME_MEASURE_SIZE], struct lota_ac_info *info)
Verify a heartbeat packet.
Parameters
const uint8_t *dataThe packet.
size_t lenSize of
data.const uint8_t *aik_pub_derMandatory; unverified claims are attacker-controlled.
size_t aik_pub_lenSize of
aik_pub_der.const uint8_t expected_game_id_hash[LOTA_AC_GAME_HASH_SIZE]const uint8_t expected_runtime_measure[LOTA_AC_RUNTIME_MEASURE_SIZE]See
lota_ac_compute_expected_runtime_measure(). Also bound into the nonce.struct lota_ac_info *infoSession and attestation details.
infois LOTA_AC_STATE_TRUSTED only if the signed status word carries LOTA_FLAG_ATTESTED. A server wanting more reads info->lota_flags, the same word.Return
0 on success, a LOTA_AC_ERR_* code on failure.
-
int lota_ac_verify_boot_evidence(const struct lota_ac_info *info, const uint8_t *evidence, size_t len, int *secure_boot)
Read Secure Boot from boot evidence.
Parameters
const struct lota_ac_info *infoFrom
lota_ac_verify_heartbeat()on the heartbeat the evidence came with; the evidence counts only for the boot that quote signed.const uint8_t *evidenceFrom
lota_ac_boot_evidence().size_t lenSize of
evidence.int *secure_boot1 if the firmware measured Secure Boot on before the boot loader, else 0.
Return
0 on success, LOTA_AC_ERR_BAD_EVIDENCE for evidence malformed or of another boot, another LOTA_AC_ERR_* code on failure.