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

intel-trust-authority-as: add error message log #424

Merged
Merged
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
19 changes: 15 additions & 4 deletions kbs/src/api/src/attestation/intel_trust_authority/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ struct Claims {
policy_ids_unmatched: Option<Vec<serde_json::Value>>,
}

#[derive(Deserialize, Debug)]
struct ErrorResponse {
error: String,
}

#[derive(Clone, Debug, Deserialize)]
pub struct IntelTrustAuthorityConfig {
pub base_url: String,
Expand Down Expand Up @@ -82,18 +87,24 @@ impl Attest for IntelTrustAuthority {
.await
.map_err(|e| anyhow!("Post attestation request failed: {:?}", e))?;

if resp.status() != reqwest::StatusCode::OK {
let status = resp.status();
if status != reqwest::StatusCode::OK {
let body = resp
.json::<ErrorResponse>()
.await
.map_err(|e| anyhow!("Deserialize error response failed: {:?}", e))?;
bail!(
"Attestation request failed: respone status={}",
resp.status()
"Attestation request failed: response status={}, message={}",
status,
body.error
);
}

// get token kid
let resp_data = resp
.json::<AttestRespData>()
.await
.map_err(|e| anyhow!("Deserialize attestation respone failed: {:?}", e))?;
.map_err(|e| anyhow!("Deserialize attestation response failed: {:?}", e))?;
let header = decode_header(&resp_data.token)
.map_err(|e| anyhow!("Decode token header failed: {:?}", e))?;
let kid = header.kid.ok_or(anyhow!("Token missing kid"))?;
Expand Down
Loading