Skip to content

Commit de3933d

Browse files
committed
refactoring contract structure
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent ad16a56 commit de3933d

12 files changed

+323
-258
lines changed

contracts/AVRValidator.sol

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {Base64} from "base64/base64.sol";
77
import {Asn1Decode, NodePtr} from "./Asn1Decode.sol";
88
import {LCPUtils} from "./LCPUtils.sol";
99
import {ILCPClientErrors} from "./ILCPClientErrors.sol";
10+
import {RemoteAttestation} from "./RemoteAttestation.sol";
1011

1112
/**
1213
* @dev AVRValidator provides the validation functions of Intel's Attestation Verification Report(AVR)
@@ -21,10 +22,6 @@ library AVRValidator {
2122
0x2a864886f70d01010b0000000000000000000000000000000000000000000000;
2223
// OID_RSA_ENCRYPTION is the OID of rsaEncryption(1.2.840.113549.1.1.1)
2324
bytes32 internal constant OID_RSA_ENCRYPTION = 0x2a864886f70d0101010000000000000000000000000000000000000000000000;
24-
// FLAG_DISALLOWED indicates that the advisory or quote status is not allowed.
25-
uint256 internal constant FLAG_DISALLOWED = 0;
26-
// FLAG_ALLOWED indicates that the advisory or quote status is allowed.
27-
uint256 internal constant FLAG_ALLOWED = 1;
2825
// '"'
2926
bytes32 internal constant CHAR_DOUBLE_QUOTE = bytes32(hex"22");
3027
// ','
@@ -50,13 +47,6 @@ library AVRValidator {
5047
uint256 notAfter; // seconds since epoch
5148
}
5249

53-
struct ReportAllowedStatus {
54-
// quote status => flag(0: not allowed, 1: allowed)
55-
mapping(string => uint256) allowedQuoteStatuses;
56-
// advisory id => flag(0: not allowed, 1: allowed)
57-
mapping(string => uint256) allowedAdvisories;
58-
}
59-
6050
// ------------------ Public functions ------------------
6151

6252
struct ReportExtractedElements {
@@ -70,7 +60,7 @@ library AVRValidator {
7060
bool developmentMode,
7161
AVRValidator.RSAParams storage verifiedRootCAParams,
7262
mapping(bytes32 => AVRValidator.RSAParams) storage verifiedSigningRSAParams,
73-
ReportAllowedStatus storage allowedStatuses,
63+
RemoteAttestation.ReportAllowedStatus storage allowedStatuses,
7464
bytes calldata report,
7565
bytes calldata signingCert,
7666
bytes calldata signature
@@ -174,7 +164,7 @@ library AVRValidator {
174164
function validateAndExtractElements(
175165
bool developmentMode,
176166
bytes calldata report,
177-
ReportAllowedStatus storage allowedStatus
167+
RemoteAttestation.ReportAllowedStatus storage allowedStatus
178168
) public view returns (ReportExtractedElements memory) {
179169
// find 'timestamp' key
180170
(uint256 i, bytes memory timestamp) = consumeTimestampReportJSON(report, 0);
@@ -190,7 +180,8 @@ library AVRValidator {
190180
// skip the validation for quote status and advisories if status is "OK"
191181
if (!(status.length == 2 && status[0] == 0x4f && status[1] == 0x4b)) {
192182
require(
193-
allowedStatus.allowedQuoteStatuses[string(status)] == FLAG_ALLOWED, "the quote status is not allowed"
183+
allowedStatus.allowedQuoteStatuses[string(status)] == RemoteAttestation.FLAG_ALLOWED,
184+
"the quote status is not allowed"
194185
);
195186
bytes32 h = keccak256(status);
196187
if (
@@ -263,13 +254,13 @@ library AVRValidator {
263254
}
264255
} else if (chr == CHAR_COMMA) {
265256
require(
266-
allowedAdvisories[string(report[lastStart:offset - 1])] == FLAG_ALLOWED,
257+
allowedAdvisories[string(report[lastStart:offset - 1])] == RemoteAttestation.FLAG_ALLOWED,
267258
"disallowed advisory is included"
268259
);
269260
} else if (chr == CHAR_LIST_END) {
270261
if (offset - lastStart > 0) {
271262
require(
272-
allowedAdvisories[string(report[lastStart:offset - 1])] == FLAG_ALLOWED,
263+
allowedAdvisories[string(report[lastStart:offset - 1])] == RemoteAttestation.FLAG_ALLOWED,
273264
"disallowed advisory is included"
274265
);
275266
}

0 commit comments

Comments
 (0)