Akash Trehan
Blog

The Chain of Trust behind Windows Runtime Attestation

How your server uses the TPM and the boot log to trust the Secure Kernel's public key, and then verifies a Windows Runtime Attestation Report with it.

By Akash Trehan · · 12 min read
Whose key is it anyway? Part 3 of the Windows Runtime Attestation Report series: the chain of trust. A chain of five steps runs from the TPM through the quote and the boot log to the key and the package.
The Chain of Trust behind Windows Runtime Attestation
Series Windows Runtime Attestation Report Part 3 of 5
  1. 1 Can You Trust a Hacked PC? An Intro to Windows Runtime Attestation
  2. 2 What's in the Package? Calling the Windows Runtime Attestation API
  3. 3 The Chain of Trust behind Windows Runtime Attestation You are here
  4. 4 Patch or Attack? Inside the Windows Secure Hotpatch Report
  5. 5 The Secure Driver Report Coming soon
About this series

In Part 1 of this series, we saw that the Windows Runtime Attestation Report is signed by the Secure Kernel, and in Part 2 we went through the signed package field by field. That leaves one question unanswered. When the package reaches your server, how does the server know the signature really came from the Secure Kernel, and how does it verify that signature?

In this post, we’ll follow the chain of trust end to end. You’ll learn:

  • Why your server needs the Secure Kernel’s public key, and why that key can’t be sent along with the package.

  • Where the key comes from: the machine’s boot log, and how the TPM lets the server trust that log.

  • How the server, or an attestation service, knows it is talking to a genuine TPM.

  • The final checks on the package itself: the signature, the nonce and the report digests.

A note on where this comes from: I work on the Windows Secure Kernel team at Microsoft, and I built the Runtime Attestation Report framework.

The server needs a public key

The signature on the package is RSA-PSS with SHA-512, as we saw in Part 2. RSA is a public-key cryptographic algorithm. Public-key cryptography, a.k.a. asymmetric cryptography, uses a pair of mathematically linked keys—a public key and a private key. The Secure Kernel signs the package with its private key, and anyone who has the matching public key can verify that signature.

So before your server can verify anything, it needs two things. It needs a public key, and it needs to be sure that this public key belongs to the Secure Kernel.

Why the key can’t come with the package

The simplest idea is to send the public key along with the package, but that doesn’t work.

Remember who sends the package to your server: an app on a machine whose normal kernel may be compromised. An attacker on that machine can generate a key pair of their own, build a fake package that lists only what they want you to see, sign it with their private key, and send the matching public key along with it. The signature verification succeeds. But it proves nothing about the machine, because the server checked the attacker’s package against the attacker’s key.

A compromised machine generates its own key pair and signs a fake package. Server A uses the public key that came with the package, so verification succeeds, but only against the attacker's own public key, which proves nothing. Server B uses the Secure Kernel's public key, which it got through the chain of trust, so verification fails and the fake is rejected. Server A checks the package against the key that came with it. Server B checks it against the Secure Kernel’s public key.

So the server needs a way to verify that the public key it receives is really the one matching the Secure Kernel’s private key. The TPM makes that possible.

A short background on the TPM

A TPM (Trusted Platform Module) is a small security chip in the machine, or a protected part of its processor. Windows 11 requires one, so nearly every PC that runs it has a TPM. It has its own firmware and its own memory, which the operating system can’t read or change. A TPM generates and stores cryptographic keys, and it can sign data with them. Software can send it commands, such as a request to sign something, but it can’t read the keys stored inside the TPM, and that holds for the kernel too.

A TPM also keeps a record of how the machine booted. That record is built from measurements. To measure something is to take a hash of it, for example a piece of code that is about to run, or a setting that changes how the machine boots. As the machine boots, each stage measures the next one before running it and passes the hash to the TPM.

