Skip to content

Commit 6bf1198

Browse files
committed
Merge main
2 parents 6f7e156 + 7f4cd74 commit 6bf1198

File tree

4 files changed

+264
-34
lines changed

4 files changed

+264
-34
lines changed

src/attestation/measurements.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::attestation::{AttestationError, AttestationType, AttestationVerifier};
1+
use crate::attestation::{AttestationError, AttestationType};
22
use std::{collections::HashMap, path::PathBuf};
33

44
use dcap_qvl::quote::Report;
@@ -9,11 +9,14 @@ use thiserror::Error;
99
/// Measurements determined by the CVM platform
1010
#[derive(Clone, PartialEq, Debug)]
1111
pub struct PlatformMeasurements {
12+
/// MRTD register value
1213
pub mrtd: [u8; 48],
14+
/// RTMR0 register value
1315
pub rtmr0: [u8; 48],
1416
}
1517

1618
impl 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)]
4144
pub 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

4753
impl 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)]
7381
pub struct Measurements {
7482
pub platform: PlatformMeasurements,
7583
pub cvm_image: CvmImageMeasurements,
7684
}
7785

7886
impl 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)]
130141
pub 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)]
148160
pub 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>]
155170
pub 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)]

src/attestation/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ pub struct AttestationVerifier {
145145
///
146146
/// If this is empty, anything will be accepted - but measurements are always injected into HTTP
147147
/// headers, so that they can be verified upstream
148-
accepted_measurements: Vec<MeasurementRecord>,
148+
pub accepted_measurements: Vec<MeasurementRecord>,
149149
/// A PCCS service to use - defaults to Intel PCS
150-
pccs_url: Option<String>,
150+
pub pccs_url: Option<String>,
151151
}
152152

153153
impl AttestationVerifier {
@@ -202,6 +202,9 @@ impl AttestationVerifier {
202202
.await?
203203
}
204204
AttestationType::None => {
205+
if self.has_remote_attestion() {
206+
return Err(AttestationError::AttestationTypeNotAccepted);
207+
}
205208
if attestation_exchange_message.attestation.is_empty() {
206209
return Ok(None);
207210
} else {
@@ -216,7 +219,8 @@ impl AttestationVerifier {
216219
// look through all our accepted measurements
217220
self.accepted_measurements
218221
.iter()
219-
.find(|a| a.attestation_type == attestation_type && a.measurements == measurements);
222+
.find(|a| a.attestation_type == attestation_type && a.measurements == measurements)
223+
.ok_or(AttestationError::MeasurementsNotAccepted)?;
220224

221225
Ok(Some(measurements))
222226
}
@@ -409,4 +413,8 @@ pub enum AttestationError {
409413
QuoteParse(#[from] QuoteParseError),
410414
#[error("Attestation type not supported")]
411415
AttestationTypeNotSupported,
416+
#[error("Attestation type not accepted")]
417+
AttestationTypeNotAccepted,
418+
#[error("Measurements not accepted")]
419+
MeasurementsNotAccepted,
412420
}

0 commit comments

Comments
 (0)