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

Fix send password handling #493

Merged
merged 3 commits into from
Jan 11, 2024
Merged

Fix send password handling #493

merged 3 commits into from
Jan 11, 2024

Conversation

Hinton
Copy link
Member

@Hinton Hinton commented Jan 10, 2024

Type of change

- [x] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

We should hash send passwords appropriately using pbkdf. Also changed how SendView handles passwords. It no longer provides the password but rather a boolean field has_password to prevent accidentally overriding the password when doing send.decrypt().encrypt().

Before you submit

  • Please add unit tests where it makes sense to do so

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (339f45e) 49.34% compared to head (2c8ef50) 49.51%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #493      +/-   ##
==========================================
+ Coverage   49.34%   49.51%   +0.17%     
==========================================
  Files         154      154              
  Lines        7373     7398      +25     
==========================================
+ Hits         3638     3663      +25     
  Misses       3735     3735              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hinton Hinton marked this pull request as ready for review January 11, 2024 09:25
@Hinton Hinton requested a review from dani-garcia January 11, 2024 09:25
@Hinton Hinton changed the title Hash send passwords Fix send password handling Jan 11, 2024
@dani-garcia
Copy link
Member

Hmm, this works but I think it would be clearer if we separated the password hashing to a different function and left the encrypt/decrypt to just do encryption.

We can even have a HashedPassword newtype to avoid people accidentally passing an unhashed password. What do you think?

let password: HashedPassword = client.kdf().hash_send_password(password);
let send = Send {
    password,
    ....
};
// Now in decrypt/encrypt we can just pass the field around without modifying it.
send.encrypt().decrypt();

@Hinton
Copy link
Member Author

Hinton commented Jan 11, 2024

@dani-garcia There are some more nuances to this. The server will also hash the password. The server response for the password field is actually serverHashed(clientHashed(password)).

If on encrypt we respond with serverHashed(clientHashed(password)) it may accidentally be sent directly to the server meaning it will be re-hashed and end up as serverHashed(serverHashed(clientHashed(password))).

My desire with the current approach was to completely eliminate the possibility of calling view.encrypt() and uploading it to the server without first removing send.password.

dani-garcia
dani-garcia previously approved these changes Jan 11, 2024
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Ah fair enough, I forgot about the server side hashing, maybe there's something we could do with an enum like enum SendPassword { NoPassword, AlreadySet, New(String) }, but maybe that won't translate very nicely to the mobile bindings.

@Hinton Hinton merged commit b385d2d into main Jan 11, 2024
42 checks passed
@Hinton Hinton deleted the ps/send-hash-password branch January 11, 2024 14:06
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.

2 participants