Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pw hashing rework#1114

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
M4LuZ wants to merge26 commits intomaster
base:master
Choose a base branch
Loading
frompw-hashing-rework
Draft

Pw hashing rework#1114

M4LuZ wants to merge26 commits intomasterfrompw-hashing-rework

Conversation

M4LuZ
Copy link
Collaborator

What is this PR doing?

Recreation of PR#83 on current master with quite a good amount of further work done.
This is not yet complete, but close enough for a wider audience to have a look and provide feedback.

  • Supports any algorithm frompbkdf2
  • Setspbkdf2-sha512 as default
  • Provides default config for all of them including fallback to a supported algorithm
  • Provides override of default config for hashing (if ever needed)
  • Adds option to convert existingmd5 hashes to an intermediate custom formatmd5-sha512via update script with transparent changeover on login topbkdf2-sha512, depends on a module framework rework or CLI updater to be fully usable
  • Unit tests provided and passing (tests for methodhash and implementation code be done)
  • Good amount of code simplifications (but some still to be done)
  • Plus everything that the existing PR already did

Which issue(s) this PR fixes:

refs#83

Checklist

  • CHANGELOG.md entry
  • Documentation update

lxpand others added21 commitsJanuary 3, 2021 16:30
This change modifies the database and requires a database upgradefrom within the lansuite admin area.After the database upgrade, the old MD5 user passwords will beautomatically converted to PBKDF2-SHA1 on the next user login.Clan and team passwords will only be upgraded, when new passwordsare set.PBKDF2-SHA1 was choosen for compatibility with the ejabberd XMPPserver password storage.
@andygrunwald
Copy link
Collaborator

@M4LuZ What is missing for this PR to move out of the draft status?

This is not yet complete, but close enough for a wider audience to have a look and provide feedback.

@M4LuZ
Copy link
CollaboratorAuthor

M4LuZ commentedMay 30, 2024
edited
Loading

Hi@andygrunwald ,

modules/install/upgrade/2.0.php is untested and has no means to be called currently.
I wanted to provide an easy mean to transfer existing md5 hashes to PBKDF2 as part of the upgrade (either by a proper module upgrade handling or a cli tool), which is a separate PR not yet done and sitting on my dev machine.

Also I was thinking about extending cases withbcrypt as that provides the similar properties asargon2id, but is part of the default PHP environment.

Unit-tests for the hashing function itself are missing and as this is one of the most crucial bits that must work I would like to see them defined and working first

But as for the original features and functionality this is feature-complete, tested and has unit test cases working

Copy link
Collaborator

@andygrunwaldandygrunwald left a comment
edited
Loading

Choose a reason for hiding this comment

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

I had a quick review and it seems we need to put a bit more work into this.@M4LuZ Let me know if you have time to do it or if you require some help.

Overall: I don't like the "global static" aspect of the class. This makes it pretty hard to re-use. I would rather love to see an object oriented approach with inheritance where each algorithm is its own sub class.

@@ -332,7 +332,7 @@ public function login($email, $password, $show_confirmation = 1)
$func->log_event(t('Login fehlgeschlagen. Email (%1) nicht verifiziert', $user['email']), "2", "Authentifikation");

// User login and wrong password?
} elseif ($user["user_login"] and$tmp_login_pass !=$user["password"]) {
} elseif ($user["user_login"] and!PasswordHash::verify($password,$user["password"])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the variable$tmp_login_pass still relevant?
In line 236, we still do md5 hashing, but continue to use the clear text password.

$hashProperties = self::getInfo($hash);
// rehashing needed if algorithm does not match or amount of iterations is different than system setting
// I was thinking about keeping higher iteration counts, but this would prevent any recovery from setting value too high by mistake
return ($hashProperties['hash'] != $systemConfig['hash']) || ($hashProperties['iterations'] != $systemConfig['iterations']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I login, i see
Screenshot 2024-06-10 at 21 09 09

@@ -8,8 +10,8 @@ function CheckClanPW($clanpw)
{
global $database;

$clan = $database->queryWithOnlyFirstRow("SELECT password FROM %prefix%clan WHERE clanid = ?", [$_GET['clanid']]);
if ($clan['password'] and $clan['password'] == md5($clanpw)) {
$clan = $db->qry_first("SELECT password FROM %prefix%clan WHERE clanid = %int%", $_GET['clanid']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this query changed?
This can't work, as the global variable$db is not present.

My suggestion: Using the old database query code here

Suggested change
$clan =$db->qry_first("SELECT password FROM %prefix%clan WHERE clanid =%int%",$_GET['clanid']);
$clan =$database->queryWithOnlyFirstRow("SELECT password FROM %prefix%clan WHERE clanid =?",[$_GET['clanid']]);

<entries>
<entry>
<value>default</value>
<description>Standard</description>
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is "Standard"?
Should we write "Standard (Algo)"?

Comment on lines +32 to +33
case 'md5':
return md5($password);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the rational still supporting md5?

protected function setUp() : void
{
$GLOBALS['cfg'] = [];
error_reporting(E_ALL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
error_reporting(E_ALL);

PHPUnit has its own error handling and we should use this:https://docs.phpunit.de/en/11.2/error-handling.html


protected function setUp() : void
{
$GLOBALS['cfg'] = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets try to avoid globals in unit tests at all.
If this is needed, we should work on a bit of a refactoring.

error_reporting(E_ALL);

// the following test hashes will be used for all functions and tests, thus defined once and shared globally
$GLOBALS['hashTestArray'] =
Copy link
Collaborator

Choose a reason for hiding this comment

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

/*
* @covers PasswordHash::hash

public function testHash()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this dead code and can be removed?

Co-authored-by: Andy Grunwald <andygrunwald@gmail.com>
@sonarqubecloudSonarQubeCloud
Copy link

Quality Gate FailedQuality Gate failed

Failed conditions
3 Security Hotspots
6.6% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extensionSonarLint

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@andygrunwaldandygrunwaldandygrunwald requested changes

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@M4LuZ@andygrunwald@lxp@t-h-e

[8]ページ先頭

©2009-2025 Movatter.jp