#memory-protection #data-protection #memory #data-security #protection #secret #memory-access

shush-rs

A Rust crate designed to manage sensitive data securely by leveraging memory protection mechanisms

11 releases

0.1.11 Nov 18, 2024
0.1.10 Sep 16, 2024

#155 in Memory management

Download history 98/week @ 2024-09-04 382/week @ 2024-09-11 150/week @ 2024-09-18 45/week @ 2024-09-25 57/week @ 2024-10-02 58/week @ 2024-10-09 44/week @ 2024-10-16 137/week @ 2024-10-23 4/week @ 2024-11-06 165/week @ 2024-11-13 100/week @ 2024-11-20 27/week @ 2024-11-27 136/week @ 2024-12-04

432 downloads per month
Used in rencfs

MIT/Apache

16KB
302 lines

shush-rs

crates.io Github

A Rust crate designed to manage sensitive data securely by leveraging memory protection mechanisms. It extends the functionality of the secrecy crate to provide enhanced security features using memory locking and protection techniques. Specifically, shush-rs ensures that secrets are kept safe from unauthorized access and are properly zeroized when no longer needed.

Brief overview

  • mlock: this is a system call that locks a specified range of memory into RAM, preventing it from being swapped out to disk.
  • mprotect: is a system call that changes the access protections (read, write, execute) for a specified range of memory.

Features

  • Memory Locking: Uses mlock to lock the secret's memory page, preventing it from being swapped to disk.
  • Memory Protection: Employs mprotect to initially set the memory page to non-readable/writable and then to readable/writable only when needed.
  • Zeroization: Guarantees that secrets are securely zeroized before they are dropped, minimizing the risk of sensitive data lingering in memory.

Key Components

  • SecretBox: A secure container for sensitive data. It locks the memory of the contained secret and ensures it is zeroized on drop.
  • CloneableSecret: A trait for secrets that can be cloned, while ensuring the original is zeroized after cloning.
  • ExposeSecret and ExposeSecretMut: Traits that provide controlled access to secrets, allowing read-only or mutable access while maintaining security.

Usage

fn protect_secret(){

  let secret = Box::new(String::from("Encrypted"));

  let mut secret_box = SecretBox::new(secret); // Secret's memory page is mlocked

  println!("Secret: {:?}", secret_box); // Prints "Secret: SecretBox<alloc::string::String>([REDACTED])"

  let exposed_secret = secret_box.expose_secret();

  println!("Exposed Secret:{:?}", exposed_secret); // Prints "ExposedSecret: SecretGuardMut { data: "Encrypted" }"
} // Memory page is munlocked when it's dropped

Dependencies

~0–7.5MB
~58K SLoC