rencfs

rencfs-bin crates.io docs.rs build-and-tests release codecov Matrix Discord Zulip Open Source Helpers

[!WARNING]
This crate hasn’t been audited, it’s using ring crate which is a well-known audited library, so in principle at least the primitives should offer similar level of security.
This is still under development. Please do not use it with sensitive data for now, please wait for a stable release.
It’s mostly ideal for experimental and learning projects.

An encrypted file system written in Rust that is mounted with FUSE on Linux. It can be used to create encrypted directories.

You can then safely backup the encrypted directory to an untrusted server without worrying about the data being exposed. You can also store it in any cloud storage like Google Drive, Dropbox, etc. and have it synced across multiple devices.

You can use it as CLI or as a library to build your custom FUSE implementation or other apps that works with encrypted data.

Key features

Functionality

In progress:

rencfs

Stack

Usage

Give it a quick try with Docker

Get the image

docker pull xorio42/rencfs

Start a container to set up mount in it

docker run -it --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined xorio42/rencfs:latest /bin/sh

In the container create mount and data directories

mkdir fsmnt && mkdir fsdata

Start rencfs

rencfs mount --mount-point fsmnt --data-dir fsdata

Enter a password for encryption.

Get the container ID

docker ps

In another terminal, attach to running container with the above ID

docker exec -it <ID> /bin/sh

From here you can play with it by creating files in fsmnt directory

cd fsmnt
mkdir 1
ls
echo "test" > 1/test
cat 1/test

As a library

For the library, you can follow the documentation.

Command Line Tool

Dependencies

To use the encrypted file system, you need to have FUSE installed on your system. You can install it by running the following command (or based on your distribution).

Arch

sudo pacman -Syu && sudo pacman -S fuse3

Ubuntu

sudo apt-get update && sudo apt-get -y install fuse3

Install from AUR

You can install the encrypted file system binary using the following command

yay -Syu && yay -S rencfs

Install with cargo

You can install the encrypted file system binary using the following command

cargo install rencfs

A basic example of how to use the encrypted file system is shown below

rencfs mount --mount-point MOUNT_POINT --data-dir DATA_DIR

It will prompt you to enter a password to encrypt/decrypt the data.

Change Password

The master encryption key is stored in a file and encrypted with a key derived from the password. This offers the possibility to change the password without needing to re-encrypt the whole data. This is done by decrypting the master key with the old password and re-encrypting it with the new password.

To change the password, you can run the following command

rencfs passwd --data-dir DATA_DIR 

DATA_DIR where the encrypted data is stored

It will prompt you to enter the old password and then the new password.

Encryption info

You can specify the encryption algorithm adding this argument to the command line

--cipher CIPHER ...

Where CIPHER is the encryption algorithm. You can check the available ciphers with rencfs --help.
Default value is ChaCha20Poly1305.

Log level

You can specify the log level adding the --log-level argument to the command line. Possible values: TRACE, DEBUG, INFO (default), WARN, ERROR.

rencfs --log-level LEVEL ...

Use it in Rust

You can see more here

Build from source

Browser

Open in Gitpod

Open Rustlings On Codespaces

You can compile it, run it, and give it a quick try in browser. After you start it from above

sudo apt-get update && sudo apt-get install fuse3
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
mkdir mnt && mkdir data
cargo run --release -- mount -m mnt -d data

Open another terminal

cd mnt
mkdir a && cd a
echo "test" > test.txt
cat test.txt

Locally

For now the FUSE (fuse3 crate) only works on Linux, so to start the project you will need to be on Linux. Instead, you can Develop inside a Container, which will start a local Linux container, the IDE will connect to it, you can build and start the app in there and also use terminal to test it.

Getting the sources

git clone git@github.com:radumarias/rencfs.git && cd rencfs

Dependencies

Rust

To build from source, you need to have Rust installed, you can see more details on how to install it here.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Accordingly, it is customary for Rust developers to include this directory in their PATH environment variable. During installation rustup will attempt to configure the PATH. Because of differences between platforms, command shells, and bugs in rustup, the modifications to PATH may not take effect until the console is restarted, or the user is logged out, or it may not succeed at all.

If, after installation, running rustc --version in the console fails, this is the most likely reason. In that case please add it to the PATH manually.

Project is setup to use nightly toolchain in rust-toolchain.toml, on first build you will see it fetch the nightly.

cargo install cargo-aur
cargo install cargo-generate-rpm

Other dependencies

Also, these deps are required (or based on your distribution):

Arch

sudo pacman -Syu && sudo pacman -S fuse3 base-devel

Ubuntu

sudo apt-get update && sudo apt-get install fuse3 build-essential

Fedora

sudo dnf update && sudo dnf install fuse3 && dnf install @development-tools

Build for debug

cargo build

Build release

cargo build --release

Run

cargo run --release -- mount --mount-point MOUNT_POINT --data-dir DATA_DIR

Dev settings

If you don’t want to be prompted for password, you can set this env var and run like this:

RENCFS_PASSWORD=PASS cargo run --release -- mount --mount-point MOUNT_POINT --data-dir DATA_DIR

For dev mode is recommended to run with DEBUG log level:

cargo run --release -- --log-level DEBUG mount --mount-point MOUNT_POINT --data-dir DATA_DIR

Build local RPM for Fedora

This is using cargo-generate-rpm

cargo install cargo-generate-rpm
cargo build --release
cargo generate-rpm

The generated RPM will be located here: target/generate-rpm.

Install and run local RPM

cd target/generate-rpm/
sudo dnf localinstall rencfs-xxx.x86_64.rpm

Developing inside a Container

See here how to configure for RustRover and for VsCode.

You can use the .devcontainer directory from the project to start a container with all the necessary tools to build and run the app.

Minimum Supported Rust Version (MSRV)

The minimum supported version is 1.75.

Future

Performance

Aes256Gcm is slightly faster than ChaCha20Poly1305 by a factor of 1.28 on average. This is because of the hardware acceleration of AES on most CPUs via AES-NI. But where hardware acceleration is not available ChaCha20Poly1305 is faster. Also ChaChaPoly1305 is better at SIMD.

Cipher comparison

AES-GCM vs. ChaCha20-Poly1305

Conclusion

Both are good options. AES-GCM can be faster with hardware support, but pure-software implementations of ChaCha20-Poly1305 are almost always fast and constant-time.

Security

Considerations

Contribute

Feel free to fork it, change and use it in any way that you want. If you build something interesting and feel like sharing pull requests are always appreciated.

How to contribute

Please see CONTRIBUTING.md.