Compare commits

...

1 Commits

Author SHA1 Message Date
p30629751 682bfb9785 ADD file via upload 2023-05-20 11:19:12 +08:00
1 changed files with 65 additions and 0 deletions

65
verify_quote.sol Normal file
View File

@ -0,0 +1,65 @@
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
// EIP712 EIP712
contract QuoteVerifier is EIP712 {
using Address for address;
using ECDSA for bytes32;
//
mapping(address => bool) public validCertificates;
// Quote结构体Quote字节数据
struct Quote {
bytes48 quoteHeader;
bytes16 cpuSvn;
bytes4 miscSelect;
bytes28 reserved1;
bytes16 attributes;
bytes32 mrEnclave;
bytes32 reserved2;
bytes32 mrSigner;
bytes96 reserved3;
bytes2 isvProdId;
bytes2 isvSvn;
bytes60 reserved4;
bytes64 reportData;
bytes4 signatureDataLen;
bytes signatureData;
}
// EIP712 domainName version
constructor(string memory domainName, string memory version) EIP712(domainName, version) {}
// Quote是否合法使 calldata
function verifyQuote(
address signer, //
bytes calldata quoteBytes, // Quote数据的字节数组
) external view returns (bool) {
// Quote
Quote memory quote = abi.decode(quoteBytes, (Quote));
//
require(validCertificates[signer], "证书无效");
//
bytes32 messageHash = encodeDataHash(quote);
require(signer == messageHash.recover(quote.signatureData), "签名无效");
// Enclave Measurement是否正确
bytes32 expectedMeasurementHash = bytes32(0x...); // Trusted measurement hash
require(quote.enclaveHash == expectedMeasurementHash, "Enclave Measurement无效");
// Report Data是否正确
bytes32 reportDataHash = bytes32(0x...); // Trusted Report Data;
require(quote.reportData == reportDataHash, "Report Data无效");
// Quote是否在有效期内
require(block.timestamp <= quote.timestamp, "Quote已过期");
return true;
}
}