Skip to content

Commit

Permalink
kbs: simplify tee-pubkey reading from the attestation token
Browse files Browse the repository at this point in the history
Signed-off-by: Mikko Ylinen <[email protected]>
  • Loading branch information
mythi committed Jun 13, 2024
1 parent 25582b0 commit 142965e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
6 changes: 6 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,12 @@ use intel_trust_authority::*;
use kbs_types::{Challenge, Tee};
use rand::{thread_rng, Rng};

// TODO: make it user configurable?
#[cfg(any(feature = "coco-as-builtin", feature = "coco-as-builtin-no-verifier"))]
pub const TOKEN_TEE_PUBKEY_PATH: &str = "/customized_claims/runtime_data/tee-pubkey";
#[cfg(feature = "intel-trust-authority-as")]
pub const TOKEN_TEE_PUBKEY_PATH: &str = "/attester_runtime_data/tee-pubkey";

#[cfg(feature = "coco-as")]
#[allow(missing_docs)]
pub mod coco;
Expand Down
27 changes: 6 additions & 21 deletions kbs/src/api/src/http/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rsa::{BigUint, Pkcs1v15Encrypt, RsaPublicKey};
use serde::Deserialize;
use serde_json::{json, Deserializer, Value};

use crate::attestation;
use crate::raise_error;

use super::*;
Expand Down Expand Up @@ -46,27 +47,11 @@ 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(attestation::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

0 comments on commit 142965e

Please sign in to comment.