-
Notifications
You must be signed in to change notification settings - Fork 7
Add VBS-Protected Key Attestation Sample. #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
carolinecreamer
wants to merge
12
commits into
microsoft:main
Choose a base branch
from
carolinecreamer:feature/kg-att-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ab76d29
Add Key Guard key attestation sample.
31f47b6
change to vbs-protected
7b185b0
Merge branch 'main' into feature/kg-att-sample
13c3458
update names to vbs-protected key
ae92704
Update NuGet package
21a2697
Update NuGet
acdbb95
update documentation
c8d69d7
edit comment
b3a134a
remove nuget from pr
ebf7875
add machine_key flag and update documentation comments
2aa2817
reformat comment
6c1b7f4
reformat comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // | ||
|
|
||
| /** | ||
| * WARNING: Information regarding VBS-Protected Keys relates to prerelease product that may be substantially modified before it's commercially released. | ||
| * Microsoft makes no warranties, express or implied, with respect to the information provided here. | ||
| */ | ||
|
|
||
| /** | ||
| * @brief This sample provides the code implementation to perform VBS-Protected key attestation, | ||
| * and retrieve an attestation token from Microsoft Azure Attestation. | ||
| * | ||
| * @remark The following environment variables must be set before running the sample. | ||
| * | ||
| * - AZURE_TENANT_ID: Tenant ID for the Azure account. Used for authenticated calls to the attestation service. | ||
| * - AZURE_CLIENT_ID: The client ID to authenticate the request. Used for authenticated calls to the attestation service. | ||
| * - AZURE_CLIENT_SECRET: The client secret. Used for authenticated calls to the attestation service. | ||
| * - AZURE_MAA_URI: Microsoft Azure Attestation provider's Attest URI (as shown in portal). Format is similar to "https://<ProviderName>.<Region>.attest.azure.net". | ||
| * | ||
| * In addition, a TPM attestation identity key named 'att_sample_aik' must be created. See README.md for instructions. | ||
| * | ||
| * Finally, a fixed relying party id and nonce are used in this sample. An application should obtain a per-session nonce from the relying party before making | ||
| * the call to the attestation service. TODOs in the code below mark the locations to be updated. | ||
| * | ||
| */ | ||
|
|
||
| #include "utils.h" | ||
| #include "attest.h" | ||
| #include <string> | ||
| #include <vector> | ||
| #include <iostream> | ||
|
|
||
| #include <att_manager.h> | ||
| #include <att_manager_logger.h> | ||
|
|
||
| using namespace std; | ||
|
|
||
| #define AIK_NAME L"att_sample_aik" | ||
|
|
||
| int main() | ||
| { | ||
| // Adjust log level to your desired level of output. | ||
| att_set_log_level(att_log_level_none); | ||
| att_set_log_listener(sample_log_listener); | ||
|
|
||
| // TODO: Use relying party's id in the line below. | ||
| string rp_id{ "https://contoso.com" }; | ||
| // TODO: Use relying party's per-session nonce below. | ||
| vector<uint8_t> rp_nonce{ 'R', 'E','P','L','A','C','E',' ','W','I','T','H', ' ','R','P', ' ','N','O','N','C','E' }; | ||
|
|
||
| try | ||
| { | ||
| auto tpm_aik = load_tpm_key(AIK_NAME, true); | ||
| auto vbs_protected_key = create_vbs_protected_key(L"att_sample_vbs_key", false); | ||
|
|
||
| att_tpm_aik aik = ATT_TPM_AIK_NCRYPT(tpm_aik.get()); | ||
| att_tpm_key key = ATT_TPM_KEY_VBS_NCRYPT(vbs_protected_key.get()); | ||
|
|
||
| att_session_params_tpm params | ||
| { | ||
| rp_nonce.data(), // relying_party_nonce | ||
| rp_nonce.size(), // relying_party_nonce_size | ||
| rp_id.c_str(), // relying_party_unique_id | ||
| &aik, // aik | ||
| &key, // request_key | ||
| nullptr, // other_keys | ||
| 0 // other_keys_count | ||
| }; | ||
|
|
||
| attest(ATT_SESSION_TYPE_TPM, ¶ms, "report_vbs_protected_key.jwt"); | ||
| } | ||
| catch (const std::exception& ex) | ||
| { | ||
| cout << ex.what() << endl; | ||
| } | ||
|
|
||
| return 0; | ||
|
|
||
| // | ||
| // Notice that the report will contain the claim "x-ms-tpm-request-key", which includes the public part of the VBS-protected key in the "jwk" field. | ||
| // In addition, the "info" section will contain "vbs_ncrypt", indicating that a VBS-protected key was certified. The fields inside "vbs_ncrypt" attest to the VBS-protected key properties. | ||
| // These properties are described in the NCrypt library documentation (https://learn.microsoft.com/en-us/windows/win32/api/ncrypt/nf-ncrypt-ncryptverifyclaim#protectingattesting-private-keys-using-virtualization-based-security-vbs). | ||
| // A relying party (RP) should validate several important fields inside "vbs_ncrypt.vbs_trustlet_report" to ensure the key was generated and protected inside a trusted VBS-protected environment: | ||
| // | ||
| // trustlet_identity - Identifies the VBS trustlet that created or protects the key. The RP should compare this value against an expected trustlet identity to ensure the key originates from a trusted environment. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I should remove descriptions, like for enclave descriptions, let me know. Added descriptions since documentation is limited right now, but I'm assuming that these values will all be properly documented once VBS-protected keys GA |
||
| // | ||
| // trustlet_svn - The security version number (SVN) of the trustlet. The RP should verify this meets its minimum required SVN. | ||
| // | ||
| // flags.trustlet_debugged - Indicates whether the trustlet was debugged during key creation or protection. RPs should reject keys where this value is true, as debugged trustlets cannot be trusted. | ||
| // | ||
| // trustlet_policy - A set of policy entries describing protections applied to the trustlet. For example, policy entry ID=2 determines whether the trustlet is debuggable. RPs should verify policy values to verify that the trustlet meets its security requirements. | ||
| // | ||
| // These validations allow a relying party to establish that the key is genuinely VBS-backed, it comes from the correct trustlet that has sufficient security level, the environment was not debugged or weakened, and policy constraints match the RP's requirements. | ||
| // | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used "att_sample_vbs_key" to distinguish from the key in the tpm key attestation sample, but I wanted to not make the name such a mouthful ("att_sample_vbs_protected_key"). If I should change the name for correctness, let me know.