Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recovery Phrase / Alternate Password #272

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Hrushi20
Copy link

@Hrushi20 Hrushi20 commented Dec 21, 2024

Description

We need a way to recover the encryption key if the user loses the password. We use a recovery phrase generated when you define the password. In case the user forgets the password, he can use this to change it.

Fixes #249


Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

@Hrushi20 Hrushi20 requested a review from radumarias as a code owner December 21, 2024 11:02
@Hrushi20
Copy link
Author

Hrushi20 commented Dec 22, 2024

I admit we need to refactor the code. Was just writing out the logic.

Another issue I see in the code is that the recovery key is display everytime the application is mounted and user enters the password. Need to fix that as well.

src/crypto.rs Outdated Show resolved Hide resolved
src/encryptedfs.rs Outdated Show resolved Hide resolved
src/encryptedfs.rs Outdated Show resolved Hide resolved
src/encryptedfs.rs Outdated Show resolved Hide resolved
src/encryptedfs.rs Outdated Show resolved Hide resolved
src/run.rs Outdated Show resolved Hide resolved
@Hrushi20 Hrushi20 requested a review from radumarias December 26, 2024 19:20
@Hrushi20 Hrushi20 marked this pull request as draft December 27, 2024 05:01
@Hrushi20
Copy link
Author

@radumarias Do we include (salt + user password) as an input to bip39 crate to generate recovery phrase?

@radumarias
Copy link
Member

Another issue I see in the code is that the recovery key is display everytime the application is mounted and user enters the password. Need to fix that as well.

@Hrushi20 is this fixed now?

use strum_macros::EnumIter;

pub fn generate_recovery_phrase(language: Language, password: &SecretString) -> Result<String> {
let recovery_phrase = bip39::Mnemonic::from_entropy_in(language.into(), &password.expose_secret().as_bytes())?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as from docs https://docs.rs/bip39/2.1.0/bip39/struct.Mnemonic.html#method.from_entropy_in

Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.

I assume you can't use the pass directly. You need to use KDF like https://github.com/xoriors/rencfs/blob/main/src/crypto.rs#L226 and a length of 256.


// Can create a struct here.
pub fn mnemonic_to_password(mnemonic: &SecretString) -> Result<SecretString> {
let parsed_data = bip39::Mnemonic::parse_normalized(&mnemonic.expose_secret())?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think correct is to_entropy

@@ -223,11 +232,19 @@ async fn async_main() -> Result<()> {

async fn run_change_password(cipher: Cipher, matches: &ArgMatches) -> Result<()> {
let data_dir: String = matches.get_one::<String>("data-dir").unwrap().to_string();
let recovery_phrase = matches.get_one::<SecretString>("recovery-phrase");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's per specs, but it seems those were wrong. My bad.
It's not safe to pass credentials as args because those are visible in commands like ps aux. Instead, this should be a flag that indicates we read the recovery phrase from the keyboard (like we now read the password). If this is present, we will not read the password at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recovery phrase / Alternate password
2 participants