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

kbs: simplify tee-pubkey reading from the attestation token #414

Merged
merged 2 commits into from
Jun 19, 2024
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
5 changes: 5 additions & 0 deletions kbs/src/api/src/attestation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ use intel_trust_authority::*;
use kbs_types::{Challenge, Tee};
use rand::{thread_rng, Rng};

#[cfg(not(feature = "intel-trust-authority-as"))]
pub const AS_TOKEN_TEE_PUBKEY_PATH: &str = "/customized_claims/runtime_data/tee-pubkey";
#[cfg(feature = "intel-trust-authority-as")]
pub const AS_TOKEN_TEE_PUBKEY_PATH: &str = "/attester_runtime_data/tee-pubkey";

#[cfg(feature = "coco-as")]
#[allow(missing_docs)]
pub mod coco;
Expand Down
2 changes: 1 addition & 1 deletion kbs/src/api/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#[cfg(feature = "as")]
use crate::attestation::AttestationService;
use crate::attestation::{AttestationService, AS_TOKEN_TEE_PUBKEY_PATH};
use crate::auth::validate_auth;
#[cfg(feature = "policy")]
use crate::policy_engine::PolicyEngine;
Expand Down
32 changes: 11 additions & 21 deletions kbs/src/api/src/http/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use crate::raise_error;

use super::*;

#[cfg(feature = "as")]
const TOKEN_TEE_PUBKEY_PATH: &str = AS_TOKEN_TEE_PUBKEY_PATH;
#[cfg(not(feature = "as"))]
const TOKEN_TEE_PUBKEY_PATH: &str = "/customized_claims/runtime_data/tee-pubkey";
Comment on lines +22 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two places defining TOKEN_TEE_PUBKEY_PATH, like before. Is it possible to define only on one place and use a reference on the other side?

Copy link
Contributor Author

@mythi mythi Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted it to be like that but I found the problem that TOKEN_TEE_PUBKEY_PATH needs to be defined even completely without attestation (i.e., as not enabled) so some "default" must be kept here.


#[allow(unused_assignments)]
/// GET /resource/{repository}/{type}/{tag}
/// GET /resource/{type}/{tag}
Expand Down Expand Up @@ -46,27 +51,12 @@ pub(crate) async fn get_resource(
Error::AttestationClaimsParseFailed(format!("illegal attestation claims: {e}"))
})?;

let pkey_value = claims
.get("customized_claims")
.ok_or(Error::AttestationClaimsParseFailed(String::from(
"No `customized_claims` in the attestation claims thus no `tee-pubkey`",
)))?
.as_object()
.ok_or(Error::AttestationClaimsParseFailed(String::from(
"`customized_claims` should be a JSON map",
)))?
.get("runtime_data")
.ok_or(Error::AttestationClaimsParseFailed(String::from(
"No `runtime_data` in the attestation claims thus no `tee-pubkey`",
)))?
.as_object()
.ok_or(Error::AttestationClaimsParseFailed(String::from(
"`runtime_data` should be a JSON map",
)))?
.get("tee-pubkey")
.ok_or(Error::AttestationClaimsParseFailed(String::from(
"No `tee-pubkey` in the attestation claims",
)))?;
let pkey_value =
claims
.pointer(TOKEN_TEE_PUBKEY_PATH)
.ok_or(Error::AttestationClaimsParseFailed(String::from(
"Failed to find `tee-pubkey` in the attestation claims",
)))?;
let pubkey = TeePubKey::deserialize(pkey_value).map_err(|e| {
Error::AttestationClaimsParseFailed(format!("illegal attestation claims: {e}"))
})?;
Expand Down
Loading