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

Do password hashing properly #9942

Merged
merged 4 commits into from
Dec 6, 2018
Merged

Do password hashing properly #9942

merged 4 commits into from
Dec 6, 2018

Conversation

Chocobo1
Copy link
Member

@Chocobo1 Chocobo1 commented Nov 29, 2018

Some notes:

  • openssl >= 1.0 is now a required dependency.
  • This PR makes stored password hash very much harder to crack compared to previously used method.
    This basically means even if bad actor acquired your password hash, he won't be able to easily compute your real password (assuming the real password is good enough for brute force attack).
  • UI changes: GUI, WebUI
  • PBKDF2 is chosen because qbt already uses openssl which saves us from adding another library, and also it is the only method openssl implemented AFAIK.
  • PBKDF2 parameters are chosen to be in line with 1password settings: https://support.1password.com/pbkdf2/
  • I've not provide mitigation code yet, that is, user need to change the password from the default one after upgrading, is this really required?

@Chocobo1 Chocobo1 added Security Related to software vulnerability in qbt (don't overuse this) WebUI WebUI-related issues/changes GUI GUI-related issues/changes labels Nov 29, 2018
@Chocobo1 Chocobo1 force-pushed the pbkdf2 branch 4 times, most recently from a394c93 to 7afdf9d Compare November 29, 2018 17:44
Copy link
Member

@glassez glassez left a comment

Choose a reason for hiding this comment

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

@Chocobo1, why don't you use QCryptographicHash just with more complex algorithm (SHA512)?

@Chocobo1
Copy link
Member Author

@Chocobo1, why don't you use QCryptographicHash just with more complex algorithm (SHA512)?

It is too weak for this purpose, you may look up "Key stretching".

@Chocobo1 Chocobo1 force-pushed the pbkdf2 branch 2 times, most recently from bbec58e to e5429e6 Compare December 3, 2018 04:19
@Chocobo1
Copy link
Member Author

Chocobo1 commented Dec 3, 2018

PR updated: resolved all comments.

glassez
glassez previously approved these changes Dec 3, 2018
Copy link
Member

@glassez glassez left a comment

Choose a reason for hiding this comment

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

LGTM. Untested though.

@sledgehammer999
Copy link
Member

IMO, PR scope looks good. But I wonder if we should do more for the nox users. I assume they have set it up to run as a daemon and may not realize the daemon doesn't run due to this change.

Or maybe target this for 4.2.0?

Any thoughts?

@Chocobo1
Copy link
Member Author

Chocobo1 commented Dec 4, 2018

I assume they have set it up to run as a daemon and may not realize the daemon doesn't run due to this change.

The mitigation action will look like this:

// pseudo code

void AuthController::loginAction()
{
  const bool passwordEqual = Utils::Password::PBKDF2::verify(secret, passwordFromWeb);
  if (!passwordEqual) {
    const bool oldPasswordEqual = // load previous webui password and verify it using previous method
    if (oldPasswordEqual)
      // update webui password using new method
    else
      // authentication failed
  }
}

While it is convenient for WebAPI users, we probably need to keep this mitigation code forever...
Or we can put out a warning in the News section? Stating that we are hardening this part and users needs to update their password from the default one.

Or maybe target this for 4.2.0?

Should be better than breaking WebAPI users in a qbt minor release, this PR is still eligible for merging into master right?

@sledgehammer999
Copy link
Member

I would have no problem if this goes into master. I just hope it won't make backporting other commits harder.

@Chocobo1
Copy link
Member Author

Chocobo1 commented Dec 5, 2018

PR updated: resolved conflicts in configure file.

@LordNyriox
Copy link
Contributor

@Chocobo1:

openssl >= 1.0 is now a required dependency.

Can you please add the OpenSSL version to the About –> Libraries GUI?

It has bugged me forever that I can never tell what OpenSSL version qBittorrent was built on (without asking someone).

@sledgehammer999
Copy link
Member

@Chocobo1 I don't know the level of paranoid we should be about this but just in case:

  1. Variable number of iterations: Have the base iteration number (100.000) and add a random number between 1 and 20.000. Of course save this info along with the salt too
  2. Use scrypt/argon2 instead of PBKDF2

Just suggestions. They are not required for merging this.

@Chocobo1
Copy link
Member Author

Chocobo1 commented Dec 5, 2018

Can you please add the OpenSSL version to the About –> Libraries GUI?

OK, but will do it in another PR.

Variable number of iterations: Have the base iteration number (100.000) and add a random number between 1 and 20.000. Of course save this info along with the salt too

I don't think this is the correct way (or any better), since we already use a lengthy salt that is infeasible for the hacker to pre-compute, and besides (in the extreme case) the hacker can just use 100.000 as a start and iterate all the way up to 120.000.

Use scrypt/argon2 instead of PBKDF2

We can but we need to find & include another library, using openssl is the cheapest in this matter :P

@Chocobo1 Chocobo1 merged commit 6bb4eb8 into qbittorrent:master Dec 6, 2018
@Chocobo1 Chocobo1 deleted the pbkdf2 branch December 6, 2018 08:22
@Chocobo1
Copy link
Member Author

Chocobo1 commented Dec 6, 2018

Thanks for the review!

@WolfganP
Copy link

WolfganP commented Dec 7, 2018

While compiling from master, I'm seeing a linking error now:

linking qbittorrent-nox

/usr/bin/ld: password.o: undefined reference to symbol 'PKCS5_PBKDF2_HMAC@@OPENSSL_1_1_0'

//usr/lib/arm-linux-gnueabihf/libcrypto.so.1.1: error adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status

Makefile:576: recipe for target 'qbittorrent-nox' failed

make[1]: *** [qbittorrent-nox] Error 1

make[1]: Leaving directory '/mnt/usb_12/wTools/qBittorrent/src'

Makefile:42: recipe for target 'sub-src-make_first' failed

make: *** [sub-src-make_first] Error 2

@thalieht
Copy link
Contributor

thalieht commented Dec 7, 2018

A ./configure solved it for me.

@WolfganP
Copy link

WolfganP commented Dec 7, 2018

A ./configure solved it for me.

@thalieht Thx, it worked for me as well.

@Piccirello
Copy link
Member

Could you update the WebAPI documentation for get/set preferences with this change? It still talks about md5 hashes.

@Chocobo1
Copy link
Member Author

Could you update the WebAPI documentation for get/set preferences with this change? It still talks about md5 hashes.

Done, I presume it will start taking effect in API v.2.3.0.

@sledgehammer999
Copy link
Member

API v.2.3.0.

Whatever the API will be in v4.2.0. This wasn't backported to the v4.1.x series.

@Piccirello Piccirello mentioned this pull request Jan 31, 2019
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI GUI-related issues/changes Security Related to software vulnerability in qbt (don't overuse this) WebUI WebUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants