Skip to content

Commit dcd5bbf

Browse files
committed
fix: use async AMD SNP KDS fetch
1 parent 17a95ca commit dcd5bbf

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
@@ -122,6 +122,7 @@ futures = "0.3.31"
122122
git-version = "0.3.9"
123123
libc = "0.2.171"
124124
log = "0.4.26"
125+
moka = { version = "0.12.15", default-features = false, features = ["sync"] }
125126
notify = "8.0.0"
126127
rand = "0.8.5"
127128
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
use crate::v1::{
3636
is_tdx_acpi_data_event, is_tdx_lite_config, strip_tdx_event_log_for_config,
3737
strip_tdx_runtime_event_log,
@@ -768,7 +768,27 @@ impl AttestationV1 {
768768
pub async fn verify_with_time(
769769
self,
770770
pccs_url: Option<&str>,
771-
_now: Option<SystemTime>,
771+
now: Option<SystemTime>,
772+
) -> Result<VerifiedAttestation> {
773+
self.verify_with_time_with_amd_kds_client(pccs_url, now, None)
774+
.await
775+
}
776+
777+
/// Verify the quote with a caller-owned AMD KDS client.
778+
pub async fn verify_with_amd_kds_client(
779+
self,
780+
pccs_url: Option<&str>,
781+
amd_kds_client: &AmdKdsClient,
782+
) -> Result<VerifiedAttestation> {
783+
self.verify_with_time_with_amd_kds_client(pccs_url, None, Some(amd_kds_client))
784+
.await
785+
}
786+
787+
async fn verify_with_time_with_amd_kds_client(
788+
self,
789+
pccs_url: Option<&str>,
790+
now: Option<SystemTime>,
791+
amd_kds_client: Option<&AmdKdsClient>,
772792
) -> Result<VerifiedAttestation> {
773793
let AttestationV1 {
774794
version: _,
@@ -847,7 +867,7 @@ impl AttestationV1 {
847867
&nsm.nsm_quote,
848868
nsm_qvl::AWS_NITRO_ENCLAVES_ROOT_G1,
849869
None,
850-
_now,
870+
now,
851871
)
852872
.context("NSM attestation verification failed")?;
853873
let Some(user_data) = verified_report.user_data.clone() else {
@@ -873,11 +893,17 @@ impl AttestationV1 {
873893
cert_chain,
874894
mr_config,
875895
} => {
876-
let verified = crate::amd_sev_snp::verify_amd_snp_evidence_with_kds_fallback(
877-
report,
878-
cert_chain,
879-
&report_data,
880-
)?;
896+
let owned_kds_client;
897+
let kds_client = match amd_kds_client {
898+
Some(client) => client,
899+
None => {
900+
owned_kds_client = AmdKdsClient::new()?;
901+
&owned_kds_client
902+
}
903+
};
904+
let verified = kds_client
905+
.verify_evidence_with_kds_fallback(report, cert_chain, &report_data)
906+
.await?;
881907
verify_snp_mr_config_host_data(mr_config, &verified.host_data)?;
882908
DstackVerifiedReport::DstackAmdSevSnp(verified)
883909
}
@@ -1788,18 +1814,44 @@ impl Attestation {
17881814
self,
17891815
pccs_url: Option<&str>,
17901816
now: Option<SystemTime>,
1817+
) -> Result<VerifiedAttestation> {
1818+
self.verify_with_time_with_amd_kds_client(pccs_url, now, None)
1819+
.await
1820+
}
1821+
1822+
/// Verify the quote with a caller-owned AMD KDS client.
1823+
pub async fn verify_with_amd_kds_client(
1824+
self,
1825+
pccs_url: Option<&str>,
1826+
amd_kds_client: &AmdKdsClient,
1827+
) -> Result<VerifiedAttestation> {
1828+
self.verify_with_time_with_amd_kds_client(pccs_url, None, Some(amd_kds_client))
1829+
.await
1830+
}
1831+
1832+
async fn verify_with_time_with_amd_kds_client(
1833+
self,
1834+
pccs_url: Option<&str>,
1835+
now: Option<SystemTime>,
1836+
amd_kds_client: Option<&AmdKdsClient>,
17911837
) -> Result<VerifiedAttestation> {
17921838
let report = match &self.quote {
17931839
AttestationQuote::DstackTdx(q) => {
17941840
let report = self.verify_tdx(pccs_url, &q.quote).await?;
17951841
DstackVerifiedReport::DstackTdx(report)
17961842
}
17971843
AttestationQuote::DstackAmdSevSnp(q) => {
1798-
let verified = crate::amd_sev_snp::verify_amd_snp_evidence_with_kds_fallback(
1799-
&q.report,
1800-
&q.cert_chain,
1801-
&self.report_data,
1802-
)?;
1844+
let owned_kds_client;
1845+
let kds_client = match amd_kds_client {
1846+
Some(client) => client,
1847+
None => {
1848+
owned_kds_client = AmdKdsClient::new()?;
1849+
&owned_kds_client
1850+
}
1851+
};
1852+
let verified = kds_client
1853+
.verify_evidence_with_kds_fallback(&q.report, &q.cert_chain, &self.report_data)
1854+
.await?;
18031855
verify_snp_mr_config_host_data(&q.mr_config, &verified.host_data)?;
18041856
DstackVerifiedReport::DstackAmdSevSnp(verified)
18051857
}

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)