-
Notifications
You must be signed in to change notification settings - Fork 99
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
AA: kbs: Add supported hash algorithms to Request #712
AA: kbs: Add supported hash algorithms to Request #712
Conversation
@@ -0,0 +1,10 @@ | |||
# Copyright (c) 2024 Intel Corporation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about move this module under deps/crypto
?
} | ||
|
||
/// Return a list of all supported hash algorithms. | ||
pub fn get() -> Vec<HashAlgorithm> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving this function under impl HashAlgorithm
and change a name? s.t.
pub fn list_all()-> Vec<Self> {
vec![
HashAlgorithm::Sha256,
HashAlgorithm::Sha384,
HashAlgorithm::Sha512,
]
}
let algorithm = if let Some(selected_hash_algorithm) = | ||
extra_params.get(SELECTED_HASH_ALGORITHM_JSON_KEY) | ||
{ | ||
// Note the blank string which will be handled as an error when parsed. | ||
let name = selected_hash_algorithm | ||
.as_str() | ||
.unwrap_or("") | ||
.to_lowercase(); | ||
|
||
name.parse::<HashAlgorithm>() | ||
.map_err(|_| Error::InvalidHashAlgorithm(name))? | ||
} else { | ||
DEFAULT_HASH_ALGORITHM | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using match
instead of let if
? That would look simpler
let hashed_data = match algorithm { | ||
HashAlgorithm::Sha256 => { | ||
let mut hasher = Sha256::new(); | ||
|
||
hasher.update(runtime_data); | ||
|
||
match tee { | ||
// IBM SE uses nonce as runtime_data to pass attestation_request | ||
Tee::Se => nonce.into_bytes(), | ||
_ => hasher.finalize().to_vec(), | ||
} | ||
} | ||
HashAlgorithm::Sha384 => { | ||
let mut hasher = Sha384::new(); | ||
|
||
hasher.update(runtime_data); | ||
|
||
match tee { | ||
// IBM SE uses nonce as runtime_data to pass attestation_request | ||
Tee::Se => nonce.into_bytes(), | ||
_ => hasher.finalize().to_vec(), | ||
} | ||
} | ||
HashAlgorithm::Sha512 => { | ||
let mut hasher = Sha512::new(); | ||
|
||
hasher.update(runtime_data); | ||
|
||
match tee { | ||
// IBM SE uses nonce as runtime_data to pass attestation_request | ||
Tee::Se => nonce.into_bytes(), | ||
_ => hasher.finalize().to_vec(), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have HashAlgorithm::digest()
function that could help to avoid the match arms here.
f61b511
to
f38d847
Compare
f38d847
to
a2f4428
Compare
Split the algorithms code out of the AA eventlog and move it to the local `crypto` crate. Doing this allows other crates to consume the code rather than duplicating the logic. Signed-off-by: James O. D. Hunt <[email protected]>
Split the `rcar_handshake()` method so that the request is now built by a the new `build_request()` function. Signed-off-by: James O. D. Hunt <[email protected]>
0099976
to
9fe321f
Compare
// Note the blank string which will be handled as an error when parsed. | ||
let name = selected_hash_algorithm | ||
.as_str() | ||
.unwrap_or("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i'd use .ok_or(Error::NotAString(selected_hash_algorithm))?
or something, otherwise we might swallow a malformed extra_params body
Add a `supported-hash-algorithms` list to the `Request` to allow the returned `Challenge` to select an appropriate TEE-specific algorithm from the list. Signed-off-by: James O. D. Hunt <[email protected]>
9fe321f
to
3f50b50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks LgTm @jodh-intel
I am doing an E2E test with this PR and the ones on the Trustee side. |
I was able to validate this in an E2E workflow, also testing the patches from trustee and also with changes to come on Kata Containers. Merging this now, thanks @jodh-intel for the work, and thanks all the reviewers for reviews! |
Add a
supported-hash-algorithms
list to theRequest
to allow thereturned
Challenge
to select an appropriate TEE-specific algorithmfrom the list.
Signed-off-by: James O. D. Hunt [email protected]