Skip to content
Guides · Enrollment

Enroll a Windows device

You'll make two calls on the device and two on your server. By the end, Root Herald knows this installation's attestation key, your client holds its blob, and your server holds an ID for the device.

Run EnrollComplete from an elevated process

RootHeraldEnrollBegin runs unprivileged. RootHeraldEnrollComplete runs TPM2_ActivateCredential, which Windows allows only in an elevated process; without elevation it returns RH_ERR_ELEVATION_REQUIRED and consumes nothing. One elevation per enrollment; attesting and minting keys never need it. Windows elevation covers the ways to get it: from your installer, a one-off helper, or a service.

1

Create the attestation key

On the client, use RootHeraldEnrollBegin to create this installation's attestation key in the TPM. It writes the enrollment request into one buffer: the new key, its storage parent and the TPM's endorsement certificate, packed for Root Herald. It writes the key, wrapped by the TPM, into the other: the attestation key blob. Post the request to your server.

client.cc
size_t n, ak_len;

RH_STATUS st = RootHeraldEnrollBegin(rh, buf, sizeof buf, &n,
                                     ak, sizeof ak, &ak_len);

if (st != RH_OK) {
    return 0;
}

const char* reply = post("/enroll", buf);
2

Relay it to Root Herald

On your server, pass the enrollment request to relayEnroll. Root Herald checks that the endorsement certificate chains to a root it ships, a TPM maker's or a cloud provider's, recomputes the key's qualified name from the two public areas it was sent, and checks that your key's identity policy accepts this kind of TPM. Then it replies with a secret that only this TPM can recover. Send the reply back to the client as it is.

If the identity policy on your key doesn't accept the device, relayEnroll throws AdmissionRefusedError instead. That's a final answer for this device under this policy, so don't retry it.

server (Node)ts
app.post("/enroll", async (req, res) => {
  const { challenge } = await rh.relayEnroll(req.body);

  res.json(challenge);
});
3

Recover the secret

Back on the client, pass the reply and the blob to RootHeraldEnrollComplete. The TPM can recover the secret only if the attestation key lives in the same chip as the endorsement key, so recovering it is the proof. The answer lands in the buffer; post it to your server, and once your server has activated the enrollment, keep the blob.

The two legs need not share a process: RootHeraldEnrollComplete takes the blob and the reply as its inputs, which is what lets an elevated helper run this leg alone. The secret works once, so if this step fails, start again from RootHeraldEnrollBegin.

client.cc
st = RootHeraldEnrollComplete(rh, reply, strlen(reply),
                              buf, sizeof buf, &n,
                              ak, ak_len);

if (st != RH_OK) {
    return 0;
}

post("/enroll/activate", buf);

save_ak_blob(ak, ak_len);
4

Keep the device's ID

Pass the answer to relayActivate. Root Herald checks it and returns the device's ID, along with status and enrolledAt. Keep the ID with whatever the device belongs to: every verdict from this device carries the same ID, so it's how your server recognises the device later.

Two failures are worth handling. If the answer doesn't prove the device holds the key, relayActivate throws ActivationRefusedError. It throws the same error for an enrollment that's unknown, expired or already complete, and never says which, so have the client start again from RootHeraldEnrollBegin. If your key's budget can't pay for another new device this period, it throws QuotaExceededError instead. The enrollment stays open, so posting the same answer again works once the budget has room.

server (Node)ts
app.post("/enroll/activate", async (req, res) => {
  const { deviceId } = await rh.relayActivate(req.body);

  await saveDevice(accountOf(req), deviceId);

  res.sendStatus(204);
});