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

feat(strata-cli)!: add hash version and optional password #392

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

storopoli
Copy link
Member

@storopoli storopoli commented Oct 9, 2024

Description

  • Adds the HashVersion enum to the wallet encryption.
  • Adds password strenght assessment with zxcvbn.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.

Related Issues

STR-493 and STR-500.

Screenshot

Empty or very low entropy password:
image

@storopoli storopoli self-assigned this Oct 9, 2024
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 0% with 60 lines in your changes missing coverage. Please review.

Project coverage is 57.17%. Comparing base (2486f5c) to head (b3709c1).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
bin/strata-cli/src/seed/password.rs 0.00% 30 Missing ⚠️
bin/strata-cli/src/seed.rs 0.00% 19 Missing ⚠️
bin/strata-cli/src/cmd/change_pwd.rs 0.00% 11 Missing ⚠️
@@            Coverage Diff             @@
##             main     #392      +/-   ##
==========================================
- Coverage   57.35%   57.17%   -0.19%     
==========================================
  Files         255      255              
  Lines       26953    27008      +55     
==========================================
- Hits        15459    15441      -18     
- Misses      11494    11567      +73     
Files with missing lines Coverage Δ
bin/strata-cli/src/cmd/change_pwd.rs 0.00% <0.00%> (ø)
bin/strata-cli/src/seed.rs 0.00% <0.00%> (ø)
bin/strata-cli/src/seed/password.rs 0.00% <0.00%> (ø)

... and 5 files with indirect coverage changes

@storopoli storopoli marked this pull request as ready for review October 9, 2024 14:49
Copy link
Member Author

@storopoli storopoli left a comment

Choose a reason for hiding this comment

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

@Zk2u can you please check the impl?
@AaronFeickert can you check if the messages are proper?

@storopoli storopoli force-pushed the STR-493-allow-user-to-enter-empty-password branch from 41239e4 to af124fa Compare October 9, 2024 14:58
let entropy = new_pw.entropy();
let _ = term.write_line(
format!(
"Password strength (estimated crack time): {}",
Copy link
Member Author

Choose a reason for hiding this comment

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

What about?

Suggested change
"Password strength (estimated crack time): {}",
"Password strength (estimated time needed by an attacker): {}",

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's neat that the library can do time estimates, but I'm not sure it's particularly useful for the end user. Is a decade sufficiently strong? A thousand years? It's not really actionable.

My recommendation is instead to use the score provided by the library (but without showing it to the user directly). If the score is at least 3 (sufficiently strong), don't provide any feedback. If the score is below that threshold, warn the user and consider providing feedback.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestions, totally agreed.
I've implemented in b3709c1

Copy link
Member Author

Choose a reason for hiding this comment

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

PS: Screenshots updated

Comment on lines 19 to 22
HashVersion::V0 => (
Algorithm::Argon2id,
Version::V0x13,
Params::new(19_456, 2, 1, None),
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend including a citation comment to the relevant OWASP recommendation to justify these magic numbers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also recommend explicitly specifying the output length instead of relying on the None default behavior for the parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, done in 953d9f4

@storopoli storopoli force-pushed the STR-493-allow-user-to-enter-empty-password branch from af124fa to b3709c1 Compare October 9, 2024 18:28
@@ -12,6 +13,17 @@ pub struct ChangePwdArgs {}
pub async fn change_pwd(_args: ChangePwdArgs, seed: Seed, persister: impl EncryptedSeedPersister) {
let term = Term::stdout();
let mut new_pw = Password::read(true).unwrap();
let entropy = new_pw.entropy();
let _ = term.write_line(format!("Password strength (Overall strength score from 0-4, where anything below 3 is too weak): {}", entropy.score()).as_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a nit, but I wouldn't even bother showing the user the score, since it's not really actionable on its own. If the passphrase is weak and there's feedback, let the user know. If it's strong, just set the passphrase.

@@ -188,6 +195,17 @@ pub fn load_or_create(
};

let mut password = Password::read(true).map_err(OneOf::new)?;
let entropy = password.entropy();
let _ = term.write_line(format!("Password strength (Overall strength score from 0-4, where anything below 3 is too weak): {}", entropy.score()).as_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

See other comment.

@delbonis
Copy link
Contributor

delbonis commented Oct 9, 2024

Fntests failing, it's probably the flaky test.

@delbonis delbonis merged commit 22e9592 into main Oct 9, 2024
14 of 17 checks passed
Rajil1213 pushed a commit that referenced this pull request Oct 10, 2024
* feat(strata-cli)!: add hash version and optional password

* feat(strata-cli): warn user about password strength
sapinb pushed a commit that referenced this pull request Oct 27, 2024
* feat(strata-cli)!: add hash version and optional password

* feat(strata-cli): warn user about password strength
storopoli added a commit that referenced this pull request Oct 28, 2024
* feat(strata-cli)!: add hash version and optional password

* feat(strata-cli): warn user about password strength
storopoli added a commit that referenced this pull request Oct 28, 2024
* feat(strata-cli)!: add hash version and optional password

* feat(strata-cli): warn user about password strength
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.

3 participants