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

Drop passlib, switch to argon2id hashes #6657

Merged
merged 2 commits into from
Oct 19, 2022
Merged

Drop passlib, switch to argon2id hashes #6657

merged 2 commits into from
Oct 19, 2022

Conversation

legoktm
Copy link
Member

@legoktm legoktm commented Oct 19, 2022

Status

Ready for review

Description of Changes

  • Use argon2-cffi directly instead of through passlib.
  • Switch to argon2id passphrase hashes for journalists

The individual commit messages have more details on specifics.

Fixes #6631.
Fixes #6655.

Testing

  • Spin up a dev environment using develop (probably use HEAD~2 since develop will have moved forward since I wrote this). Log in as journalist. Look in the database (e.g. SELECT username, passphrase_hash FROM journalists) and verify the hash starts with $argon2i$....
  • Check out this branch, see the dev environment reload models.py
  • Log in as journalist again. Look in the database and verify the hash now starts with $argon2id$...
  • Spin up a fresh dev environment, verify the passphrase_hashes start with $argon2id$...

Note that there's a 50% chance the generated journalist uses the even more legacy pw_hash/pw_salt scrypt mechanism if you notice that passphrase_hash is sometimes null.

Deployment

Any special considerations for deployment?

  • Newly created journalists will use the argon2id hash by default.
  • Existing journalists will be migrated as they log in.

Checklist

  • Linting (make lint) and tests (make test) pass in the development container
  • I have written a test plan and validated it for this PR
  • These changes do not require documentation

Unfortunately passlib appears unmaintained with no commits in the past 2
years and literal spam tickets in their issue tracker. It brings in ~20k
lines of code (per tokei), but we only need the argon2 functionality
that is in argon2-cffi already.

Using argon2-cffi directly is roughly the same, with just a few renames
(e.g. rounds → time_cost) and different method signatures (verify()
throws an exception instead of returning false).

We explicitly specify a type=argon2i, in the next commit we'll switch
over to argon2id.

Fixes #6631.
argon2id is the current recommended hashing algorithm, as it is able to
take advantage of both the argon2d and argon2i algorithms. It's the
default in argon2-cffi as well.

argon2-cffi automatically handles verifying argon2i passphrases, this is
verified in the new `test_passphrase_argon2i_migration` test case. We
use the `check_needs_rehash()` function to see if it needs an update,
and rehash if so.

valid_password() has been slight adjusted that we return False as soon
as we know the passphrase is invalid rather than needing to guard the
migration checks against is_valid.

The test_valid_login_calls_argon2 test is dropped because it broke with
the new migration checking and IMO provides little value.

Fixes #6655.
@legoktm legoktm requested a review from a team as a code owner October 19, 2022 19:41
@eaon eaon self-assigned this Oct 19, 2022
Copy link
Contributor

@eaon eaon left a comment

Choose a reason for hiding this comment

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

Yay for dependency slashing. Checks out, looks great, thanks!

@eaon eaon merged commit d42422e into develop Oct 19, 2022
@eaon eaon deleted the argon2 branch October 19, 2022 21:18
@cfm cfm mentioned this pull request Jun 15, 2023
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants