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

AA: kbs: Add supported hash algorithms to Request #712

Merged

Conversation

jodh-intel
Copy link
Member

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]

@@ -0,0 +1,10 @@
# Copyright (c) 2024 Intel Corporation
Copy link
Member

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> {
Copy link
Member

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,
    ]
}

Comment on lines 175 to 183
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
};
Copy link
Member

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

Comment on lines 249 to 282
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(),
}
}
Copy link
Member

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.

@jodh-intel jodh-intel force-pushed the aa-advertise-hash-algorithms branch from f61b511 to f38d847 Compare September 9, 2024 18:05
@jodh-intel
Copy link
Member Author

@Xynnn007 - Thanks for reviewing! Branch updated.

/cc @mythi.

@jodh-intel jodh-intel force-pushed the aa-advertise-hash-algorithms branch from f38d847 to a2f4428 Compare September 10, 2024 08:30
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]>
@jodh-intel jodh-intel force-pushed the aa-advertise-hash-algorithms branch 2 times, most recently from 0099976 to 9fe321f Compare September 10, 2024 09:04
// Note the blank string which will be handled as an error when parsed.
let name = selected_hash_algorithm
.as_str()
.unwrap_or("")
Copy link
Contributor

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]>
@jodh-intel jodh-intel force-pushed the aa-advertise-hash-algorithms branch from 9fe321f to 3f50b50 Compare September 10, 2024 13:50
@jodh-intel jodh-intel marked this pull request as ready for review September 10, 2024 13:51
@jodh-intel jodh-intel requested a review from a team as a code owner September 10, 2024 13:51
Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Xynnn007 Xynnn007 left a 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

@fidencio
Copy link
Member

I am doing an E2E test with this PR and the ones on the Trustee side.
Let me finish the tests before merging it.

@fidencio
Copy link
Member

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!

@fidencio fidencio merged commit 1db6c3a into confidential-containers:main Sep 11, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants