Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "kbs-types"
description = "Rust (de)serializable types for KBS"
version = "0.16.0"
version = "0.17.0"
authors = ["Sergio Lopez <slp@redhat.com>"]
edition = "2021"
repository = "https://github.com/virtee/kbs-types"
Expand Down
68 changes: 68 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ pub enum TeePubKey {
x: String,
y: String,
},
/// Algorithm Key Pair (AKP) key type for PQC algorithm support as per
/// [draft-ietf-jose-pqc-kem-05](https://datatracker.ietf.org/doc/draft-ietf-jose-pqc-kem/)
AKP {
alg: String,
#[serde(rename = "pub")]
public_key: String,
},
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -152,6 +159,20 @@ impl From<&TeePubKey> for ear::RawValue {
RawValue::String(y.clone()),
));
}
TeePubKey::AKP { alg, public_key } => {
map.push((
RawValue::String("kty".to_string()),
RawValue::String("AKP".to_string()),
));
map.push((
RawValue::String("alg".to_string()),
RawValue::String(alg.clone()),
));
map.push((
RawValue::String("pub".to_string()),
RawValue::String(public_key.clone()),
));
}
}

RawValue::Map(map)
Expand Down Expand Up @@ -618,6 +639,44 @@ mod tests {
);
}

#[test]
fn parse_attestation_akp() {
let data = r#"
{
"runtime-data": {
"nonce": "test_nonce",
"tee-pubkey": {
"kty": "AKP",
"alg": "fakealgorithm",
"pub": "fakepublickey"
}
},
"tee-evidence": {
"primary_evidence": "test_primary_evidence",
"additional_evidence": "test_additional_evidence"
}
}"#;

let attestation: Attestation = serde_json::from_str(data).unwrap();
let tee_pubkey = attestation.runtime_data.tee_pubkey;

let TeePubKey::AKP { alg, public_key } = tee_pubkey else {
panic!("Must be a AKP key");
};

assert_eq!(attestation.runtime_data.nonce, "test_nonce");
assert_eq!(alg, "fakealgorithm");
assert_eq!(public_key, "fakepublickey");
assert_eq!(
attestation.tee_evidence.primary_evidence,
"test_primary_evidence"
);
assert_eq!(
attestation.tee_evidence.additional_evidence,
"test_additional_evidence"
);
}

#[test]
fn parse_error_information() {
let data = r#"
Expand Down Expand Up @@ -655,6 +714,15 @@ mod tests {
let ear_raw: RawValue = (&tpk).into();
let json_str = serde_json::to_string(&ear_raw).unwrap();
assert_eq!(json_str, serde_json::to_string(&tpk).unwrap());

// AKP key.
let tpk = TeePubKey::AKP {
alg: "test".to_string(),
public_key: "test".to_string(),
};
let ear_raw: RawValue = (&tpk).into();
let json_str = serde_json::to_string(&ear_raw).unwrap();
assert_eq!(json_str, serde_json::to_string(&tpk).unwrap());
}

#[test]
Expand Down