Skip to content

Commit d7472bf

Browse files
authored
make Attest an async trait (#360)
this was motivated by excising `rt` from `AttestSledAgent`, and after looking at uses of Attest elsewhere I think we don't really have much reason to keep the sync interfaces around. this pairs with a change in `vm-attest`, both end up in propolis. I haven't actually tried to pull this into sprockets but this makes AttestIpcc now Send so this when this gets crank-turned over in sprockets we can take a swing at `get_attest_data()` over in `tls/src/keys.rs` there!
1 parent deab8e3 commit d7472bf

File tree

10 files changed

+153
-109
lines changed

10 files changed

+153
-109
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ resolver = "2"
1414

1515
[workspace.dependencies]
1616
anyhow = { version = "1.0.100", default-features = false }
17+
async-trait = "0.1.89"
1718
attest.path = "attest"
1819
chrono = { version = "0.4.42", default-features=false }
1920
clap = { version = "4.5.51", features = ["derive", "env"] }

verifier-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tempfile.workspace = true
2626
dice-verifier.path = "../verifier"
2727
x509-cert = { workspace = true, default-features = true }
2828
serde_json.workspace = true
29+
tokio = { workspace = true, features = ["full"] }
2930

3031
[features]
3132
ipcc = ["dice-verifier/ipcc"]

verifier-cli/src/main.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn get_attest(interface: Interface, log: &Logger) -> Result<Box<dyn Attest>> {
3333
slog::info!(log, "attesting via {interface:?}");
3434
match interface {
3535
#[cfg(feature = "ipcc")]
36-
Interface::Ipcc => Ok(Box::new(AttestIpcc::new()?)),
36+
Interface::Ipcc => Ok(Box::new(AttestIpcc::new())),
3737
Interface::Rot => Ok(Box::new(AttestHiffy::new(AttestTask::Rot))),
3838
#[cfg(feature = "sled-agent")]
3939
Interface::SledAgent(addr) => {
@@ -205,7 +205,8 @@ impl fmt::Display for Encoding {
205205
}
206206
}
207207

208-
fn main() -> Result<()> {
208+
#[tokio::main(flavor = "current_thread")]
209+
async fn main() -> Result<()> {
209210
let args = Args::parse();
210211

211212
let stderr_decorator = slog_term::TermDecorator::new().build();
@@ -246,6 +247,7 @@ fn main() -> Result<()> {
246247
Nonce::try_from(nonce).context("Nonce from file contents")?;
247248
let attestation = attest
248249
.attest(&nonce)
250+
.await
249251
.context("Getting attestation with provided Nonce")?;
250252

251253
// serialize attestation to json & write to file
@@ -261,6 +263,7 @@ fn main() -> Result<()> {
261263
AttestCommand::CertChain => {
262264
let cert_chain = attest
263265
.get_certificates()
266+
.await
264267
.context("Getting attestation certificate chain")?;
265268

266269
for cert in cert_chain {
@@ -277,6 +280,7 @@ fn main() -> Result<()> {
277280
AttestCommand::Log => {
278281
let log = attest
279282
.get_measurement_log()
283+
.await
280284
.context("Getting attestation measurement log")?;
281285
let mut log = serde_json::to_string(&log)
282286
.context("Encode measurement log as JSON")?;
@@ -311,13 +315,16 @@ fn main() -> Result<()> {
311315
// Use the directory provided by the caller to hold intermediate
312316
// files, or fall back to a temp dir.
313317
let platform_id = match work_dir {
314-
Some(w) => verify(
315-
attest.as_ref(),
316-
ca_cert.as_deref(),
317-
corpus.as_deref(),
318-
self_signed,
319-
&w,
320-
)?,
318+
Some(w) => {
319+
verify(
320+
attest.as_ref(),
321+
ca_cert.as_deref(),
322+
corpus.as_deref(),
323+
self_signed,
324+
&w,
325+
)
326+
.await?
327+
}
321328
None => {
322329
if corpus.is_none() && !skip_appraisal {
323330
return Err(anyhow!("no corpus provided but not instructed to skip measurement log appraisal"));
@@ -329,7 +336,8 @@ fn main() -> Result<()> {
329336
corpus.as_deref(),
330337
self_signed,
331338
work_dir.as_ref(),
332-
)?
339+
)
340+
.await?
333341
}
334342
};
335343

@@ -358,7 +366,7 @@ fn main() -> Result<()> {
358366
verify_measurements(&cert_chain, &log, &corpus)?;
359367
}
360368
AttestCommand::MeasurementSet => {
361-
let set = measurement_set(attest.as_ref())?;
369+
let set = measurement_set(attest.as_ref()).await?;
362370
for item in set.into_iter() {
363371
println!("* {item}");
364372
}
@@ -368,15 +376,17 @@ fn main() -> Result<()> {
368376
Ok(())
369377
}
370378

371-
fn measurement_set(attest: &dyn Attest) -> Result<MeasurementSet> {
379+
async fn measurement_set(attest: &dyn Attest) -> Result<MeasurementSet> {
372380
info!("getting measurement log");
373381
let log = attest
374382
.get_measurement_log()
383+
.await
375384
.context("Get measurement log from attestor")?;
376385
let mut cert_chain = Vec::new();
377386

378387
let certs = attest
379388
.get_certificates()
389+
.await
380390
.context("Get certificate chain from attestor")?;
381391

382392
for (index, cert) in certs.iter().enumerate() {
@@ -431,7 +441,7 @@ fn verify_measurements(
431441
.context("Verify measurements")
432442
}
433443

434-
fn verify(
444+
async fn verify(
435445
attest: &dyn Attest,
436446
ca_cert: Option<&Path>,
437447
corpus: Option<&Path>,
@@ -453,6 +463,7 @@ fn verify(
453463
info!("getting attestation");
454464
let attestation = attest
455465
.attest(&nonce)
466+
.await
456467
.context("Get attestation with nonce")?;
457468

458469
// serialize attestation to json & write to file
@@ -471,6 +482,7 @@ fn verify(
471482
info!("getting measurement log");
472483
let log = attest
473484
.get_measurement_log()
485+
.await
474486
.context("Get measurement log from attestor")?;
475487
let mut log = serde_json::to_string(&log)
476488
.context("Serialize measurement log to JSON")?;
@@ -494,6 +506,7 @@ fn verify(
494506

495507
let certs = attest
496508
.get_certificates()
509+
.await
497510
.context("Get certificate chain from attestor")?;
498511

499512
// the first cert in the chain / the leaf cert is the one

verifier/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MPL-2.0"
77

88
[dependencies]
99
attest-data = { path = "../attest-data", features = ["std"] }
10+
async-trait.workspace = true
1011
const-oid.workspace = true
1112
ed25519-dalek = { workspace = true, features = ["std"] }
1213
env_logger.workspace = true
@@ -20,7 +21,7 @@ sha3.workspace = true
2021
sled-agent-client = { workspace = true, optional = true }
2122
sled-agent-types-versions = { workspace = true, optional = true }
2223
slog.workspace = true
23-
tokio = { workspace = true, features = [ "net", "rt", "time" ], optional = true }
24+
tokio = { workspace = true, features = [ "net", "rt", "time", "process" ] }
2425
tempfile.workspace = true
2526
thiserror.workspace = true
2627
x509-cert = { workspace = true, default-features = true }
@@ -33,4 +34,4 @@ attest-data = { path = "../attest-data", features = ["std", "testing"] }
3334
testing = []
3435
ipcc = ["libipcc"]
3536
mock = ["ed25519-dalek/pem"]
36-
sled-agent = ["sled-agent-client", "sled-agent-types-versions", "tokio"]
37+
sled-agent = ["sled-agent-client", "sled-agent-types-versions"]

0 commit comments

Comments
 (0)