1- use crate :: attestation:: { AttestationError , AttestationType , AttestationVerifier } ;
1+ use crate :: attestation:: { AttestationError , AttestationType } ;
22use std:: { collections:: HashMap , path:: PathBuf } ;
33
44use dcap_qvl:: quote:: Report ;
@@ -9,11 +9,14 @@ use thiserror::Error;
99/// Measurements determined by the CVM platform
1010#[ derive( Clone , PartialEq , Debug ) ]
1111pub struct PlatformMeasurements {
12+ /// MRTD register value
1213 pub mrtd : [ u8 ; 48 ] ,
14+ /// RTMR0 register value
1315 pub rtmr0 : [ u8 ; 48 ] ,
1416}
1517
1618impl PlatformMeasurements {
19+ /// Given a quote from the dcap_qvl library, extract the platform measurements
1720 pub fn from_dcap_qvl_quote ( quote : & dcap_qvl:: quote:: Quote ) -> Result < Self , AttestationError > {
1821 let report = match quote. report {
1922 Report :: TD10 ( report) => report,
@@ -36,15 +39,19 @@ impl PlatformMeasurements {
3639 }
3740}
3841
39- /// Measurements determined by the CVM image
42+ /// Measurements determined by the CVM image or application
4043#[ derive( Clone , PartialEq , Debug ) ]
4144pub struct CvmImageMeasurements {
45+ /// RTMR1 register value
4246 pub rtmr1 : [ u8 ; 48 ] ,
47+ /// RTMR2 register value
4348 pub rtmr2 : [ u8 ; 48 ] ,
49+ /// RTMR3 register value
4450 pub rtmr3 : [ u8 ; 48 ] ,
4551}
4652
4753impl CvmImageMeasurements {
54+ /// Given a quote from the dcap_qvl library, extract the CVM image / application measurements
4855 pub fn from_dcap_qvl_quote ( quote : & dcap_qvl:: quote:: Quote ) -> Result < Self , AttestationError > {
4956 let report = match quote. report {
5057 Report :: TD10 ( report) => report,
@@ -69,13 +76,15 @@ impl CvmImageMeasurements {
6976 }
7077}
7178
79+ /// A full set of measurement register values
7280#[ derive( Debug , Clone , PartialEq ) ]
7381pub struct Measurements {
7482 pub platform : PlatformMeasurements ,
7583 pub cvm_image : CvmImageMeasurements ,
7684}
7785
7886impl Measurements {
87+ /// Convert to the JSON format used in HTTP headers
7988 pub fn to_header_format ( & self ) -> Result < HeaderValue , MeasurementFormatError > {
8089 let mut measurements_map = HashMap :: new ( ) ;
8190 measurements_map. insert ( 0 , hex:: encode ( self . platform . mrtd ) ) ;
@@ -88,6 +97,7 @@ impl Measurements {
8897 ) ?) ?)
8998 }
9099
100+ /// Parse the JSON used in HTTP headers
91101 pub fn from_header_format ( input : & str ) -> Result < Self , MeasurementFormatError > {
92102 let measurements_map: HashMap < u32 , String > = serde_json:: from_str ( input) ?;
93103 let measurements_map: HashMap < u32 , [ u8 ; 48 ] > = measurements_map
@@ -126,6 +136,7 @@ impl Measurements {
126136 }
127137}
128138
139+ /// An error when converting measurements / to or from HTTP header format
129140#[ derive( Error , Debug ) ]
130141pub enum MeasurementFormatError {
131142 #[ error( "JSON: {0}" ) ]
@@ -144,17 +155,21 @@ pub enum MeasurementFormatError {
144155 BadLength ,
145156}
146157
158+ /// An accepted measurement value given in the measurements file
147159#[ derive( Clone , Debug ) ]
148160pub struct MeasurementRecord {
161+ /// An identifier, for example the name and version of the corresponding OS image
149162 pub measurement_id : String ,
163+ /// The associated attestation platform
150164 pub attestation_type : AttestationType ,
165+ /// The expected measurement register values
151166 pub measurements : Measurements ,
152167}
153168
154169/// Given the path to a JSON file containing measurements, return a [Vec<MeasurementRecord>]
155170pub async fn get_measurements_from_file (
156171 measurement_file : PathBuf ,
157- ) -> Result < AttestationVerifier , MeasurementFormatError > {
172+ ) -> Result < Vec < MeasurementRecord > , MeasurementFormatError > {
158173 #[ derive( Debug , Deserialize ) ]
159174 struct MeasurementRecordSimple {
160175 measurement_id : String ,
@@ -202,10 +217,7 @@ pub async fn get_measurements_from_file(
202217 } ) ;
203218 }
204219
205- Ok ( AttestationVerifier {
206- accepted_measurements : measurements,
207- pccs_url : None ,
208- } )
220+ Ok ( measurements)
209221}
210222
211223#[ cfg( test) ]
0 commit comments