Skip to content

Commit 38dd317

Browse files
Added support for the getPolicy, setPolicy, and resetPolicy APIs (Azure#15432)
* Added getPolicy and AttestationAdministrationClient APIs; code cleanup to use correct shared attestation provider; other fixes * Documentation cleanup - added in documentation in more places * Addressed API review feedback; started adding in attestation token validation logic * Prepared for release
1 parent a6fbc39 commit 38dd317

File tree

103 files changed

+2706
-2239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2706
-2239
lines changed

sdk/attestation/attestation/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Release History
22

3-
## 1.0.0-beta.3 (Unreleased)
3+
## 1.0.0-beta.3 (2021-06-08)
44

55
### Features Added
66

77
### Breaking Changes
88

99
- Essentially completely rewritten. All existing functionality has been replaced.
10+
- Removed `policy` property on `AttestationClient` object, because it has been replaced.
11+
- Removed `policy.reset` and `policy.set`, replaced with the `resetPolicy` and `setPolicy` methods on the `AttestationAdministrationClient`.
12+
- Removed `policy.get`, replaced with the `getPolicy` method of the new `AttestationAdministrationClient` client object.
1013
- Removed `attestation.attestSgxEnclave`, `attestation.attestOpenEnclave`, `attestation.attestTpm`, and `attestation` property from attestationClient, replaced with `attestSgxEnclave`, `attestOpenEnclave` and `attestTpm`.
1114
- Removed `metadataConfiguration` and `signingCertificates` properties from attestationClient.
1215
- Removed `metadataConfiguration.get()` method, replaced with `client.getOpenIdMetadata()`.

sdk/attestation/attestation/README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,30 @@ Creates an instance of the Attestation Client at uri `endpoint`.
177177

178178
### Get attestation policy
179179

180-
The `set_policy` method retrieves the attestation policy from the service.
180+
The `getPolicy` method retrieves the attestation policy from the service.
181181
Attestation Policies are instanced on a per-attestation type basis, the `AttestationType` parameter defines the type to retrieve.
182182

183183
```js
184-
<FILL THIS IN>
184+
const policyResult = await adminClient.getPolicy(attestationType);
185+
186+
// The text policy document is available in the `policyResult.value`
187+
// property.
188+
189+
// The actual attestation token returned by the MAA service is available
190+
// in `policyResult.token`.
185191
```
186192

187193
### Set an attestation policy for a specified attestation type
188194

189195
If the attestation service instance is running in Isolated mode, the set_policy API needs to provide a signing certificate (and private key) which can be used to validate that the caller is authorized to modify policy on the attestation instance. If the service instance is running in AAD mode, then the signing certificate and key are optional.
190196

191-
Under the covers, the SetPolicy APIs create a [JSON Web Token][json_web_token] based on the policy document and signing information which is sent to the attestation service.
197+
Under the covers, the setPolicy APIs create a [JSON Web Token][json_web_token] based on the policy document and signing information which is sent to the attestation service.
192198

193199
```js
194200
<FILL THIS IN>
195201
```
196202

197-
If the service instance is running in AAD mode, the call to set_policy can be
203+
If the service instance is running in AAD mode, the call to setPolicy can be
198204
simplified:
199205

200206
```js
@@ -205,13 +211,26 @@ Clients need to be able to verify that the attestation policy document was not m
205211

206212
There are two properties provided in the [PolicyResult][attestation_policy_result] that can be used to verify that the service received the policy document:
207213

208-
- [`policy_signer`][attestation_policy_result_parameters] - if the `set_policy` call included a signing certificate, this will be the certificate provided at the time of the `set_policy` call. If no policy signer was set, this will be null.
209-
- [`policy_token_hash`][attestation_policy_result_parameters] - this is the hash of the [JSON Web Token][json_web_token] sent to the service.
214+
- [`policy_signer`][attestation_policy_result_parameters] - if the `setPolicy` call included a signing certificate, this will be the certificate provided at the time of the `setPolicy` call. If no policy signer was set, this will be null.
215+
- [`policy_token_hash`][attestation_policy_result_parameters] - this is the hash of the [JSON Web Signature][json_web_token] sent to the service for the setPolicy API.
210216

211217
To verify the hash, clients can generate an attestation token and verify the hash generated from that token:
212218

213219
```js
214-
<FILL THIS IN>
220+
const expectedPolicy = AttestationToken.create(
221+
{
222+
body: new StoredAttestationPolicy(minimalPolicy).serialize(),
223+
signer: signer
224+
});
225+
226+
// Use your favorite SHA256 hash generator function to create a hash of the
227+
// stringized JWS. The tests in this package use `KJUR.crypto.Util.hashString(buffer, "sha256")`
228+
// from the `jsrsasign` library, but any crypto library will
229+
// work.
230+
const expectedHash = generateSha256Hash(expectedPolicy.serialize());
231+
232+
// The hash returned in expectedHash will match the value in
233+
// `setResult.value.policy_token_hash.
215234
```
216235

217236
### Attest SGX Enclave
@@ -232,12 +251,20 @@ The client can then send that Attestation Token (which contains the serialized k
232251

233252
This example shows one common pattern of calling into the attestation service to retrieve an attestation token associated with a request.
234253

235-
This example assumes that you have an existing `AttestationClient` object which is configured with the base URI for your endpoint. It also assumes that you have an SGX Quote (`quote`) generated from within the SGX enclave you are attesting, and "Runtime Data" (`runtime_data`) which is referenced in the SGX Quote.
254+
This example assumes that you have an existing `AttestationClient` object which is configured with the base URI for your endpoint. It also assumes that you have an SGX Quote (`quote`) generated from within the SGX enclave you are attesting, and "Runtime Data" (`binaryRuntimeData`) which is referenced in the SGX Quote.
236255

237256
```ts
238-
<FILL THIS IN>
257+
const attestationResult = await client.attestOpenEnclave(
258+
quote,
259+
{
260+
runTimeData: new AttestationData(binaryRuntimeData, false),
261+
});
239262
```
240263

264+
If the `isJson` parameter to the `AttestationData` constructor is not provided,
265+
the code will attempt to determine if binaryRuntimeData is JSON or not by attempting
266+
to parse the data.
267+
241268
Additional information on how to perform attestation token validation can be found in the [MAA Service Attestation Sample](https://github.com/Azure-Samples/microsoft-azure-attestation).
242269

243270
### Retrieve Token Certificates

sdk/attestation/attestation/karma.conf.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ module.exports = function(config) {
5959
"TEST_MODE",
6060
"AAD_ATTESTATION_URL",
6161
"ISOLATED_ATTESTATION_URL",
62+
"ATTESTATION_LOCATION_SHORT_NAME",
6263
"policySigningCertificate0",
6364
"policySigningCertificate1",
6465
"policySigningCertificate2",
6566
"isolatedSigningCertificate",
67+
"ATTESTATION_ISOLATED_SIGNING_CERTIFICATE",
68+
"ATTESTATION_ISOLATED_SIGNING_KEY",
6669
"AZURE_CLIENT_ID",
6770
"AZURE_CLIENT_SECRET",
6871
"AZURE_TENANT_ID",

sdk/attestation/attestation/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"@azure/core-http": "^1.2.0",
99
"@azure/core-tracing": "1.0.0-preview.11",
1010
"@azure/logger": "^1.0.0",
11-
"tslib": "^2.0.0"
11+
"tslib": "^2.0.0",
12+
"jsrsasign": "^8.0.12"
1213
},
1314
"keywords": [
1415
"node",
@@ -41,7 +42,6 @@
4142
"chai-as-promised": "^7.1.1",
4243
"dotenv": "^8.2.0",
4344
"eslint": "^7.15.0",
44-
"jsrsasign": "^8.0.12",
4545
"karma": "^6.2.0",
4646
"karma-chrome-launcher": "^3.0.0",
4747
"karma-coverage": "^2.0.0",
@@ -94,7 +94,7 @@
9494
"integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"",
9595
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
9696
"lint:fix": "eslint package.json api-extractor.json test --ext .ts --fix --fix-type [problem,suggestion]",
97-
"lint": "eslint package.json api-extractor.json test --ext .ts",
97+
"lint": "eslint package.json api-extractor.json src test --ext .ts",
9898
"pack": "npm pack 2>&1",
9999
"prebuild": "npm run clean",
100100
"test": "npm run clean && npm run build:test && npm run unit-test",

0 commit comments

Comments
 (0)