-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api-server-rest: Add extend_runtime_measurement API #635
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
// | ||
|
||
use crate::router::ApiHandler; | ||
use crate::ttrpc_proto::attestation_agent::{GetEvidenceRequest, GetTokenRequest}; | ||
use crate::ttrpc_proto::attestation_agent::{ | ||
ExtendRuntimeMeasurementRequest, GetEvidenceRequest, GetTokenRequest, | ||
}; | ||
use crate::ttrpc_proto::attestation_agent_ttrpc::AttestationAgentServiceClient; | ||
use anyhow::*; | ||
use async_trait::async_trait; | ||
|
@@ -20,6 +22,7 @@ pub const AA_ROOT: &str = "/aa"; | |
/// URL for querying CDH get resource API | ||
const AA_TOKEN_URL: &str = "/token"; | ||
const AA_EVIDENCE_URL: &str = "/evidence"; | ||
const AA_MEASUREMENT_URL: &str = "/extend_runtime_measurement"; | ||
|
||
pub struct AAClient { | ||
client: AttestationAgentServiceClient, | ||
|
@@ -50,17 +53,13 @@ impl ApiHandler for AAClient { | |
.map(|v| form_urlencoded::parse(v.as_bytes()).into_owned().collect()) | ||
.unwrap_or_default(); | ||
|
||
if params.len() != 1 { | ||
return self.not_allowed(); | ||
} | ||
|
||
match url_path { | ||
AA_TOKEN_URL => match params.get("token_type") { | ||
Some(token_type) => match self.get_token(token_type).await { | ||
std::result::Result::Ok(results) => return self.octet_stream_response(results), | ||
Err(e) => return self.internal_error(e.to_string()), | ||
}, | ||
None => return self.bad_request(), | ||
None => return self.internal_error("invalid param: token_type None!".to_string()), | ||
}, | ||
AA_EVIDENCE_URL => match params.get("runtime_data") { | ||
Some(runtime_data) => { | ||
|
@@ -71,8 +70,38 @@ impl ApiHandler for AAClient { | |
Err(e) => return self.internal_error(e.to_string()), | ||
} | ||
} | ||
None => return self.bad_request(), | ||
None => { | ||
return self.internal_error("invalid param: runtime_data None!".to_string()) | ||
} | ||
}, | ||
AA_MEASUREMENT_URL => { | ||
let domain = params.get("domain"); | ||
let operation = params.get("operation"); | ||
let content = params.get("content"); | ||
match (domain, operation, content) { | ||
(Some(domain), Some(operation), Some(content)) => { | ||
let register_index: Option<u64> = params | ||
.get("register_index") | ||
.and_then(|value| value.parse::<u64>().ok()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, return error is make sense for me, I'll update this part. |
||
|
||
match self | ||
.extend_runtime_measurement(domain, operation, content, register_index) | ||
.await | ||
{ | ||
std::result::Result::Ok(results) => { | ||
return self.octet_stream_response(results) | ||
} | ||
Err(e) => return self.internal_error(e.to_string()), | ||
} | ||
} | ||
_ => { | ||
return self.internal_error(format!( | ||
"invalid params: domain {:?}, operation {:?}, content {:?}!", | ||
domain, operation, content | ||
)) | ||
} | ||
} | ||
} | ||
|
||
_ => { | ||
return self.not_found(); | ||
|
@@ -116,4 +145,24 @@ impl AAClient { | |
.await?; | ||
Ok(res.Evidence) | ||
} | ||
|
||
pub async fn extend_runtime_measurement( | ||
&self, | ||
domain: &str, | ||
operation: &str, | ||
content: &str, | ||
register_index: Option<u64>, | ||
) -> Result<Vec<u8>> { | ||
let req = ExtendRuntimeMeasurementRequest { | ||
Domain: domain.to_string(), | ||
Operation: operation.to_string(), | ||
Content: content.to_string(), | ||
RegisterIndex: register_index, | ||
..Default::default() | ||
}; | ||
self.client | ||
.extend_runtime_measurement(ttrpc::context::with_timeout(TTRPC_TIMEOUT), &req) | ||
.await?; | ||
Ok("runtime measurement extend success".into()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's update the example when the spec is finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we'll update this part to follow the spec.