ask password twice
This commit is contained in:
parent
46bcc2f52a
commit
8a9cf9019d
@ -167,14 +167,32 @@ impl PasswordHelper {
|
|||||||
use PasswordHelper::*;
|
use PasswordHelper::*;
|
||||||
match self {
|
match self {
|
||||||
Systemd => unimplemented!(),
|
Systemd => unimplemented!(),
|
||||||
Stdin => Ok(rpassword::read_password_from_tty(Some("Password: "))?),
|
Stdin => Ok(rpassword::read_password_from_tty(Some("Password: "))
|
||||||
|
.map_err(|e| Fido2LuksError::AskPassError {
|
||||||
|
cause: AskPassError::IO(e),
|
||||||
|
})
|
||||||
|
.and_then(|pass| {
|
||||||
|
match rpassword::read_password_from_tty(Some("Password again: ")).map_err(|e| {
|
||||||
|
Fido2LuksError::AskPassError {
|
||||||
|
cause: AskPassError::IO(e),
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Ok(ref pass2) if &pass == pass2 => Ok(pass),
|
||||||
|
Ok(_) => Err(Fido2LuksError::AskPassError {
|
||||||
|
cause: error::AskPassError::Mismatch,
|
||||||
|
}),
|
||||||
|
e => e,
|
||||||
|
}
|
||||||
|
})?),
|
||||||
Script(password_helper) => {
|
Script(password_helper) => {
|
||||||
let mut helper_parts = password_helper.split(" ");
|
let mut helper_parts = password_helper.split(" ");
|
||||||
|
|
||||||
let password = Command::new((&mut helper_parts).next().unwrap())
|
let password = Command::new((&mut helper_parts).next().unwrap())
|
||||||
.args(helper_parts)
|
.args(helper_parts)
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| Fido2LuksError::AskPassError { cause: e })?
|
.map_err(|e| Fido2LuksError::AskPassError {
|
||||||
|
cause: error::AskPassError::IO(e),
|
||||||
|
})?
|
||||||
.stdout;
|
.stdout;
|
||||||
Ok(String::from_utf8(password)?.trim().to_owned())
|
Ok(String::from_utf8(password)?.trim().to_owned())
|
||||||
}
|
}
|
||||||
|
12
src/error.rs
12
src/error.rs
@ -1,12 +1,12 @@
|
|||||||
use ctap::FidoError;
|
use ctap::FidoError;
|
||||||
use std::io;
|
use std::{fmt, io};
|
||||||
|
|
||||||
pub type Fido2LuksResult<T> = Result<T, Fido2LuksError>;
|
pub type Fido2LuksResult<T> = Result<T, Fido2LuksError>;
|
||||||
|
|
||||||
#[derive(Debug, Fail)]
|
#[derive(Debug, Fail)]
|
||||||
pub enum Fido2LuksError {
|
pub enum Fido2LuksError {
|
||||||
#[fail(display = "unable to retrieve password: {}", cause)]
|
#[fail(display = "unable to retrieve password: {}", cause)]
|
||||||
AskPassError { cause: io::Error },
|
AskPassError { cause: AskPassError },
|
||||||
#[fail(display = "unable to read keyfile: {}", cause)]
|
#[fail(display = "unable to read keyfile: {}", cause)]
|
||||||
KeyfileError { cause: io::Error },
|
KeyfileError { cause: io::Error },
|
||||||
#[fail(display = "authenticator error: {}", cause)]
|
#[fail(display = "authenticator error: {}", cause)]
|
||||||
@ -32,6 +32,14 @@ pub enum ConfigurationError {
|
|||||||
MissingField(String),
|
MissingField(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Fail)]
|
||||||
|
pub enum AskPassError {
|
||||||
|
#[fail(display = "unable to retrieve password: {}", _0)]
|
||||||
|
IO(io::Error),
|
||||||
|
#[fail(display = "provided passwords don't match")]
|
||||||
|
Mismatch,
|
||||||
|
}
|
||||||
|
|
||||||
impl From<serde_json::error::Error> for Fido2LuksError {
|
impl From<serde_json::error::Error> for Fido2LuksError {
|
||||||
fn from(e: serde_json::error::Error) -> Self {
|
fn from(e: serde_json::error::Error) -> Self {
|
||||||
Fido2LuksError::ConfigurationError {
|
Fido2LuksError::ConfigurationError {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user