Open cecton opened 4 years ago
@cecton being able to read from a file directly into a SecretString
would definitely be interesting!
@cecton did you ever implement the reading in a secret from a file?
@c-git sorry I totally forgot about this ticket, Feel free to go ahead with the implementation if you would likd
Ok thanks. If I do I'll submit it but I'm not quite sure how to securely accomplish that task.
tbh I'm not sure either, My colleagues back in the days mentioned something special to do but I forgot what exactly... @tomaka maybe you can help with some advice here? (I think it was you)
I would be happy to provide a PR that convert an
impl Read
to aSecretString
that would zeroes things between reads if you think that is a good implementation.
oh wait, probably that was a not so innocent suggestion, I think the idea was to copy the code of fs::read_to_string from std and do something special like zeroing the buffer before the exit.
Thanks that looks like something I might be able to follow up on.
Disclaimer I'm new to Rust (but not programing). So if someone can look over what I did that would be great. (I used PyCharm to follow the code from one point to the next in the standard library and it looks like it was navigating correctly to me. Was able to match it in the online github repo)
That said I think no separate buffers are used other than the one created to store the string in the first call. And this owned string is moved into the Secret wrapper. There was one point in the code here where it looked like another buffer was allocated.
However when I checked what a ReadBuf
was it turns out it's just a pointer to part of an already existing buffer (the one created earlier). That is based on the comments that I found here.
I did see two ways that part of the file could be loaded into memory and then not cleared. I'm not sure of the viability of either approach but from reading the comments and following the code logic I was lead to believe that it might be possible.
I was wondering if this code could potentially leave a copy of a secret in memory:
Because the underlying implementation of
read_to_string
might re-allocate theString
and not zeroes the partially-read secret.Do you have any suggestion?
I would be happy to provide a PR that convert an
impl Read
to aSecretString
that would zeroes things between reads if you think that is a good implementation.