Verifying the Anvil Agent with an offline cryptographic handshake
Before an instrumented Control4 driver sends any telemetry, the Driverforge SDK challenges the Anvil Agent and verifies a signed proof of identity, entirely on the controller and without a network call.
Control4 drivers are Lua programs packaged as .c4z archives. They run inside Director, a process on a controller installed in a home or building. Drivers on the same controller can send each other messages, but that channel doesn't verify the sender's identity.
Our telemetry tool, Anvil, uses an SDK embedded as a single Lua file in each instrumented driver. A separate agent driver collects its telemetry and forwards it to our cloud. The SDK stays inactive when the agent isn't present, so startup begins by looking for one.
Finding a driver by its package filename, anvil-agent.c4z, establishes a name but proves nothing about the software answering to it. On a development controller, Composer, the platform's configuration application, allows only one instance of the agent, so the real agent holds that filename. On a field controller without the agent, any driver can ship under the same filename while showing a different name in Composer. An SDK that trusted the filename would send that impostor handler arguments and local variables from every instrumented driver on the controller: information a co-installed driver has no other way to read.
So the SDK verifies the agent cryptographically before sending it anything, and keeps capture off when verification fails. It does that under the SDK's standing constraints: developers ship the same instrumented build to production, so the SDK must preserve handler arguments, return values and errors exactly, and stay inert on controllers without the agent.
Verifying identity without a network call
The verifier runs inside a third-party driver, potentially on an offline controller. Its runtime is embedded LuaJIT, with cryptography provided by the firmware's lua-openssl binding. The SDK makes no network calls of its own, and its open-source bundle can't contain a secret.
So the cloud signs an attestation that the SDK can check offline. The signing keys stay where they're generated: the root key in a managed vault and the agent's identity key on the controller. Only public key material reaches the SDK.
Making the agent prove itself
The agent already has a keypair for the HTTPS server that accepts driver deployments from the Driverforge CLI. Its certificate is self-signed, so the CLI checks its fingerprint against the value registered with our cloud. The verification handshake reuses that per-controller identity.
On first load, the agent generates and persists an RSA-2048 keypair and a self-signed certificate on the controller. The private key never appears in a shipped artifact. At login, on boot and on a schedule, the agent registers with our GraphQL cloud API over an OAuth-authenticated connection, sending the controller's MAC address and the SHA-256 fingerprint of the certificate's DER encoding.
The response contains an RS256 JWT binding {sub: controller MAC, certFingerprint, aud: "anvil-sdk", exp}. A dedicated attestation root signs it using a non-exportable private key in a managed cloud key vault.
After discovering an agent during driver initialisation, the SDK sends it an ANVIL_VERIFY challenge with a 128-bit random nonce and the challenger's device id. The agent returns its attestation and certificate, plus a signature from the device key over five pipe-separated fields:
anvil-verify-v1|<nonce>|<controller MAC>|<agent device id>|<challenger device id>
The protocol prefix prevents challenge responses from being reused as signatures for other protocols. The random nonce prevents replay, while the MAC address binds the response to this controller. Both device ids are included so the proof applies to the particular agent and challenger involved in discovery.
The SDK first checks the attestation signature against the embedded root public key identified by kid. Missing or unknown key ids are rejected. It then validates the issuer, audience and expiry before comparing the presented certificate's independently calculated fingerprint with the attested fingerprint. Finally, it verifies the challenge signature using that certificate's public key. There are twenty rejection reasons across the chain: twelve for the attestation and eight for the proof.
Telemetry waits in a queue during verification and drains when the agent is verified. An invalid proof or a 10-second timeout clears the agent reference and discards the queued data, with one warning:
Anvil: WARNING - the device claiming to be the Anvil agent failed identity verification (...). Telemetry is disabled.
Telemetry to that device stays disabled until a new discovery event starts another verification attempt.
The proof arrives through ExecuteCommand, but the SDK consumes its own protocol reply before it reaches the driver's handler. That traffic exists only because of instrumentation, so passing it through would add a command to the driver's behaviour. A spec checks that the driver's ExecuteCommand sees no proof commands and still receives an ordinary command exactly once.
Keeping attestations fresh
An attestation expires after 72 hours, and the SDK rejects expired tokens. Controllers routinely stay up far longer than that, so the agent doesn't wait for a reboot: an hourly check re-registers whenever the attestation is missing or within 24 hours of expiry. Registration can be repeated safely and returns a fresh token, and starting a day early leaves roughly 24 hourly attempts if the cloud is briefly unreachable.
While the token is fresh, the agent only decodes its expiry and compares the time. It doesn't verify the signature for this scheduling check and doesn't hold the root key. The SDK verifies the token when deciding whether to trust the agent.
Treating peer messages as untrusted
Any driver on a controller can send the agent a message, so the agent treats every peer message as untrusted input. Peer messages can't carry configuration: the broker endpoint is fixed at build time, and publishing uses one cached client that ignores any options in the envelope. Actions that belong to the controller owner, such as signing out or starting a sign-in, are reachable only from Composer's own UI path (the literal LUA_ACTION command) and are refused from peers. Regression specs send hostile options through the entry point and check that nothing is forwarded.
The same review made every signature check name its digest explicitly. pkey:verify(data, signature) defaults to SHA-256 in the current firmware binding, but nothing guarantees that default in future firmware, so every sign and verify call in the SDK and agent now passes it:
pkey:verify(data, signature, 'sha256')
Telemetry queued while the SDK waits for an agent is capped at 500 envelopes, dropping the oldest, and reports how many were dropped when it drains. That bound matters when a driver accidentally replaces one of the SDK's lifecycle handlers, which stops the queue from ever draining: pushing 10,000 envelopes through the built bundle in that state grows the Lua heap by roughly 18 KB.
A Lua version difference at the instrumentation boundary
xpcall(func, handler, ...) passing its extra arguments on to func is a Lua 5.2 feature. Many LuaJIT builds enable it through an optional 5.2 compatibility setting; the controller's build doesn't. Code that relies on it works on a typical developer machine and silently calls the function with no arguments on a controller, which surfaces as an error in whatever code expected them:
attempt to concatenate local 'sProperty' (a nil value)
The SDK's instrument() wrapper captures the arguments, including nil values and the exact argument count, and unpacks them explicitly inside the closure it passes to xpcall. The test suite replaces the global xpcall with a shim that behaves like the controller's, whatever the host build, and the fix is also checked under Lua 5.1.5.
Because a runtime difference like this could appear again in future firmware, the SDK checks its own boundary before the first real handler runs. It sends fresh tables through the actual instrumented path as an argument and a return value, checks error propagation with a sentinel error, and compares table identity to confirm the values survive unchanged. Telemetry is suppressed during the probe. If the probe fails, instrument() forwards later calls directly and emits one diagnostic, so the driver runs untouched without instrumentation.
Testing cryptography and controller behaviour
Cryptographic verification. Each run generates RSA-2048 keypairs for a root, a device and an independent impostor, then creates and verifies real RS256 tokens. Fifteen specs check exact rejection messages. An impostor's certificate must fail with certificate does not match the attested fingerprint; replaying a certificate without possessing its private key must fail with challenge signature invalid. Agent-side tests reconstruct the signed message and verify it with openssl, including a tampered-message case.
Verification lifecycle. Seven specs use a scripted C4 platform object to exercise the pending, verified and failed states. They include a proof with the wrong nonce, which must be ignored, and the 10-second deadline for a verification attempt.
Built bundles. We verified a development-signed attestation against a development bundle, checked that a tampered certificate failed its fingerprint check, and confirmed that a production bundle rejects the development signing key. Three CI patterns also guard the published subtree against private keys, development key files and development key identifiers.
Rolling out verification and maintaining the keys
Unverified agents receive no telemetry. Continuing after a timeout would let an impostor bypass verification simply by declining to answer. The diagnostic points to an older agent without verification support as a possible benign cause, but doesn't restore capture.
Embedding a root key enables verification. Committed SDK source contains an empty key map and a sentinel marker. The build injects the public root into the output bundle. Without an embedded key, discovery behaves as it did before verification existed, which let agent proof support ship first and SDK enforcement follow one release later.
The injection step rejects non-public keys, production builds reject non-production key ids, and a missing marker fails the build. Development keys remain outside the published subtree.
Each controller keeps its own private key. An identity key shared in every agent package would let anyone who extracted it impersonate the fleet. Device-generated keys keep that secret out of distributed artifacts, and registration binds each controller to its own key.
Attestation uses a dedicated root. The SDK needs a stable public key for offline verification. Reusing the OAuth provider's rotating keys would tie SDK releases to the identity provider's key schedule. The embedded map supports a rotation window with two keys, selected by kid; an unknown id is rejected.
Published key material is separated by directory. The production public key can be published and audited, while development key material stays outside the mirrored tree. CI checks the boundary. Keeping the development key outside the allowed subtree means the publication rule needs no exceptions.
Peer commands have an explicit allowlist. Adding a peer-callable action requires a security review recorded at its handler. The verification handler accepts a length-capped nonce and a reply address, returns public material, and neither changes state nor reads configuration from the caller.
One trust assumption remains: drivers belonging to the same user can't yet be prevented from spoofing each other's keys.
What the SDK checks before capture
Discovery locates a candidate by filename; the signed handshake establishes whether the SDK can send it telemetry. That verification runs locally, using the public root embedded in the bundle.