What's in the package? Calling the Windows Runtime Attestation API
How to call the GetRuntimeAttestationReport API, and what's in the signed package it returns, field by field.
Series Windows Runtime Attestation Report Part 2 of 5
- 1 Can you trust a hacked PC? An intro to Windows Runtime Attestation
- 2 What's in the package? Calling the Windows Runtime Attestation API You are here
- 3 The chain of trust Coming soon
- 4 Patch or attack? Inside the Windows Secure Hotpatch Report
- 5 The Secure Driver Report Coming soon
In Part 1 of this series, we looked at the problem the Windows Runtime Attestation Report solves and what the report is. In this post, we’ll learn how to use the GetRuntimeAttestationReport API in a project and go through the structure and details of the package it returns.
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 code in this post is from the public sample, which uses only the public Windows SDK.
What you’ll need
If you would like to follow along, all the code in this walkthrough is in the companion sample repository on GitHub.
Build requirements
The sample is already set up with all of these. You need them only if you call GetRuntimeAttestationReport from your own project:
Windows SDK 10.0.29648, available through the
Microsoft.Windows.SDK.CPP10.0.29648.1000-preview NuGet package. That package holds the headers.Ensure
NTDDI_VERSION >= NTDDI_WIN11_GEis set in your build configuration.Link against
onecore.libfor the API export. The import libraries are in theMicrosoft.Windows.SDK.CPP.x64andMicrosoft.Windows.SDK.CPP.arm64NuGet packages, so add the one for your architecture as well.
Runtime requirements
Windows 11 25H2 or later, with VBS enabled.
The driver report also requires HVCI.
The hotpatch report requires Windows 11 Insider Experimental (Future Platforms) Preview Build 29591.1000 or later. It does not require HVCI.
Calling GetRuntime Attestation Report
The API function prototype
1
2
3
4
5
6
7
BOOL GetRuntimeAttestationReport(
UCHAR* Nonce, // 32 bytes; NULL for a size query
UINT16 PackageVersion, // the package format version
UINT64 ReportTypesBitmap, // which reports you want
PVOID ReportBuffer, // output; NULL for a size query
PUINT32 ReportBufferSize // in: size; out: written or needed
);
GetRuntimeAttestationReport is declared in sysinfoapi.h. The package structures and the RUNTIME_REPORT_TYPE enumeration are in winnt.h, so including windows.h brings in everything.
The function returns TRUE on success. On failure it returns FALSE, and GetLastError() tells you why.
Let’s go through the arguments in order.
The nonce
The first argument is a 32-byte nonce, a random value that your server generates for each request and your app passes into the API call. The Secure Kernel signs it into the package. Your server can then check that the package was made for this request, and isn’t an old one sent again. This ensures freshness and avoids replay attacks.
The sample has no server, so it fills the nonce with BCryptGenRandom to have something to pass.
The package version
The second argument is the version of the package format you want to request. Pass RUNTIME_REPORT_PACKAGE_VERSION_CURRENT for the latest format.
Choosing the reports
The third argument says which reports you want. Each report type is one bit in ReportTypesBitmap. The RUNTIME_REPORT_TYPE_TO_MASK macro turns an enumeration value into its bit, and you OR together the ones you want:
1
2
3
UINT64 reportTypes =
RUNTIME_REPORT_TYPE_TO_MASK(RuntimeReportTypeDriver) |
RUNTIME_REPORT_TYPE_TO_MASK(RuntimeReportTypeHotpatch);
One package comes back, with both reports under one signature.
If you ask for a type that the running build doesn’t support, the call fails with ERROR_INVALID_PARAMETER.
Size first, then fetch
The last two arguments are the output buffer and its size. You don’t know how big the package is up front, so the usual pattern is two calls. The first passes a NULL buffer. It fails with ERROR_INSUFFICIENT_BUFFER, but it fills in the required size. The second call passes a buffer that big.
There’s a catch, though. The package can grow between those two calls: a driver could load, or a hotpatch could land. When that happens, the second call fails with ERROR_INSUFFICIENT_BUFFER again, and you resize the buffer and retry.
If the package grew between the two calls, the fetch fails and you go back to step 2.
Here is the loop from the sample, reformatted to fit the page and with the error messages removed. It gives up after four attempts:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
UINT32 size = 0;
if (!GetRuntimeAttestationReport(
nullptr, RUNTIME_REPORT_PACKAGE_VERSION_CURRENT,
reportTypes, nullptr, &size) &&
GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
return false; // a real failure, not just a small buffer
}
constexpr int kMaxFetchAttempts = 4;
for (int attempt = 0; attempt < kMaxFetchAttempts; attempt += 1) {
package.resize(size);
if (GetRuntimeAttestationReport(
nonce, RUNTIME_REPORT_PACKAGE_VERSION_CURRENT,
reportTypes, package.data(), &size)) {
package.resize(size); // bytes actually written
return true;
}
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
return false;
}
}
return false; // the size kept growing
You can also skip the size query and pass a buffer you expect to be big enough. That saves a call, but the size of the package depends on the machine, so you still have to handle ERROR_INSUFFICIENT_BUFFER and grow the buffer.
The package layout
Great, now that you know how to call the API, let’s understand the response package.
The call gives you one buffer of bytes. That buffer is the package, and this is how it’s laid out:
Top to bottom is the order of the bytes in the buffer.
Two parts and a signature
The package has three sections, packed one after another with no padding:
The signed part comes first. It holds the package header, the nonce, and one digest header for each report.
The signature blob follows. It’s an RSA-PSS signature, with SHA-512, over the signed part.
The authenticated part comes last. It holds the reports themselves, and each one starts with a small report header.
The reports aren’t signed directly. Each report is hashed with SHA-512, header included, and that hash is stored in a digest header inside the signed part. So a report can be trusted only after its hash has been checked against its digest header.
Why the reports aren’t signed directly
The layout is a deliberate design decision and one you should pay careful attention to. The signed part is small: a header, the nonce, and one digest for each report. The reports are where the bulk of the content is. On my test machine, a package with two reports was 10,520 bytes. The signed part was 208 bytes and the signature was 256 bytes, so the two reports made up the other 10,056, about 96% of the package.
Your app doesn’t have to send the whole package to your server every time. It can send the signed part and the signature, and the server can verify those without the reports. The server then asks for only the reports it needs, and checks each one against its digest header when it arrives.
For example, the server can keep the digest of each report from the last time it checked a machine. If a digest hasn’t changed, the report hasn’t changed, and the server doesn’t need to ask for it again. That saves network bandwidth and compute on a server that is checking packages from a very large number of machines.
The server asks for a report only when its digest has changed.
The signed part
The signed part is everything the signature covers: the package header, the nonce and the digest headers, in that order.
The package header
1
2
3
4
5
6
7
8
9
10
11
12
13
typedef struct _RUNTIME_REPORT_PACKAGE_HEADER {
UINT32 Magic; // "RTRP"
UINT16 PackageVersion; // Currently 1
UINT16 NumberOfReports; // Number of report types
UINT64 ReportTypesBitmap; // Which report types
UINT32 PackageSize; // Size of whole package
UINT16 ReportDigestType; // CALG_SHA_512
UINT16 TotalReportDigestsSize; // Size of digest headers
UINT16 Reserved; // Must be zero
UINT16 SignatureScheme; // RSA-PSS with SHA-512
UINT32 SignatureSize; // Size of the signature
UINT32 TotalAuthenticatedReportsSize; // Size of all reports
} RUNTIME_REPORT_PACKAGE_HEADER;
A few notes on these fields:
Magicis alwaysRUNTIME_REPORT_PACKAGE_MAGIC. Compare the field with that constant and not with text. Its value is0x52545250, stored little-endian, so the first four bytes of the buffer readPRTR, notRTRP.PackageVersionis the version of the package format. It should be the version you asked for.NumberOfReportsis how many reports the package holds.ReportTypesBitmaplists the report types that are actually in the package. It sits in the signed part, so your server can tell when a report it needs is missing.PackageSizeis the size of the whole package. The sample compares it with the number of bytes the API returned, and rejects the package if they differ.ReportDigestTypeandSignatureSchemeare the hash algorithm used for the report digests and the scheme used for the signature. Today they are always SHA-512 and RSA-PSS with SHA-512. They can change in the future, for example to move to post-quantum cryptography, so check them before you verify a package.
The three size fields, TotalReportDigestsSize, SignatureSize and TotalAuthenticatedReportsSize, give the size of the digest headers, the signature and the reports. The signed part is the package header, the nonce and the digest headers, so the signature starts right after the last digest header, and the reports start right after the signature.
The nonce
The nonce comes right after the package header. It is the same 32 bytes you passed to the API.
We sign the nonce along with the header, so an attacker can’t forge it or swap in a different one without breaking the signature. Once the signature checks out, your server compares these 32 bytes with the nonce it sent to verify freshness.
The digest headers
1
2
3
4
5
typedef struct _RUNTIME_REPORT_DIGEST_HEADER {
UINT16 ReportType; // Which report was hashed
UINT16 Reserved;
UINT8 ReportDigest[RUNTIME_REPORT_DIGEST_MAX_SIZE]; // SHA-512
} RUNTIME_REPORT_DIGEST_HEADER;
The digest headers come after the nonce, and they are the last thing in the signed part. There is one for each report in the package. ReportType says which report it belongs to, and ReportDigest is the SHA-512 hash of that whole report, with its report header.
The signature
The signature comes after the last digest header. It covers the whole signed part: the package header, the nonce and every digest header. The current scheme is RSA-PSS with SHA-512. That name has three parts:
RSA is the public-key algorithm. The Secure Kernel signs with a private key, and your server checks the signature with the matching public key.
SHA-512 is the hash. The signed part is hashed first, and that hash is what gets signed.
PSS (Probabilistic Signature Scheme) is how the hash is padded before RSA is applied. It mixes in random bytes, so two signatures over the same data are different, and both are valid. PSS needs a hash function for its own steps too, and that is also SHA-512.
SignatureSize gives its size. With the current scheme that is always 256 bytes, because an RSA signature is as long as its key and the key is 2048 bits in this case. A future scheme can have a different size, so read the field instead of assuming 256. Part 3 of the series covers how your server verifies the signature, and how it comes to trust the key.
The authenticated part
The authenticated part holds the reports, one after another. The signature doesn’t cover them directly. Each one is tied to the signed part by its digest.
The report header
1
2
3
4
5
typedef struct _RUNTIME_REPORT_HEADER {
UINT16 ReportType; // Driver, Hotpatch, ...
UINT16 Reserved;
UINT32 ReportSize; // Bytes in this report, header included
} RUNTIME_REPORT_HEADER;
Every report in the authenticated part starts with this header, whatever its type. ReportType tells you how to read the rest of the report. ReportSize is the size of the report including this header, so adding it to a report’s offset gives the offset of the next report.
The report data
The report’s own data follows its header. Its layout depends on the report type, and each type has its own structure in winnt.h.
This series covers two of the reports: the hotpatch report in Part 4, and the driver report in Part 5 (coming soon). They aren’t the only ones. winnt.h also defines a code integrity report today, and more reports will be added in the future.
The reports are in the same order as their digest headers, so the first digest header holds the digest of the first report and so on.
Try the sample
Alright, now you understand the complete structure of the Windows runtime report package.
The sample pulls all of this together. It fetches the package, parses it, and prints the reports. It doesn’t verify the signature or the digests:
1
> WindowsRuntimeAttestationReport.exe --type all
The output starts with the package header. This is from a package that holds two reports:
1
2
3
4
5
6
7
8
========================================================================
Runtime Report Package
========================================================================
version : 1
reports : 2
size : 10520 bytes
digest : SHA-512
signature : RSA-PSS SHA-512
The reports are printed after it.
--type takes driver, hotpatch or all, and it defaults to driver. Full source code and build instructions are available on GitHub: github.com/CodeMaxx/windows-runtime-attestation-report.
The sample builds for x64 and ARM64. It has no third-party dependencies beyond the Windows SDK and the MSVC toolchain, and it links the C runtime statically, so the executable runs without the Visual C++ Redistributable.
What’s next
In Part 3 (coming soon), we’ll go through the chain of trust from end to end: how your server gets the public half of the signing key from the machine’s boot logs, how it verifies that those logs came from a genuine TPM, and how it then verifies the signature, the nonce and the report digests.
After that, the series goes through the reports themselves:
Part 4: the Secure Hotpatch Report. How to tell a Microsoft hotpatch from a malicious hook.
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. :)