Crates.io | safebox |
lib.rs | safebox |
version | 0.1.0 |
source | src |
created_at | 2019-11-09 08:02:57.75638 |
updated_at | 2019-11-09 08:02:57.75638 |
description | Lower the risk of leaving secret around in memory |
homepage | |
repository | https://github.com/bombela/safebox |
max_upload_size | |
id | 179672 |
size | 13,745 |
Via intrinsics, and guarding behind unsafe, the SafeBox helps you reduce the chances of leaking some secret around in memory.
get_ref
and get_mut
. Both
methods are marked unsafe
. The idea is to prevent implicit copies. And
hopefully get the programmer to be more careful on the sight of unsafe.DO NOT USE IN PRODUCTION UNLESS YOU LIKE TO TRUST A RANDOM STRANGER ON THE INTERNET
use safebox::SafeBox;
use rand::prelude::*;
let a = SafeBox::new_slice_with(8, &random::<u8>);
unsafe {
println!("My secret: {:?}", secret.get_ref());
}
Prints (non-deterministic):
My secret: [242, 144, 235, 196, 84, 35, 85, 232]
To zero a piece RAM requires a bit more than calling memset(0). There is few layers of optimizations and abstractions working against us:
With the above taken care of, we must also enforce that the content cannot be copied in RAM inadvertently:
And finally, the Operating System can be involved:
This crate solves 1) to 4) with volatile write and atomic fence.
The Operating System side is ignored. 7) and 8) could be addressed via mlock and mprotect syscalls. And as for 9), you should use an encrypted storage anyway.