#secret #secure #security #values #data-structures #encryption #memory

secret-vault-value

Library provides a simple implementation of a secure and serializable type to store and control secret/sensitive values

16 releases

0.3.9 Jul 12, 2024
0.3.8 Oct 1, 2023
0.3.7 Jan 27, 2023
0.3.6 Sep 18, 2022
0.1.1 Jul 21, 2022

#222 in Cryptography

Download history 6924/week @ 2024-07-23 7398/week @ 2024-07-30 6991/week @ 2024-08-06 8024/week @ 2024-08-13 8701/week @ 2024-08-20 8403/week @ 2024-08-27 11248/week @ 2024-09-03 9297/week @ 2024-09-10 9330/week @ 2024-09-17 10001/week @ 2024-09-24 11773/week @ 2024-10-01 10435/week @ 2024-10-08 11799/week @ 2024-10-15 10526/week @ 2024-10-22 9539/week @ 2024-10-29 9606/week @ 2024-11-05

43,105 downloads per month
Used in 20 crates (4 directly)

Apache-2.0

29KB
556 lines

Cargo tests and formatting security audit unsafe license

Secret value type

A simple implementation of a secure and serializable (serde and proto) type of any kind of secrets:

  • Automatically cleaning up its value after destruction in memory using zeroize;
  • Prevents leaking in logs and stack traces;
  • Stored as a byte array and suitable for binary secrets;
  • Introduces additional functions with predicates to control the exposed border; of exposed secret values and clean-ups: exposed_in_*.
  • Securely encoding/decoding from hex/base64 formats;

Working with the type:

use secret_vault_value::*;

// Creating from string
let secret_value: SecretValue = "test".into();

// Creating from vec
let secret_value: SecretValue = vec![4,2].into();

// Creating from BytesMut
let secret_value: SecretValue = bytes::BytesMut::from("test").into();

// Reading as string
let secret_value: &str = secret_value4.as_sensitive_str();

// Reading as bytes
let secret_value: &[u8] = secret_value.as_sensitive_bytes();

// Reading as hex string
let secret_value: Zeroizing<String> = secret_value.as_sensitive_hex_str();

// Reading as base64 string
let secret_value: Zeroizing<String> = secret_value.as_sensitive_base64_str();

// Controlling the exposed value with closures/lambdas
let your_result = secret_value.exposed_in_as_zstr(|secret_value|{
    todo!()
});

// Controlling the exposed value with async closures/lambdas
let your_result = secret_value.exposed_in_as_zstr_async(|secret_value| async {
    todo!()
}).await;

// Deserialize embedded string value from JSON and expose it as zeroizable structure:
#[derive(Deserialize, Zeroize)]
struct YourType {
    _some_field: String
}

let your_result_json: YourType = secret_value.expose_json_value_as::<YourType>().unwrap();

Quick start

Cargo.toml:

[dependencies]
secret-vault-type = { version = "0.3.<x>", features=["..."] }

See security consideration below about versioning.

Available optional features for secret value type:

  • serde for serde serialization support
  • prost for protobuf serialization support
  • bytes for bytes conversion support
  • hex for hex conversion support
  • base64 for 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

Dependencies

~0.3–1MB
~23K SLoC