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

allow request for new key to confirm entered pass #702

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ merge = { workspace = true }

directories = { workspace = true }
nom = { workspace = true }
rpassword = { workspace = true }
dialoguer = "0.10.4"
bytesize = { workspace = true }
indicatif = { workspace = true }
path-dedot = { workspace = true }
Expand Down Expand Up @@ -232,7 +232,6 @@ cachedir = "0.3"

# commands
merge = "0.1"
rpassword = "7"
directories = "5"
nom = "7"
indicatif = "0.17"
Expand Down
1 change: 1 addition & 0 deletions changelog/new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ New features:
- New option: `no-require-git` for backup - if enabled, a git repository is not required to apply `git-ignore` rule.
- fix: wait for password-command to successfully exit, allowing to input something into the command, and read password from stdout.
- repoinfo: Added new options --json, --only-files, --only-index
- Creation of new keys now enforces confirmation of entered key. This helps to prevent mistype of passwords during the initial entry
2 changes: 1 addition & 1 deletion crates/rustic_core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rustic_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ clap = { workspace = true, optional = true }
clap_complete = { workspace = true, optional = true }

merge = { workspace = true, optional = true }
rpassword = { workspace = true }
dialoguer = "0.10.4"
directories = { workspace = true }
nom = { workspace = true }
path-dedot = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/rustic_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ pub use crate::{
},
RepoFile,
},
repository::{OpenRepository, Repository, RepositoryOptions},
repository::{read_password_from_reader, OpenRepository, Repository, RepositoryOptions},
};
9 changes: 6 additions & 3 deletions crates/rustic_core/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use nom::{
sequence::delimited,
IResult,
};
use rpassword::prompt_password;
use dialoguer::Password;

use serde_with::{serde_as, DisplayFromStr};

Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn parse_command<'a, E: ParseError<&'a str>>(
)(input)
}

pub(crate) fn read_password_from_reader(file: &mut impl BufRead) -> RusticResult<String> {
pub fn read_password_from_reader(file: &mut impl BufRead) -> RusticResult<String> {
let mut password = String::new();
_ = file
.read_line(&mut password)
Expand Down Expand Up @@ -350,7 +350,10 @@ pub(crate) fn get_key(be: &impl ReadBackend, password: Option<String>) -> Rustic
// TODO: Differentiate between wrong password and other error!
if let Ok(key) = find_key_in_backend(
be,
&prompt_password("enter repository password: ")
&Password::new()
.with_prompt("enter repository password")
.allow_empty_password(true)
.interact()
.map_err(RepositoryErrorKind::ReadingPasswordFromPromptFailed)?,
None,
) {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{bail, Result};
use crate::{commands::get_repository, Application, RUSTIC_APP};

use bytes::Bytes;
use rpassword::prompt_password;
use dialoguer::Password;

use rustic_core::{
hash, random_poly, ConfigFile, DecryptBackend, DecryptWriteBackend, FileType, Id, Key, KeyFile,
Expand Down Expand Up @@ -80,7 +80,11 @@ pub(crate) fn save_config(
let key = Key::new();

let pass = password.map_or_else(
|| match prompt_password("enter password for new key: ") {
|| match Password::new().with_prompt("enter password for new key")
.allow_empty_password(true)
.with_confirmation("confirm password", "passwords do not match")
.interact()
{
Ok(it) => it,
Err(err) => {
status_err!("{}", err);
Expand Down
12 changes: 8 additions & 4 deletions src/commands/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use anyhow::Result;

use std::{fs::File, io::BufReader};

use rpassword::{prompt_password, read_password_from_bufread};
use dialoguer::Password;

use rustic_core::{hash, FileType, KeyFile, WriteBackend};
use rustic_core::{hash, read_password_from_reader, FileType, KeyFile, WriteBackend};

/// `key` subcommand
#[derive(clap::Parser, Command, Debug)]
Expand Down Expand Up @@ -79,7 +79,11 @@ impl AddCmd {
let key = repo.key;

let pass = self.new_password_file.as_ref().map_or_else(
|| match prompt_password("enter password for new key: ") {
|| match Password::new().with_prompt("enter password for new key")
.allow_empty_password(true)
.with_confirmation("confirm password", "passwords do not match")
.interact()
{
Ok(it) => it,
Err(err) => {
status_err!("{}", err);
Expand All @@ -94,7 +98,7 @@ impl AddCmd {
RUSTIC_APP.shutdown(Shutdown::Crash);
}
});
match read_password_from_bufread(&mut file) {
match read_password_from_reader(&mut file) {
Ok(it) => it,
Err(err) => {
status_err!("{}", err);
Expand Down