-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AA/kbs_protocol: add AAEvidenceProvider
AAEvidenceProvider gets evidence via ttrpc from AA. This patch also does some refactoring upon the code structure of ttrpc to avoid duplication of ttrpc files. Signed-off-by: Xynnn007 <[email protected]>
- Loading branch information
Showing
9 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
attestation-agent/kbs_protocol/src/evidence_provider/aa_ttrpc.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2025 Alibaba Cloud | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
use async_trait::async_trait; | ||
use kbs_types::Tee; | ||
use serde_json::json; | ||
use ttrpc::context; | ||
|
||
use crate::{ | ||
ttrpc_protos::{ | ||
attestation_agent::{GetEvidenceRequest, GetTeeTypeRequest}, | ||
attestation_agent_ttrpc::AttestationAgentServiceClient, | ||
}, | ||
Error, Result, | ||
}; | ||
|
||
use super::EvidenceProvider; | ||
|
||
const AA_SOCKET_FILE: &str = | ||
"unix:///run/confidential-containers/attestation-agent/attestation-agent.sock"; | ||
|
||
/// The timeout for ttrpc call to Attestation Agent | ||
const AA_TTRPC_TIMEOUT_SECONDS: i64 = 50; | ||
|
||
pub struct AAEvidenceProvider { | ||
client: AttestationAgentServiceClient, | ||
} | ||
|
||
impl AAEvidenceProvider { | ||
pub async fn new() -> Result<Self> { | ||
let c = ttrpc::r#async::Client::connect(AA_SOCKET_FILE) | ||
.map_err(|e| Error::AATokenProvider(format!("ttrpc connect failed {e}")))?; | ||
let client = AttestationAgentServiceClient::new(c); | ||
Ok(Self { client }) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl EvidenceProvider for AAEvidenceProvider { | ||
/// Get evidence with as runtime data (report data, challege) | ||
async fn get_evidence(&self, runtime_data: Vec<u8>) -> Result<String> { | ||
let req = GetEvidenceRequest { | ||
RuntimeData: runtime_data, | ||
..Default::default() | ||
}; | ||
let res = self | ||
.client | ||
.get_evidence( | ||
context::with_timeout(AA_TTRPC_TIMEOUT_SECONDS * 1000 * 1000 * 1000), | ||
&req, | ||
) | ||
.await | ||
.map_err(|e| Error::AAEvidenceProvider(format!("call ttrpc failed: {e}")))?; | ||
let evidence = String::from_utf8(res.Evidence) | ||
.map_err(|e| Error::AAEvidenceProvider(format!("non-utf8 evidence: {e}")))?; | ||
Ok(evidence) | ||
} | ||
|
||
/// Get the underlying Tee type | ||
async fn get_tee_type(&self) -> Result<Tee> { | ||
let req = GetTeeTypeRequest { | ||
..Default::default() | ||
}; | ||
let res = self | ||
.client | ||
.get_tee_type( | ||
context::with_timeout(AA_TTRPC_TIMEOUT_SECONDS * 1000 * 1000 * 1000), | ||
&req, | ||
) | ||
.await | ||
.map_err(|e| Error::AAEvidenceProvider(format!("call ttrpc failed: {e}")))?; | ||
|
||
let tee = serde_json::from_value(json!(res.tee)) | ||
.map_err(|e| Error::AAEvidenceProvider(format!("failed to parse Tee type: {e}")))?; | ||
Ok(tee) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (c) 2025 Alibaba Cloud | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
pub mod attestation_agent; | ||
pub mod attestation_agent_ttrpc; |