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

Use infallible conversion into instead of try_into #747

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

gowthamsk-arm
Copy link
Contributor

A new clippy lint https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_fallible_conversions has been added to rust 1.75.0 that is causing the CI failure. The use of try_into when into is available will be reported by the lint now.

Signed-off-by: Gowtham Suresh Kumar [email protected]

A new clippy lint https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_fallible_conversions
has been added to rust 1.75.0 that is causing the CI failure.
The use of try_into when into is available will be reported by
the lint now.

Signed-off-by: Gowtham Suresh Kumar <[email protected]>
@gowthamsk-arm
Copy link
Contributor Author


impl Context {
pub fn asym_encrypt(
&self,
key_id: u32,
alg: AsymmetricEncryption,
mut plaintext: Vec<u8>,
Copy link
Collaborator

@minosgalanakis minosgalanakis Jan 4, 2024

Choose a reason for hiding this comment

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

I am assuming zeroisation is no longer required and we trust the vector data to be the responsibility of the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

zeroisation was only happening when we would get an error from try_into(). With into() there is no error scenario so we would never zeroise. So it would be the caller's responsibility to clear as it is with the positive case.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, what I find interesting is that we didn't zeroize it after sending the request, even though we don't pass ownership of the plaintext data, just a reference to it. Maybe we should do it before returning, regardless of whether it's an exception or not. Or maybe we didn't do it for some reason and I forgot the reason 🤔

Would it be possible for you to quickly check if zeroizing at the end breaks anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought all the structs from ts_protobuf have Drop trail implemented here. But I can only see Drop being implemented for ImportKeyIn, ExportKeyOut, SignHashIn, VerifyHashIn. For these structs the drop method takes care of the zeroise part.

Not sure why AsymmetricEncryptIn and AsymmetricDecryptIn don't have them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test patch seems to work fine and there are no failures reported in the CI jobs for trusted services backend.

Choose a reason for hiding this comment

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

I would be more inclined for the Drop method of the involved types to handle the zeroization. Could you check if this is possible and easy to do? I'm approving in case it's not possible/easy.

Copy link
Collaborator

@minosgalanakis minosgalanakis 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

@tgonzalezorlandoarm tgonzalezorlandoarm left a comment

Choose a reason for hiding this comment

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

One check to do, but LGTM other than that


impl Context {
pub fn asym_encrypt(
&self,
key_id: u32,
alg: AsymmetricEncryption,
mut plaintext: Vec<u8>,

Choose a reason for hiding this comment

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

I would be more inclined for the Drop method of the involved types to handle the zeroization. Could you check if this is possible and easy to do? I'm approving in case it's not possible/easy.

@gowthamsk-arm
Copy link
Contributor Author

CI run failure for the Cargo deny job is expected and @tgonzalezorlandoarm has a fix for it.

…etricDecryptIn

The drop functions zeroise the ciphertext, plaintext and salt information
to avoid leakage of any confifdential information.

Signed-off-by: Gowtham Suresh Kumar <[email protected]>
Copy link
Member

@tgonzalezorlandoarm tgonzalezorlandoarm 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

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

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

👍🏻

@gowthamsk-arm gowthamsk-arm merged commit 80da25f into parallaxsecond:main Feb 5, 2024
15 of 16 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.

4 participants