Skip to content

Commit

Permalink
AA: add GetTeeType API
Browse files Browse the repository at this point in the history
This new API is used for a caller to get current platform name.

Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Jul 18, 2024
1 parent 4619b4b commit dc48014
Show file tree
Hide file tree
Showing 10 changed files with 610 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions attestation-agent/attestation-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config.workspace = true
const_format.workspace = true
env_logger = { workspace = true, optional = true }
kbs_protocol = { path = "../kbs_protocol", default-features = false, optional = true }
kbs-types.workspace = true
log.workspace = true
prost = { workspace = true, optional = true }
protobuf = { workspace = true, optional = true }
Expand Down
30 changes: 28 additions & 2 deletions attestation-agent/attestation-agent/src/bin/grpc-aa/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use attestation::attestation_agent_service_server::{
};
use attestation::{
CheckInitDataRequest, CheckInitDataResponse, ExtendRuntimeMeasurementRequest,
ExtendRuntimeMeasurementResponse, GetEvidenceRequest, GetEvidenceResponse, GetTokenRequest,
GetTokenResponse, UpdateConfigurationRequest, UpdateConfigurationResponse,
ExtendRuntimeMeasurementResponse, GetEvidenceRequest, GetEvidenceResponse, GetTeeTypeRequest,
GetTeeTypeResponse, GetTokenRequest, GetTokenResponse, UpdateConfigurationRequest,
UpdateConfigurationResponse,
};
use attestation_agent::{AttestationAPIs, AttestationAgent};
use log::{debug, error};
Expand Down Expand Up @@ -162,6 +163,31 @@ impl AttestationAgentService for AA {

Result::Ok(Response::new(reply))
}

async fn get_tee_type(
&self,
_request: Request<GetTeeTypeRequest>,
) -> Result<Response<GetTeeTypeResponse>, Status> {
let mut attestation_agent = self.inner.lock().await;

debug!("AA (grpc): get tee type ...");

let tee = attestation_agent.get_tee_type();

let tee = serde_json::to_string(&tee)
.map_err(|e| {
error!("AA (ttrpc): get tee type failed:\n {e:?}");
Status::internal(format!("[ERROR:{AGENT_NAME}] AA get tee type failed"))
})?
.trim_end_matches('"')
.trim_start_matches('"')
.to_string();
debug!("AA (ttrpc): get tee type succeeded.");

let reply = GetTeeTypeResponse { tee };

Result::Ok(Response::new(reply))
}
}

pub async fn start_grpc_service(socket: SocketAddr, aa: AttestationAgent) -> Result<()> {
Expand Down
33 changes: 31 additions & 2 deletions attestation-agent/attestation-agent/src/bin/ttrpc-aa/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::sync::Arc;

use crate::ttrpc_protocol::attestation_agent::{
ExtendRuntimeMeasurementRequest, ExtendRuntimeMeasurementResponse, GetEvidenceRequest,
GetEvidenceResponse, GetTokenRequest, GetTokenResponse, UpdateConfigurationRequest,
UpdateConfigurationResponse,
GetEvidenceResponse, GetTeeTypeRequest, GetTeeTypeResponse, GetTokenRequest, GetTokenResponse,
UpdateConfigurationRequest, UpdateConfigurationResponse,
};
use crate::ttrpc_protocol::attestation_agent_ttrpc::{
create_attestation_agent_service, AttestationAgentService,
Expand Down Expand Up @@ -145,6 +145,35 @@ impl AttestationAgentService for AA {
let reply = UpdateConfigurationResponse::new();
::ttrpc::Result::Ok(reply)
}

async fn get_tee_type(
&self,
_ctx: &::ttrpc::r#async::TtrpcContext,
_req: GetTeeTypeRequest,
) -> ::ttrpc::Result<GetTeeTypeResponse> {
debug!("AA (ttrpc): get tee type ...");

let mut attestation_agent = self.inner.lock().await;

let tee = attestation_agent.get_tee_type();

let res = serde_json::to_string(&tee)
.map_err(|e| {
error!("AA (ttrpc): get tee type failed:\n {e:?}");
let mut error_status = ::ttrpc::proto::Status::new();
error_status.set_code(Code::INTERNAL);
error_status
.set_message(format!("[ERROR:{AGENT_NAME}] AA-KBC get tee type failed"));
::ttrpc::Error::RpcStatus(error_status)
})?
.trim_end_matches('"')
.trim_start_matches('"')
.to_string();
debug!("AA (ttrpc): get tee type succeeded.");
let mut reply = GetTeeTypeResponse::new();
reply.tee = res;
::ttrpc::Result::Ok(reply)
}
}

pub fn start_ttrpc_service(aa: AttestationAgent) -> Result<HashMap<String, Service>> {
Expand Down
Loading

0 comments on commit dc48014

Please sign in to comment.