11pub mod measurements;
22
33use measurements:: { CvmImageMeasurements , MeasurementRecord , Measurements , PlatformMeasurements } ;
4+ use parity_scale_codec:: { Decode , Encode } ;
45use serde:: { Deserialize , Serialize } ;
56use std:: {
67 fmt:: { self , Display , Formatter } ,
@@ -22,13 +23,19 @@ use x509_parser::prelude::*;
2223/// For fetching collateral directly from intel, if no PCCS is specified
2324const PCS_URL : & str = "https://api.trustedservices.intel.com" ;
2425
25- #[ derive( Debug , Serialize , Deserialize ) ]
26+ /// This is the type sent over the channel to provide an attestation
27+ #[ derive( Debug , Serialize , Deserialize , Encode , Decode ) ]
2628pub struct AttesationPayload {
29+ /// What CVM platform is used (including none)
2730 pub attestation_type : AttestationType ,
31+ /// The attestation evidence as bytes - in the case of DCAP this is a quote
2832 pub attestation : Vec < u8 > ,
2933}
3034
3135impl AttesationPayload {
36+ /// Given an attestation generator (quote generation function for a specific platform)
37+ /// return an attestation
38+ /// This also takes the certificate chain and exporter as they are given as input to the attestation
3239 pub fn from_attestation_generator (
3340 cert_chain : & [ CertificateDer < ' _ > ] ,
3441 exporter : [ u8 ; 32 ] ,
@@ -39,6 +46,15 @@ impl AttesationPayload {
3946 attestation : attesation_generator. create_attestation ( cert_chain, exporter) ?,
4047 } )
4148 }
49+
50+ /// Create an empty attestation payload for the case that we are running in a non-confidential
51+ /// environment
52+ pub fn without_attestation ( ) -> Self {
53+ Self {
54+ attestation_type : AttestationType :: None ,
55+ attestation : Vec :: new ( ) ,
56+ }
57+ }
4258}
4359
4460/// Type of attestaion used
@@ -73,6 +89,7 @@ impl AttestationType {
7389 }
7490 }
7591
92+ /// Get a quote generator for this type of platform
7693 pub fn get_quote_generator ( & self ) -> Result < Arc < dyn QuoteGenerator > , AttestationError > {
7794 match self {
7895 AttestationType :: None => Ok ( Arc :: new ( NoQuoteGenerator ) ) ,
@@ -85,6 +102,23 @@ impl AttestationType {
85102 }
86103}
87104
105+ /// SCALE encode (used over the wire)
106+ impl Encode for AttestationType {
107+ fn encode ( & self ) -> Vec < u8 > {
108+ self . as_str ( ) . encode ( )
109+ }
110+ }
111+
112+ /// SCALE decode
113+ impl Decode for AttestationType {
114+ fn decode < I : parity_scale_codec:: Input > (
115+ input : & mut I ,
116+ ) -> Result < Self , parity_scale_codec:: Error > {
117+ let s: String = String :: decode ( input) ?;
118+ serde_json:: from_str ( & format ! ( "\" {s}\" " ) ) . map_err ( |_| "Failed to decode enum" . into ( ) )
119+ }
120+ }
121+
88122impl Display for AttestationType {
89123 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
90124 f. write_str ( self . as_str ( ) )
@@ -104,9 +138,15 @@ pub trait QuoteGenerator: Send + Sync + 'static {
104138 ) -> Result < Vec < u8 > , AttestationError > ;
105139}
106140
141+ /// Allows remote attestations to be verified
107142#[ derive( Clone , Debug ) ]
108143pub struct AttestationVerifier {
144+ /// The measurement values we accept
145+ ///
146+ /// If this is empty, anything will be accepted - but measurements are always injected into HTTP
147+ /// headers, so that they can be verified upstream
109148 accepted_measurements : Vec < MeasurementRecord > ,
149+ /// A PCCS service to use - defaults to Intel PCS
110150 pccs_url : Option < String > ,
111151}
112152
0 commit comments