Skip to content

Commit

Permalink
Add password verification for stratis-min
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Aug 13, 2024
1 parent 06fbfa1 commit 8a64d23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions dracut/90stratis/stratis-rootfs-setup
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ if $(stratis-min pool is-stopped "$STRATIS_ROOTFS_UUID"); then
ATTEMPTS_REMAINING=3
if
! while [ $((ATTEMPTS_REMAINING--)) -gt 0 ]; do
systemd-ask-password --id="stratis:$STRATIS_ROOTFS_UUID" "Enter password for Stratis pool with UUID $STRATIS_ROOTFS_UUID containing root filesystem" |
stratis-min pool start --prompt --unlock-method=keyring "$STRATIS_ROOTFS_UUID" && break
PASSWORD=$(systemd-ask-password --id="stratis:$STRATIS_ROOTFS_UUID" "Enter password for Stratis pool with UUID $STRATIS_ROOTFS_UUID containing root filesystem")

echo -e "$PASSWORD\n$PASSWORD\n" | stratis-min pool start --prompt --unlock-method=keyring "$STRATIS_ROOTFS_UUID" && break
done
then
echo Failed to start pool with UUID $STRATIS_ROOTFS_UUID using a passphrase >&2
Expand Down
16 changes: 13 additions & 3 deletions src/jsonrpc/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use nix::unistd::isatty;
use termios::{tcsetattr, Termios, ECHO, ECHONL, TCSADRAIN};

use crate::stratis::StratisResult;
use crate::stratis::{StratisError, StratisResult};

#[macro_export]
macro_rules! do_request {
Expand Down Expand Up @@ -217,8 +217,8 @@ pub fn to_suffix_repr(size: u128) -> String {
})
}

pub fn prompt_password() -> StratisResult<Option<String>> {
print!("Enter passphrase followed by return: ");
pub fn get_passphrase(msg: &str) -> StratisResult<Option<String>> {
print!("{}", msg);
stdout().flush()?;

let stdin = stdin();
Expand Down Expand Up @@ -252,6 +252,16 @@ pub fn prompt_password() -> StratisResult<Option<String>> {
}
}

pub fn prompt_password() -> StratisResult<Option<String>> {
let pass = get_passphrase("Enter passphrase followed by return: ")?;
let verify_pass = get_passphrase("Verify passphrase: ")?;
if pass != verify_pass {
Err(StratisError::Msg("Passphrases did not match".to_string()))
} else {
Ok(pass)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 8a64d23

Please sign in to comment.