Skip to content

Commit

Permalink
intel-trust-authority-as: add error message log
Browse files Browse the repository at this point in the history
- Added logging error message for failed appraisal request.
- Fixed typos

Sample log:

`ERROR api_server::http::error] Attestation failed: Attestation request failed: response status=400 Bad Request, message=Invalid nonce and/or run time data provided in the request`

Signed-off-by: Pawel Proskurnicki <[email protected]>
  • Loading branch information
pawelpros committed Jun 20, 2024
1 parent 5c403b2 commit a94ea97
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 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,20 @@ impl Attest for IntelTrustAuthority {
.await
.map_err(|e| anyhow!("Post attestation request failed: {:?}", e))?;

if resp.status() != reqwest::StatusCode::OK {
bail!(
"Attestation request failed: respone status={}",
resp.status()
);
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: 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

0 comments on commit a94ea97

Please sign in to comment.