Skip to content
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

Basic quote handlers #157

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ async fn main() -> Result<()> {
web::resource("/quotes/identity")
.route(web::get().to(quotes_handler::identity)),
)
.service(
web::resource("/quotes/integrity")
.route(web::get().to(quotes_handler::integrity)),
)
})
.bind(format!("{}:{}", cloudagent_ip, cloudagent_port))?
.run()
Expand Down
60 changes: 59 additions & 1 deletion src/quotes_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,64 @@ pub struct Ident {
nonce: String,
}

#[derive(Deserialize)]
pub struct Integ {
nonce: String,
mask: String,
vmask: String,
partial: String,
}

pub async fn identity(param: web::Query<Ident>) -> impl Responder {
HttpResponse::Ok().body(format!("Nonce: {}", param.nonce))
// nonce can only be in alphanumerical format
if !param.nonce.chars().all(char::is_alphanumeric) {
HttpResponse::BadRequest()
.body(format!(
"Parameters should be strictly alphanumeric: {}",
param.nonce
))
.await
} else {
// place holder for identity quote code
HttpResponse::Ok()
.body(format!(
"Calling Identity Quote with nonce: {}",
param.nonce
))
.await
}
}

pub async fn integrity(param: web::Query<Integ>) -> impl Responder {
// nonce, mask, vmask can only be in alphanumerical format
if !param.nonce.chars().all(char::is_alphanumeric) {
HttpResponse::BadRequest()
.body(format!(
"nonce should be strictly alphanumeric: {}",
param.nonce
))
.await
} else if !param.mask.chars().all(char::is_alphanumeric) {
HttpResponse::BadRequest()
.body(format!(
"mask should be strictly alphanumeric: {}",
param.mask
))
.await
} else if !param.vmask.chars().all(char::is_alphanumeric) {
HttpResponse::BadRequest()
.body(format!(
"vmask should be strictly alphanumeric: {}",
param.vmask
))
.await
} else {
// place holder for integrity quote code
HttpResponse::Ok()
.body(format!(
"Calling Integrity Quote with nonce: {}",
param.nonce
))
.await
}
}