The TPM keeps these measurements in registers called PCRs (Platform Configuration Registers). A PCR can’t be written directly. It can only be extended: the TPM takes the PCR’s current value, appends the new measurement, hashes the two together and stores the result. That means the value of a PCR depends on every measurement that went into it, in order. The PCRs that record the boot can’t be reset without restarting the machine. Because each stage is measured before it runs, code can’t remove its own measurement once it has control. It can only add more.

A PCR holds only the result, not the list of measurements that produced it. That is why each measurement is also written to a log, which lists everything that went into the PCRs. It is called the boot log, or the TCG log. This is the measured boot we met in Part 1.

The last piece is the quote. The TPM can sign its current PCR values with a key that never leaves the TPM, and that signed statement is called a quote. A server that wants to know a machine’s PCR values asks the machine for a quote.

If you want to learn about the TPM in more depth, A Practical Guide to TPM 2.0 by Will Arthur, David Challener and Kenneth Goldman is a free book that explains it in detail.

The public key is measured at boot

Now back to the problem of proving that a public key belongs to the Secure Kernel. The Secure Kernel gets its signing key pair during boot. At that time, the public half is measured into a PCR and written to the boot log. That happens before the Windows kernel starts, so a compromised kernel can’t undo it. The private half is given only to the Secure Kernel.

In the log, the key is in an event named SIPAEVENT_VSM_IDKS_INFO, defined in the public SDK header wbcl.h. The event holds the RSA public key used to verify the signature on a package.

The public key is now in the boot log, but the log comes from the same machine as the package, so the server can’t trust the log on its own either.

Trusting the boot log

The boot log is not signed. It is plain data that the machine hands over, and an attacker who controls the normal kernel could send a modified log with their own key in it.

What the attacker can’t do is set a PCR to a value of their choosing, so the server also asks for a quote, in which the TPM signs its PCR values together with a fresh nonce from the server. The nonce does the same job here as it does in the package: an old quote carries an old nonce, so it can’t be reused.

The server checks the signature and the nonce on the quote, and then it replays the log. Each entry in the log holds two things: the data that was measured, and the hash of that data, which is what was extended into the PCR. The replay has three steps:

  1. The server hashes the data in the entries it relies on, such as the signing key, and checks that each result matches the entry’s hash.

  2. The server then starts from zero and extends the hashes in order, the same way the TPM did during boot.

  3. It compares the values it ends up with against the PCR values in the quote. (Strictly, the quote holds a hash of the PCR values, so the server compares hashes.)

If they match, the measurements in the log are exactly what the TPM recorded. A log with an entry added, removed or changed would give different values, and because every step is a hash, an attacker can’t craft a different log that produces the same PCR values.

That is why the server can’t just read the key out of the log. The replay is what ties the log, and the key in it, to the PCR values the TPM signed.

On the machine, during boot, a PCR starts at zero and the firmware, the boot loader and the public half of the signing key are extended into it, giving the PCR value in the TPM. The boot log holds the data and its hash for each entry, and is not signed. The quote holds the PCR values and your nonce and is signed by the TPM. Your server checks the data against each entry's hash and extends the hashes from zero, checks the quote's signature and nonce, and compares the two sets of PCR values. If they match, the public key in the log is the one that was measured at boot. The boot log and the quote leave the machine separately, and the server checks one against the other.

Is it a real TPM?

One gap is still left though. A quote is only trustworthy if a real TPM signed it. An attacker could run a software TPM that they fully control, feed it any measurements they like, and get a quote that matches a made-up log. We need to verify that the quote was signed by a real hardware TPM.

Every TPM has an endorsement key (EK) that its manufacturer certifies. The attestation service keeps the manufacturers’ root certificates, so it can check that an endorsement key belongs to a genuine TPM.

The endorsement key doesn’t sign quotes, though. The key that does is called an attestation key, or AIK (Attestation Identity Key). It is generated inside the TPM and can’t be exported, and the TPM won’t use it to sign a quote that it didn’t produce itself. The attestation key is tied to the endorsement key, so the attestation service can trace it back to a manufacturer’s certificate. If the AIK validation succeeds, it proves that the quote it signed came from a genuine TPM.

