Secret value type
A secure and serializable type for any kind of secret:
- Zeroizes its bytes in memory when dropped, using zeroize;
- Prints
***inDebugandDisplay, so it does not leak into logs and panic messages; - Stores bytes, so it fits binary secrets too;
- Lends copies to closures with the
exposed_in_*methods and zeroizes them afterwards; - Parses JSON embedded in a secret with
expose_json_value_as; - Encodes and decodes hex and base64.
Working with the type
use SecretValue;
let secret_value: SecretValue = "my-password".into;
assert_eq!;
// Borrowing, no copies
let password: &str = secret_value.as_sensitive_str;
let bytes: & = secret_value.as_sensitive_bytes;
// The copy passed to the closure is zeroized when the closure is done
let length = secret_value.exposed_in_as_zstr;
// Async closures work the same way
async
Full example with hex, base64, JSON, BytesMut and protobuf available here:
Quick start
Cargo.toml:
[]
= { = "1.0", = ["..."] }
See security consideration below about versioning.
Available optional features for secret value type:
serdefor serde serialization support, it also bringsserde_jsonforexpose_json_value_as;protofor protobuf serialization support;bytesforBytesMutconversion support;hexfor hex conversion support;base64for base64 conversion support.
Security considerations and risks
OSS
Open source code is created through voluntary collaboration of software developers. The original authors license the code so that anyone can see it, modify it, and distribute new versions of it. You should manage all OSS using the same procedures and tools that you use for commercial products. As always, train your employees on cyber security best practices that can help them securely use and manage software products. You should not solely rely on individuals, especially on the projects like this reading sensitive information.
Versioning
Please don't use broad version dependency management not to include a new version of dependency automatically without your auditing the changes.
Zeroing, protecting memory and encryption don't provide 100% safety
There are still allocations on the protocol layers, there is a session secret key available in memory, privileged users on OS still have broad access, etc. So don't consider this is a completely safe solution for all possible attacks. Mitigation some of the attacks is not possible without implementing additional support on hardware/OS level (such as Intel SGX project, for instance).
Licence
Apache Software License (ASL)
Author
Abdulla Abdurakhmanov