Skip to content

Commit 52f9437

Browse files
penglimsftPeng LiLarryOsterman
authored
Update AttestationClient::AttestTpm API to match existing AttestOpenEnclave and AttestSgxmEnclave (#3928)
* Fix broken link and typo in contributing.md * Use vector<uint8_t> for attest instead of strings * remove options * fix comments * update release version * remove versionig * revert changelog * add the change * update comment * Update sdk/attestation/azure-security-attestation/CHANGELOG.md Co-authored-by: Larry Osterman <[email protected]> * fix formatting * address pr comment * fix formating * update a comment * remove the attest tpm comment Co-authored-by: Peng Li <[email protected]> Co-authored-by: Larry Osterman <[email protected]>
1 parent 9b29538 commit 52f9437

File tree

9 files changed

+34
-37
lines changed

9 files changed

+34
-37
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Thank you for your interest in contributing to Azure SDK for C++.
1515
- **DO** submit all code changes via pull requests (PRs) rather than through a direct commit. PRs will be reviewed and potentially merged by the repo maintainers after a peer review that includes at least one maintainer.
1616
- **DO** review your own PR to make sure there aren't any unintended changes or commits before submitting it.
1717
- **DO NOT** submit "work in progress" PRs. A PR should only be submitted when it is considered ready for review and subsequent merging by the contributor.
18-
- If the change is work-in-progress or an experiment, **DO** start if off as a temporary draft PR.
18+
- If the change is work-in-progress or an experiment, **DO** start it off as a temporary draft PR.
1919
- **DO** give PRs short-but-descriptive names (e.g. "Improve code coverage for Azure.Core by 10%", not "Fix #1234") and add a description which explains why the change is being made.
2020
- **DO** refer to any relevant issues, and include [keywords](https://docs.github.com/articles/closing-issues-via-commit-messages/) that automatically close issues when the PR is merged.
2121
- **DO** tag any users that should know about and/or review the change.
@@ -48,13 +48,13 @@ Codespaces is new technology that allows you to use a container as your developm
4848
### GitHub Codespaces
4949

5050
1. From the Azure SDK GitHub repo, click on the "Code -> Open with Codespaces" button.
51-
1. Open a Terminal. The development environment will be ready for you. Continue to [Building and Testing](https://github.com/Azure/azure-sdk-for-cpp/blob/main/CONTRIBUTING.md#building-and-testing).
51+
1. Open a Terminal. The development environment will be ready for you. Continue to [Building the project](#building-the-project).
5252

5353
### VS Code Codespaces
5454

5555
1. Install the [VS Code Remote Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)
5656
1. When you open the Azure SDK for C++ repo in VS Code, it will prompt you to open the project in the Dev Container. If it does not prompt you, then hit CTRL+P, and select "Remote-Containers: Open Folder in Container..."
57-
1. Open a Terminal. The development environment will be ready for you. Continue to [Building and Testing](https://github.com/Azure/azure-sdk-for-cpp/blob/main/CONTRIBUTING.md#building-and-testing).
57+
1. Open a Terminal. The development environment will be ready for you. Continue to [Building the project](#building-the-project).
5858

5959
## Full Local Setup
6060

sdk/attestation/azure-security-attestation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
### Breaking Changes
88

9+
- Changed `AttestationClient::AttestTpm` to match `AttestOpenEnclave` and `AttestSgxEnclave`
10+
- Added `std::vector<uint8_t>` dataToAttest parameter.
11+
- Removed `PayLoad` in `TpmAttestationOptions`
12+
- Changed `TpmResult` in `TpmAttestationResult` to type `std::vector<uint8_t>`
13+
914
### Bugs Fixed
1015

1116
### Other Changes

sdk/attestation/azure-security-attestation/inc/azure/attestation/attestation_client.hpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,26 +223,20 @@ namespace Azure { namespace Security { namespace Attestation {
223223
Azure::Core::Context const& context = Azure::Core::Context{}) const;
224224

225225
/**
226-
* @brief Perform a single leg
227-
*
228-
* Processes attestation evidence from a VBS enclave, producing an attestation result.
229-
*
226+
* @brief Sends TPM-based attestation data to the service.
230227
* The TPM attestation protocol is defined
231228
* [here](https://docs.microsoft.com/azure/attestation/virtualization-based-security-protocol')
232229
*
233-
* Unlike OpenEnclave reports and SGX enclave quotes, TPM attestation is implemented using
234-
* JSON encoded strings.
235230
*
236-
* The client formats a string serialized JSON request to the
237-
* service, which responds with a JSON response. The serialized JSON object exchange continues
238-
* until the service responds with a JSON string with a property named {@code "report"}, whose
239-
* value will be an attestation result token.
231+
* @param dataToAttest - Attestation request data.
232+
* @param options - Options to the attestation request.
233+
* @param context - Context for the operation.
240234
*
241-
* @param options sent to the service for Trusted Platform Module (TPM) attestation.
242-
* @return attestation response for Trusted Platform Module (TPM) attestation.
235+
* @return Response<TpmAttestationResult> - The result of the attestation operation
243236
*/
244237
Response<Models::TpmAttestationResult> AttestTpm(
245-
AttestTpmOptions const& options,
238+
std::vector<uint8_t> const& dataToAttest,
239+
AttestTpmOptions const& options = AttestTpmOptions{},
246240
Azure::Core::Context const& context = Azure::Core::Context{}) const;
247241

248242
private:

sdk/attestation/azure-security-attestation/inc/azure/attestation/attestation_client_models.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,13 @@ namespace Azure { namespace Security { namespace Attestation { namespace Models
448448
*/
449449
struct TpmAttestationResult final
450450
{
451-
/** @brief The JSON encoded value returned from TPM attestation.
451+
/** @brief Attestation response data.
452+
*
452453
* The TPM attestation protocol is defined
453454
* [here](https://docs.microsoft.com/azure/attestation/virtualization-based-security-protocol')
454455
*
455456
*/
456-
std::string TpmResult;
457+
std::vector<uint8_t> TpmResult;
457458
};
458459

459460
/**

sdk/attestation/azure-security-attestation/inc/azure/attestation/attestation_client_options.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ namespace Azure { namespace Security { namespace Attestation {
261261
*/
262262
struct AttestTpmOptions final
263263
{
264-
/**
265-
* @brief JSON Data to send to the attestation service for TPM attestation.
266-
* @details The TPM attestation protocol is defined
267-
* [here](https://docs.microsoft.com/azure/attestation/virtualization-based-security-protocol')
268-
*/
269-
std::string Payload;
270264
};
271265

272266
/** @brief The AttestationSigningKey represents a tuple of asymmetric private cryptographic key

sdk/attestation/azure-security-attestation/src/attestation_client.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,14 @@ Azure::Response<AttestationToken<AttestationResult>> AttestationClient::AttestOp
196196
}
197197

198198
Azure::Response<TpmAttestationResult> AttestationClient::AttestTpm(
199-
AttestTpmOptions const& attestTpmOptions,
199+
std::vector<uint8_t> const& dataToAttest,
200+
AttestTpmOptions const&,
200201
Azure::Core::Context const& context) const
201202
{
202203
auto tracingContext(m_tracingFactory.CreateTracingContext("AttestTpm", context));
203204
try
204205
{
205-
std::string jsonToSend = TpmDataSerializer::Serialize(attestTpmOptions.Payload);
206+
std::string jsonToSend = TpmDataSerializer::Serialize(dataToAttest);
206207
auto encodedVector = std::vector<uint8_t>(jsonToSend.begin(), jsonToSend.end());
207208
Azure::Core::IO::MemoryBodyStream stream(encodedVector);
208209

@@ -212,7 +213,7 @@ Azure::Response<TpmAttestationResult> AttestationClient::AttestTpm(
212213
// Send the request to the service.
213214
auto response
214215
= AttestationCommonRequest::SendRequest(*m_pipeline, request, tracingContext.Context);
215-
std::string returnedBody(TpmDataSerializer::Deserialize(response));
216+
std::vector<uint8_t> returnedBody{TpmDataSerializer::Deserialize(response)};
216217
return Response<TpmAttestationResult>(TpmAttestationResult{returnedBody}, std::move(response));
217218
}
218219
catch (std::runtime_error const& ex)

sdk/attestation/azure-security-attestation/src/private/attestation_deserializers_private.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,21 +397,21 @@ namespace Azure { namespace Security { namespace Attestation { namespace _detail
397397
returnValue.CertificateThumbprint, jsonResult, "x-ms-certificate-thumbprint");
398398
return returnValue;
399399
}
400-
std::string TpmDataSerializer::Serialize(std::string const& tpmData)
400+
std::string TpmDataSerializer::Serialize(std::vector<uint8_t> const& tpmData)
401401
{
402402
Azure::Core::Json::_internal::json jsonData;
403-
jsonData["data"] = Azure::Core::_internal::Base64Url::Base64UrlEncode(
404-
std::vector<uint8_t>(tpmData.begin(), tpmData.end()));
403+
jsonData["data"] = Azure::Core::_internal::Base64Url::Base64UrlEncode(tpmData);
405404
return jsonData.dump();
406405
}
407-
std::string TpmDataSerializer::Deserialize(Azure::Core::Json::_internal::json const& jsonData)
406+
std::vector<uint8_t> TpmDataSerializer::Deserialize(
407+
Azure::Core::Json::_internal::json const& jsonData)
408408
{
409409
std::vector<uint8_t> returnValue;
410410
JsonOptional::SetIfExists<std::string, std::vector<uint8_t>>(
411411
returnValue, jsonData, "data", Azure::Core::_internal::Base64Url::Base64UrlDecode);
412-
return std::string(returnValue.begin(), returnValue.end());
412+
return returnValue;
413413
}
414-
std::string TpmDataSerializer::Deserialize(
414+
std::vector<uint8_t> TpmDataSerializer::Deserialize(
415415
std::unique_ptr<Azure::Core::Http::RawResponse> const& response)
416416
{
417417
return TpmDataSerializer::Deserialize(

sdk/attestation/azure-security-attestation/src/private/attestation_deserializers_private.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ namespace Azure { namespace Security { namespace Attestation { namespace _detail
136136

137137
struct TpmDataSerializer
138138
{
139-
static std::string Serialize(std::string const& tpmData);
140-
static std::string Deserialize(Azure::Core::Json::_internal::json const& jsonData);
141-
static std::string Deserialize(std::unique_ptr<Azure::Core::Http::RawResponse> const& response);
139+
static std::string Serialize(std::vector<uint8_t> const& tpmData);
140+
static std::vector<uint8_t> Deserialize(Azure::Core::Json::_internal::json const& jsonData);
141+
static std::vector<uint8_t> Deserialize(
142+
std::unique_ptr<Azure::Core::Http::RawResponse> const& response);
142143
};
143144

144145
}}}} // namespace Azure::Security::Attestation::_detail

sdk/attestation/azure-security-attestation/test/ut/tpmattestation_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ namespace Azure { namespace Security { namespace Attestation { namespace Test {
118118
{
119119
auto client(CreateClient(InstanceType::AAD));
120120

121-
auto response(client.AttestTpm(AttestTpmOptions{R"({"payload": { "type": "aikcert" } })"}));
121+
std::string tpmQuote = R"({"payload": { "type": "aikcert" } })";
122+
auto response(client.AttestTpm(std::vector<uint8_t>(tpmQuote.begin(), tpmQuote.end())));
122123

123124
Azure::Core::Json::_internal::json parsedResponse(
124125
Azure::Core::Json::_internal::json::parse(response.Value.TpmResult));

0 commit comments

Comments
 (0)