The attestation service also checks what else the boot log says about the boot: for example that Secure Boot and VBS were on, and that debugging and test signing were off. This is how it knows the machine booted genuine Windows with the Secure Kernel running.

The whole chain summarized

Phewww that was a journey! Now you have all of the pieces, so let’s put the puzzle together.

Your server asks the machine for three things: a quote, the boot log and the Windows Runtime Report package. On Windows, your app can get the boot log with Tbsi_Get_TCG_Log_Ex, and the package from GetRuntimeAttestationReport, as shown in Part 2.

Here is everything the server then checks, from the TPM down to the reports:

Nine rows, each a step in the chain and what it proves. The manufacturer's certificate: the endorsement key belongs to a genuine TPM. The attestation key: it is in the same TPM as that endorsement key. The quote: the PCR values and your nonce, signed with that key. The boot log: replaying it gives the PCR values in the quote. The signing key's public half: it is in the log, and the log shows a boot you trust. The package signature: the Secure Kernel signed the header, nonce and digests. The nonce: the package was made for this request. The report digests: each report is the one whose digest was signed. The reports: now it is safe to read them. Each row is trusted because of the one above it.

The first five checks give the server a public key it can trust. The server doesn’t have to do this verification itself. It can use an attestation service: the machine sends the quote and the log to the service, the service checks them and gives the server a signed statement of what the log contains. Azure Attestation is a service that verifies quotes and boot logs, and Microsoft’s attestation client samples show the client side of it. You can also use another service, or do the checks on your own server. The chain is the same in each case.

The remaining checks are about the package, and the server always does those itself.

The final checks

The server now has both things it needed: a public key, and proof that the key belongs to the Secure Kernel. It can finally check the Runtime Report package. For a refresher on the package’s structure, see Part 2 of this series.

The signature

The server hashes the signed part of the package, which is the package header, the nonce and the digest headers, with SHA-512. Then it verifies the RSA-PSS signature over that hash with the public key.

If the verification succeeds, the Secure Kernel produced this signed part, and nothing in it has changed since. If an attacker tampered with a single byte of it, the verification fails.

The nonce

Next, the server compares the 32-byte nonce in the package with the one it sent. A package from an earlier request carries a different nonce, so reusing a captured package fails here.

The digests

The digest headers are inside the signed part, so the server can trust them now. It first checks that there is a digest header for every report its policy requires. An attacker’s app can ask the API for fewer reports, but it can’t hide that, because the list of reports in the package is signed too.

Then, for each report, the server hashes the report with SHA-512, its report header included, and compares the result with the digest in that report’s digest header. If the two match, the report is exactly what the Secure Kernel wrote.

Now it is safe to read what a report says 🥳.

Bonus: What the chain doesn’t prove

There is one attack the chain doesn’t stop. A compromised machine can pass your server’s nonces to a second, healthy machine, let that machine produce a genuine quote, log and package, and send those back as its own. Every check passes, because everything is genuine. It just came from a different computer.

This is known as the cuckoo attack, and it isn’t specific to Windows: every remote attestation scheme has to deal with it. The chain of trust cryptographically proves that the report package is genuine. It doesn’t prove which machine it came from. The report doesn’t solve this today.

An attacker can also block the machine from sending the package altogether. It’s up to your server whether a missing package counts as a failure.

What’s next

You now understand everything about the Windows Runtime Attestation Report framework: what the report is, how to get it, and how to trust it. The rest of the series dives deep into the reports that build on top of this framework:

  • Part 4: the Secure Hotpatch Report. How to tell a legitimate Windows hotpatch from kernel tampering, using a report signed in VTL1.

  • Part 5: the Secure Driver Report (coming soon). Which drivers a machine has loaded, with the image hash and signer of each one.

Thank you for reading! If something here is unclear, or you spot a mistake, let me know in the comments. I’d love to hear from you. :)