Skip to content

Commit

Permalink
KBS: return more context about RCAR/Attestation error
Browse files Browse the repository at this point in the history
Before this commit, if the rcar auth fails, the client would only get
error information "Attestation error". This commit expose more error
information to the client side. A typical error would say
"Attestation error: RCAR handshake Auth failed: KBS Client Protocol
Version Mismatch: ..."

This would do much help to debugging and error locating.

Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Nov 26, 2024
1 parent 29cac9d commit cfbf15a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions kbs/src/attestation/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl AttestationService {
let version = Version::parse(&request.version).context("failed to parse KBS version")?;
if !VERSION_REQ.matches(&version) {
bail!(
"expected version: {}, requested version: {}",
"KBS Client Protocol Version Mismatch: expect {} while the request is {}",
*VERSION_REQ,
request.version
);
Expand All @@ -191,9 +191,9 @@ impl AttestationService {
.inner
.generate_challenge(request.tee, request.extra_params.clone())
.await
.context("generate challenge")?;
.context("Attestation Service generate challenge failed")?;

let session = SessionStatus::auth(request, self.timeout, challenge).context("Session")?;
let session = SessionStatus::auth(request, self.timeout, challenge);

let response = HttpResponse::Ok()
.cookie(session.cookie())
Expand Down
2 changes: 1 addition & 1 deletion kbs/src/attestation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum Error {
source: anyhow::Error,
},

#[error("RCAR handshake Auth failed")]
#[error("RCAR handshake Auth failed: {source}")]
RcarAuthFailed {
#[source]
source: anyhow::Error,
Expand Down
7 changes: 3 additions & 4 deletions kbs/src/attestation/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use actix_web::cookie::{
time::{Duration, OffsetDateTime},
Cookie,
};
use anyhow::Result;
use kbs_types::{Challenge, Request};
use log::warn;
use uuid::Uuid;
Expand Down Expand Up @@ -49,17 +48,17 @@ macro_rules! impl_member {
}

impl SessionStatus {
pub fn auth(request: Request, timeout: i64, challenge: Challenge) -> Result<Self> {
pub fn auth(request: Request, timeout: i64, challenge: Challenge) -> Self {
let id = Uuid::new_v4().as_simple().to_string();

let timeout = OffsetDateTime::now_utc() + Duration::minutes(timeout);

Ok(Self::Authed {
Self::Authed {
request,
challenge,
id,
timeout,
})
}
}

pub fn cookie<'a>(&self) -> Cookie<'a> {
Expand Down
4 changes: 2 additions & 2 deletions kbs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub type Result<T> = std::result::Result<T, Error>;

#[derive(Error, AsRefStr, Debug)]
pub enum Error {
#[error("Admin auth error")]
#[error("Admin auth error: {0}")]
AdminAuth(#[from] crate::admin::Error),

#[cfg(feature = "as")]
#[error("Attestation error")]
#[error("Attestation error: {0}")]
AttestationError(#[from] crate::attestation::Error),

#[error("HTTP initialization failed")]
Expand Down

0 comments on commit cfbf15a

Please sign in to comment.