Skip to content

Commit de5cee4

Browse files
committed
Allow PCCS url to be passed on command line
1 parent e1c92e5 commit de5cee4

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
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: 2 additions & 2 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 {

src/main.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ enum CliCommand {
4949
/// Optional path to file containing JSON measurements to be enforced on the server
5050
#[arg(long)]
5151
server_measurements: Option<PathBuf>,
52-
#[arg(long)]
5352
/// Additional CA certificate to verify against (PEM) Defaults to no additional TLS certs.
53+
#[arg(long)]
5454
tls_ca_certificate: Option<PathBuf>,
55+
/// The URL of a PCCS to use when verifying DCAP attestations. Defaults to Intel PCS.
56+
#[arg(long)]
57+
pccs_url: Option<String>,
5558
// TODO missing:
5659
// Name: "dev-dummy-dcap",
5760
// EnvVars: []string{"DEV_DUMMY_DCAP"},
@@ -81,6 +84,9 @@ enum CliCommand {
8184
/// Optional path to file containing JSON measurements to be enforced on the client
8285
#[arg(long)]
8386
client_measurements: Option<PathBuf>,
87+
/// The URL of a PCCS to use when verifying DCAP attestations. Defaults to Intel PCS.
88+
#[arg(long)]
89+
pccs_url: Option<String>,
8490
// TODO missing:
8591
// Name: "listen-addr-healthcheck",
8692
// EnvVars: []string{"LISTEN_ADDR_HEALTHCHECK"},
@@ -98,6 +104,9 @@ enum CliCommand {
98104
/// Optional path to file containing JSON measurements to be enforced on the server
99105
#[arg(long)]
100106
server_measurements: Option<PathBuf>,
107+
/// The URL of a PCCS to use when verifying DCAP attestations. Defaults to Intel PCS.
108+
#[arg(long)]
109+
pccs_url: Option<String>,
101110
},
102111
}
103112

@@ -132,6 +141,7 @@ async fn main() -> anyhow::Result<()> {
132141
client_attestation_type,
133142
server_measurements,
134143
tls_ca_certificate,
144+
pccs_url,
135145
} => {
136146
let target_addr = target_addr
137147
.strip_prefix("https://")
@@ -153,9 +163,10 @@ async fn main() -> anyhow::Result<()> {
153163
};
154164

155165
let attestation_verifier = match server_measurements {
156-
Some(server_measurements) => {
157-
get_measurements_from_file(server_measurements).await?
158-
}
166+
Some(server_measurements) => AttestationVerifier {
167+
accepted_measurements: get_measurements_from_file(server_measurements).await?,
168+
pccs_url,
169+
},
159170
None => AttestationVerifier::do_not_verify(),
160171
};
161172

@@ -199,6 +210,7 @@ async fn main() -> anyhow::Result<()> {
199210
client_auth,
200211
server_attestation_type,
201212
client_measurements,
213+
pccs_url,
202214
} => {
203215
let tls_cert_and_chain =
204216
load_tls_cert_and_key(tls_certificate_path, tls_private_key_path)?;
@@ -210,9 +222,10 @@ async fn main() -> anyhow::Result<()> {
210222
let local_attestation_generator = server_attestation_type.get_quote_generator()?;
211223

212224
let attestation_verifier = match client_measurements {
213-
Some(client_measurements) => {
214-
get_measurements_from_file(client_measurements).await?
215-
}
225+
Some(client_measurements) => AttestationVerifier {
226+
accepted_measurements: get_measurements_from_file(client_measurements).await?,
227+
pccs_url,
228+
},
216229
None => AttestationVerifier::do_not_verify(),
217230
};
218231

@@ -235,11 +248,13 @@ async fn main() -> anyhow::Result<()> {
235248
CliCommand::GetTlsCert {
236249
server,
237250
server_measurements,
251+
pccs_url,
238252
} => {
239253
let attestation_verifier = match server_measurements {
240-
Some(server_measurements) => {
241-
get_measurements_from_file(server_measurements).await?
242-
}
254+
Some(server_measurements) => AttestationVerifier {
255+
accepted_measurements: get_measurements_from_file(server_measurements).await?,
256+
pccs_url,
257+
},
243258
None => AttestationVerifier::do_not_verify(),
244259
};
245260
let cert_chain = get_tls_cert(server, attestation_verifier).await?;

0 commit comments

Comments
 (0)