Skip to content

Commit 84eda4f

Browse files
committed
fix: use async AMD SNP KDS fetch
1 parent 9a30faa commit 84eda4f

7 files changed

Lines changed: 303 additions & 107 deletions

File tree

Cargo.lock

Lines changed: 3 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
@@ -127,6 +127,7 @@ futures = "0.3.31"
127127
git-version = "0.3.9"
128128
libc = "0.2.171"
129129
log = "0.4.26"
130+
moka = { version = "0.12.15", default-features = false, features = ["sync"] }
130131
notify = "8.0.0"
131132
rand = "0.8.5"
132133
tracing = "0.1.40"

dstack-attest/src/attestation.rs

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use tpm_qvl::verify::VerifiedReport as TpmVerifiedReport;
3131
// Re-export TpmQuote from tpm-types
3232
pub use tpm_types::TpmQuote;
3333

34-
use crate::amd_sev_snp::VerifiedAmdSnpReport;
34+
use crate::amd_sev_snp::{AmdKdsClient, VerifiedAmdSnpReport};
3535
pub use crate::v1::{Attestation as AttestationV1, PlatformEvidence, StackEvidence};
3636

3737
pub const SNP_REPORT_DATA_RANGE: std::ops::Range<usize> = 0x50..0x90;
@@ -757,7 +757,27 @@ impl AttestationV1 {
757757
pub async fn verify_with_time(
758758
self,
759759
pccs_url: Option<&str>,
760-
_now: Option<SystemTime>,
760+
now: Option<SystemTime>,
761+
) -> Result<VerifiedAttestation> {
762+
self.verify_with_time_with_amd_kds_client(pccs_url, now, None)
763+
.await
764+
}
765+
766+
/// Verify the quote with a caller-owned AMD KDS client.
767+
pub async fn verify_with_amd_kds_client(
768+
self,
769+
pccs_url: Option<&str>,
770+
amd_kds_client: &AmdKdsClient,
771+
) -> Result<VerifiedAttestation> {
772+
self.verify_with_time_with_amd_kds_client(pccs_url, None, Some(amd_kds_client))
773+
.await
774+
}
775+
776+
async fn verify_with_time_with_amd_kds_client(
777+
self,
778+
pccs_url: Option<&str>,
779+
now: Option<SystemTime>,
780+
amd_kds_client: Option<&AmdKdsClient>,
761781
) -> Result<VerifiedAttestation> {
762782
let AttestationV1 {
763783
version: _,
@@ -836,7 +856,7 @@ impl AttestationV1 {
836856
&nsm.nsm_quote,
837857
nsm_qvl::AWS_NITRO_ENCLAVES_ROOT_G1,
838858
None,
839-
_now,
859+
now,
840860
)
841861
.context("NSM attestation verification failed")?;
842862
let Some(user_data) = verified_report.user_data.clone() else {
@@ -862,11 +882,17 @@ impl AttestationV1 {
862882
cert_chain,
863883
mr_config,
864884
} => {
865-
let verified = crate::amd_sev_snp::verify_amd_snp_evidence_with_kds_fallback(
866-
report,
867-
cert_chain,
868-
&report_data,
869-
)?;
885+
let owned_kds_client;
886+
let kds_client = match amd_kds_client {
887+
Some(client) => client,
888+
None => {
889+
owned_kds_client = AmdKdsClient::new()?;
890+
&owned_kds_client
891+
}
892+
};
893+
let verified = kds_client
894+
.verify_evidence_with_kds_fallback(report, cert_chain, &report_data)
895+
.await?;
870896
verify_snp_mr_config_host_data(mr_config, &verified.host_data)?;
871897
DstackVerifiedReport::DstackAmdSevSnp(verified)
872898
}
@@ -1751,18 +1777,44 @@ impl Attestation {
17511777
self,
17521778
pccs_url: Option<&str>,
17531779
now: Option<SystemTime>,
1780+
) -> Result<VerifiedAttestation> {
1781+
self.verify_with_time_with_amd_kds_client(pccs_url, now, None)
1782+
.await
1783+
}
1784+
1785+
/// Verify the quote with a caller-owned AMD KDS client.
1786+
pub async fn verify_with_amd_kds_client(
1787+
self,
1788+
pccs_url: Option<&str>,
1789+
amd_kds_client: &AmdKdsClient,
1790+
) -> Result<VerifiedAttestation> {
1791+
self.verify_with_time_with_amd_kds_client(pccs_url, None, Some(amd_kds_client))
1792+
.await
1793+
}
1794+
1795+
async fn verify_with_time_with_amd_kds_client(
1796+
self,
1797+
pccs_url: Option<&str>,
1798+
now: Option<SystemTime>,
1799+
amd_kds_client: Option<&AmdKdsClient>,
17541800
) -> Result<VerifiedAttestation> {
17551801
let report = match &self.quote {
17561802
AttestationQuote::DstackTdx(q) => {
17571803
let report = self.verify_tdx(pccs_url, &q.quote).await?;
17581804
DstackVerifiedReport::DstackTdx(report)
17591805
}
17601806
AttestationQuote::DstackAmdSevSnp(q) => {
1761-
let verified = crate::amd_sev_snp::verify_amd_snp_evidence_with_kds_fallback(
1762-
&q.report,
1763-
&q.cert_chain,
1764-
&self.report_data,
1765-
)?;
1807+
let owned_kds_client;
1808+
let kds_client = match amd_kds_client {
1809+
Some(client) => client,
1810+
None => {
1811+
owned_kds_client = AmdKdsClient::new()?;
1812+
&owned_kds_client
1813+
}
1814+
};
1815+
let verified = kds_client
1816+
.verify_evidence_with_kds_fallback(&q.report, &q.cert_chain, &self.report_data)
1817+
.await?;
17661818
verify_snp_mr_config_host_data(&q.mr_config, &verified.host_data)?;
17671819
DstackVerifiedReport::DstackAmdSevSnp(verified)
17681820
}

sev-snp-qvl/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ description = "AMD SEV-SNP Quote Verification Library"
1313
[dependencies]
1414
anyhow.workspace = true
1515
hex.workspace = true
16-
reqwest = { workspace = true, features = ["blocking"] }
16+
moka.workspace = true
17+
reqwest.workspace = true
1718
sev.workspace = true
19+
tokio = { workspace = true, features = ["rt", "time"] }

0 commit comments

Comments
 (0)