Skip to content

Commit

Permalink
core: Add optional password entropy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Aug 25, 2024
1 parent 495bc8f commit cc920c1
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 21 deletions.
186 changes: 186 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ thiserror = "1.0.24"
time = "0.3.7"
trycmd = "0.15"
url = "2.2.2"
zxcvbn = "3.1.0"

[package]
name = "magic-wormhole"
Expand Down Expand Up @@ -100,6 +101,7 @@ thiserror = { workspace = true }
futures = { workspace = true }
url = { workspace = true, features = ["serde"] }
percent-encoding = { workspace = true }
zxcvbn = { workspace = true, optional = true }

# Transit dependencies

Expand Down Expand Up @@ -143,6 +145,8 @@ eyre = { workspace = true }

[features]

# Check the entropy of custom codes. Will fail for any weak passwords.
entropy = ["zxcvbn"]
transfer = ["transit", "dep:tar", "dep:rmp-serde"]
transit = [
"dep:noise-rust-crypto",
Expand Down
6 changes: 4 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async-std = { workspace = true, features = ["attributes", "unstable"] }
rand = { workspace = true }

# CLI specific dependencies
magic-wormhole = { path = "..", version = "0.7", features = ["all"] }
magic-wormhole = { path = "..", version = "0.7", features = ["all", "entropy"] }
clap = { workspace = true, features = ["cargo", "derive", "help"] }
clap_complete = { workspace = true }
env_logger = { workspace = true }
Expand All @@ -39,7 +39,9 @@ color-eyre = { workspace = true }
number_prefix = { workspace = true }
ctrlc = { workspace = true }
qr2term = { workspace = true }
arboard = { workspace = true, features = ["wayland-data-control"] } # Wayland by default, fallback to X11.
arboard = { workspace = true, features = [
"wayland-data-control",
] } # Wayland by default, fallback to X11.

[dev-dependencies]
trycmd = { workspace = true }
Expand Down
27 changes: 20 additions & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,26 @@ async fn parse_and_connect(
}

// TODO: Apply this change to all usages after an API break
// Check if an interactive terminal is connected
let code: Option<magic_wormhole::Code> = if std::io::stdin().is_terminal() {
// We accept a little breakage in non-interactive use, because this is a security issue
code.map(|c| c.parse()).transpose()?
} else {
// We run as a script. Only output an error
code.map(|c| c.into())
// https://github.com/magic-wormhole/magic-wormhole.rs/issues/193
// We accept a little breakage in non-interactive use, because this is a security issue
// Split the nameplate parsing from the code parsing to ensure we allow non-integer nameplates
// until the next breaking release
let res: Option<Result<magic_wormhole::Code, _>> = code.as_ref().map(|c| c.parse());
let code: Option<magic_wormhole::Code> = {
match res {
Some(Ok(code)) => Some(code),
// Check if an interactive terminal is connected
Some(Err(err)) if std::io::stdin().is_terminal() => {
// Only fail for the case where the password is < 4 characters.
// Anything else will just print an error for now.
return Err(err.into());
},
Some(Err(_)) => {
// The library crate already emits an error log for this.
code.map(|c| c.into())
},
None => None,
}
};

/* We need to track that information for when we generate a QR code */
Expand Down
Loading

0 comments on commit cc920c1

Please sign in to comment.