Skip to content

Commit

Permalink
AA/kbs_protocol: fix RCAR handshake protocol
Browse files Browse the repository at this point in the history
Before this commit, the tee-pubkey is not fully integrity-protected by
binding the digest into the evidence. The update of this commit is
aligned with the KBS side.

Fixes confidential-containers#366

Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Dec 12, 2023
1 parent dec7f10 commit b2f863f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions attestation-agent/kbs_protocol/src/client/rcar_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use kbs_types::{Attestation, Challenge, ErrorInformation, Request, Response};
use log::{debug, warn};
use resource_uri::ResourceUri;
use serde::Deserialize;
use serde_json::json;
use sha2::{Digest, Sha384};

use crate::{
Expand Down Expand Up @@ -133,8 +134,13 @@ impl KbsClient<Box<dyn EvidenceProvider>> {

debug!("get challenge: {challenge:#?}");
let tee_pubkey = self.tee_key.export_pubkey()?;
let materials = vec![tee_pubkey.k_mod.as_bytes(), tee_pubkey.k_exp.as_bytes()];
let evidence = self.generate_evidence(challenge.nonce, materials).await?;
let runtime_data = json!({
"tee-pubkey": tee_pubkey,
"nonce": challenge.nonce,
});
let runtime_data =
serde_json::to_string(&runtime_data).context("serialize runtime data failed")?;
let evidence = self.generate_evidence(runtime_data).await?;
debug!("get evidence with challenge: {evidence}");

let attest_endpoint = format!("{}/{KBS_PREFIX}/attest", self.kbs_host_url);
Expand Down Expand Up @@ -173,12 +179,9 @@ impl KbsClient<Box<dyn EvidenceProvider>> {
Ok(())
}

async fn generate_evidence(&self, nonce: String, key_materials: Vec<&[u8]>) -> Result<String> {
async fn generate_evidence(&self, runtime_data: String) -> Result<String> {
let mut hasher = Sha384::new();
hasher.update(nonce.as_bytes());
key_materials
.iter()
.for_each(|key_material| hasher.update(key_material));
hasher.update(runtime_data);

let ehd = hasher.finalize().to_vec();

Expand Down

0 comments on commit b2f863f

Please sign in to comment.