-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,60 @@ | ||
# Solidity AWS Nitro Attestation validator | ||
|
||
This repo provides solidity contracts for the verification of attestations generated by AWS Nitro Enclaves, as outlined in | ||
[this doc](https://github.com/aws/aws-nitro-enclaves-nsm-api/blob/4b851f3006c6fa98f23dcffb2cba03b39de9b8af/docs/attestation_process.md#3-attestation-document-validation). | ||
|
||
Note it costs around 63m gas to validate an attestation with no prior verified certs. | ||
You can break this up into smaller transactions by verifying each cert in the chain separately. | ||
You can call `CertManager.verifyCert` for each cert in the attestation `cabundle`. | ||
|
||
## Usage | ||
|
||
1. Deploy the `CertManager` separately. | ||
2. Validate Nitro attestation in your contract: | ||
|
||
```solidity | ||
pragma solidity ^0.8.0; | ||
import {NitroValidator} from "@nitro-validator/NitroValidator.sol"; | ||
import {CborDecode} from "@nitro-validator/CborDecode.sol"; | ||
import {CertManager} from "@nitro-validator/CertManager.sol"; | ||
contract Validator is NitroValidator { | ||
using CborDecode for bytes; | ||
uint256 public constant MAX_AGE = 60 minutes; | ||
bytes32 public constant PCR0 = keccak256("some PCR0 value"); | ||
constructor(CertManager certManager) NitroValidator(certManager) {} | ||
function registerSigner(bytes calldata attestationTbs, bytes calldata signature) external onlyOwner { | ||
Ptrs memory ptrs = validateAttestation(attestationTbs, signature); | ||
bytes32 pcr0 = attestationTbs.keccak(ptrs.pcrs[0]); | ||
require(pcr0 == PCR0, "invalid pcr0 in attestation"); | ||
require(ptrs.timestamp + MAX_AGE > block.timestamp, "attestation too old"); | ||
bytes memory publicKey = attestationTbs.slice(ptrs.publicKey); | ||
// do something with the public key, user data, etc | ||
} | ||
} | ||
``` | ||
3. Convert an attestation document to a attestationTbs / signature (TBS means to-be-signed). | ||
Note it's cheaper to perform this conversion offchain (e.g. using `cast call`). | ||
```solidity | ||
bytes memory attestation = hex"84.."; | ||
(bytes memory attestationTbs, bytes memory signature) = validator.decodeAttestationTbs(attestation); | ||
validator.validateAttestation(attestationTbs, signature); | ||
``` | ||
|
||
## Build | ||
|
||
```sh | ||
forge install | ||
forge build | ||
``` | ||
|
||
## Test | ||
|
||
```sh | ||
forge test | ||
``` |