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 GH-11438: mysqlnd fails to authenticate with sha256_password accounts using passwords longer than 19 characters #11445

Closed
wants to merge 3 commits into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Jun 12, 2023

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
Copy link
Member

@kamil-tekiela kamil-tekiela left a comment

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.

ext/mysqli/tests/gh11438.phpt Outdated Show resolved Hide resolved
ext/mysqli/tests/gh11438.phpt Outdated Show resolved Hide resolved
ext/mysqli/tests/gh11438.phpt Outdated Show resolved Hide resolved
ext/mysqli/tests/gh11438.phpt Outdated Show resolved Hide resolved
@kamil-tekiela
Copy link
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.

@nielsdos
Copy link
Member Author

nielsdos commented Aug 3, 2023

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).

Copy link
Member

@kamil-tekiela kamil-tekiela left a comment

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.

@nielsdos nielsdos closed this in 509906b Aug 3, 2023
jorgsowa pushed a commit to jorgsowa/php-src that referenced this pull request Aug 16, 2023
…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

Closes phpGH-11445.

Co-authored-by: Kamil Tekiela <[email protected]>
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