Skip to content

Fix GH-11438: mysqlnd fails to authenticate with sha256_password accounts using passwords longer than 19 characters - #11445

Closed
ndossche wants to merge 3 commits into
php:PHP-8.1from
ndossche:fix-11438
Closed

ndossche wants to merge 3 commits into
php:PHP-8.1from
ndossche:fix-11438

Conversation

@ndossche

@ndossche ndossche commented Jun 12, 2023 •

Copy link
Copy Markdown
Member

https://dev.mysql.com/doc/dev/mysql-server/latest/page_caching_sha2_authentication_exchanges.html tells us that the nonce used in this authentication method is 20 bytes long. However, we might receive additional scramble data in php_mysqlnd_greet_read not used in this method.
On my test setup, I received 21 bytes (20 bytes + '\0'). This resulted in the xor computation to incorrectly include the NUL byte. Every password of at least 20 characters therefore failed to authenticate using this method.

Looking at mysql-server source code also seems to reveal that it always uses a fixed number of scramble bytes [1].

[1] https://github.com/mysql/mysql-server/blob/ea7087d885006918ad54458e7aad215b1650312c/sql/auth/sha2_password.cc#L1078-L1079

I'm a mysqlnd noob, so someone should triple check this please.

…ccounts using passwords longer than 19 characters

https://dev.mysql.com/doc/dev/mysql-server/latest/page_caching_sha2_authentication_exchanges.html
tells us that the nonce used in this authentication method is 20 bytes
long. However, we might receive additional scramble data in
php_mysqlnd_greet_read not used in this method.
On my test setup, I received 21 bytes (20 bytes + '\0'). This resulted
in the xor computation to incorrectly include the NUL byte. Every
password of at least 20 characters therefore failed to authenticate
using this method.

Looking at mysql-server source code also seems to reveal that it always
uses a fixed number of scramble bytes [1].

[1] https://github.com/mysql/mysql-server/blob/ea7087d885006918ad54458e7aad215b1650312c/sql/auth/sha2_password.cc#L1078-L1079

@kamil-tekiela kamil-tekiela left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the right solution, but please add a test for it. You can add it in mysqli or PDO_mysql. You can copy the /ext/mysqli/tests/mysqli_pam_sha256_public_key_ini.phpt test or similar, but with >20 char long password.

Comment thread ext/mysqli/tests/gh11438.phpt Outdated
Comment thread ext/mysqli/tests/gh11438.phpt Outdated
Comment thread ext/mysqli/tests/gh11438.phpt Outdated
Comment thread ext/mysqli/tests/gh11438.phpt Outdated
Comment thread ext/mysqli/tests/gh11438.phpt
@kamil-tekiela

Copy link
Copy Markdown
Member

I think I got it. So sorry again, but I think I misled you and myself by pointing at a very weird test that is either completely nonsense or tests some obscure feature. Anyway, I trimmed it down to the actual bug fix and now the test works. You can verify with your fix it is green, and without is red. Hopefully CI agrees.

@ndossche

ndossche commented Aug 3, 2023

Copy link
Copy Markdown
Member Author

Alright, thanks for taking care of the test.
Looks like CI passed. FreeBSD failed due to an unrelated intl failure (that is fixed in the current development branches, but I hadn't rebased my branch yet, hence it shows up here).

@kamil-tekiela kamil-tekiela left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! You can merge it.

@ndossche ndossche closed this in 509906b Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mysqlnd fails to authenticate with sha256_password accounts using passwords longer than 19 characters.

2 participants