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

zeroize: implement Zeroize for CString #509

Closed
robinkrahl opened this issue Sep 22, 2020 · 6 comments
Closed

zeroize: implement Zeroize for CString #509

robinkrahl opened this issue Sep 22, 2020 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed zeroize Issues affecting the 'zeroize' crate

Comments

@robinkrahl
Copy link
Contributor

I have to store a password that will be passed to a C API using the Rust FFI. To avoid unnecessary copies, I store it as a std::ffi::CString. But as Zeroize is not implemented for CString, I can’t wrap this field in a Secret.

Could you please add a Zeroize implementation for CString?

@tony-iqlusion
Copy link
Member

I think this would be a good addition, yes.

@tony-iqlusion tony-iqlusion added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed zeroize Issues affecting the 'zeroize' crate labels Sep 30, 2020
@tony-iqlusion tony-iqlusion changed the title Implement Zeroize for CString zeroize: implement Zeroize for CString Sep 30, 2020
@cyberia-ng
Copy link
Contributor

Since CString is only in std (and not in alloc), I think this would have to be gated behind another crate feature?

@tony-iqlusion
Copy link
Member

Yep, it would require a new std feature, which would need to be off-by-default.

@cyberia-ng
Copy link
Contributor

Taking a look at this today, I think it might not be possible.

Rust's CString type "is a static guarantee that the underlying bytes contain no interior 0 bytes ("nul characters") and that the final byte is 0 ("nul terminator")" (docs). Therefore overwriting interior bytes with 0s is explicitly breaking this guarantee.

This might not prevent doing some kind of SecretCString type over in secrecy though, with a Drop implementation that does the zeroing immediately before free.

@cyberia-ng
Copy link
Contributor

We could do something slightly wacky and overwrite internal bytes with 0xFF or something, so as to obliterate the data while preserving the "no internal NUL bytes" guarantee.

@tony-iqlusion
Copy link
Member

Moved to RustCrypto/utils#650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed zeroize Issues affecting the 'zeroize' crate
Projects
None yet
Development

No branches or pull requests

3 participants