From a01a1abe44de63befe9496114451fc3b641d4cff Mon Sep 17 00:00:00 2001 From: Ziqi Huang Date: Thu, 20 Oct 2022 17:02:29 -0700 Subject: [PATCH] Create dataclass for Attestation Document (#454) Summary: Pull Request resolved: https://github.com/facebookresearch/fbpcp/pull/454 ## Context Given an attestation document, Attestation Service is able to validate the document utilizing different attestation providers. design doc: https://docs.google.com/document/d/13EnDLiFY-Zn5AIFsxjdFY8TW0m9lHOcF7XbSr9_dBjE/edit# The attestation document format were aligned as: ``` { "policy": { "policy_name": "BINARY_MATCH", "params": { "package_name": "ls", "version": "1.0" } }, "measurements": [ { "key": "MD5", "value": "" } ] } ``` ## This commit Create dataclass for attestation document Differential Revision: D40365313 fbshipit-source-id: 66ef66de416924188eac6c038bbbd09fb3a02425 --- fbpcp/entity/attestation_document.py | 38 ++++++++++++++++++++++++++++ fbpcp/entity/measurement.py | 17 +++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 fbpcp/entity/attestation_document.py create mode 100644 fbpcp/entity/measurement.py diff --git a/fbpcp/entity/attestation_document.py b/fbpcp/entity/attestation_document.py new file mode 100644 index 00000000..168bda90 --- /dev/null +++ b/fbpcp/entity/attestation_document.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# pyre-strict +from dataclasses import dataclass +from enum import Enum +from typing import List, Optional + +from dataclasses_json import dataclass_json +from fbpcp.entity.measurement import Measurement + + +class PolicyName(str, Enum): + BINARY_MATCH = "BINARY_MATCH" + + +@dataclass_json +@dataclass +class PolicyParams: + package_name: Optional[str] + version: Optional[str] + + +@dataclass_json +@dataclass +class AttestationPolicy: + policy_name: PolicyName + params: PolicyParams + + +@dataclass_json +@dataclass +class AttestationDocument: + policy: AttestationPolicy + measurements: List[Measurement] diff --git a/fbpcp/entity/measurement.py b/fbpcp/entity/measurement.py new file mode 100644 index 00000000..1dbf42f1 --- /dev/null +++ b/fbpcp/entity/measurement.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# pyre-strict +from dataclasses import dataclass + +from dataclasses_json import dataclass_json + + +@dataclass_json +@dataclass +class Measurement: + key: str + value: str