Skip to content

Add caching_sha2_password authentication support#72

Merged
jappeace merged 1 commit intowinterland1989:masterfrom
jappeace-sloth:caching-sha2-password-support
Mar 7, 2026
Merged

Add caching_sha2_password authentication support#72
jappeace merged 1 commit intowinterland1989:masterfrom
jappeace-sloth:caching-sha2-password-support

Conversation

@jappeace-sloth
Copy link
Copy Markdown

@jappeace-sloth jappeace-sloth commented Mar 7, 2026

Summary

MySQL 8.0+ defaults to caching_sha2_password instead of mysql_native_password. This PR adds support for connecting to MySQL 8.0+ servers using the default authentication plugin.

Changes:

  • SHA256 scramble for caching_sha2_password fast auth path
  • AuthMoreData (0x01) handling for fast auth success / full auth request
  • AuthSwitchRequest (0xFE) handling when the server switches auth plugins (e.g., user configured with mysql_native_password on a server defaulting to caching_sha2_password)
  • TLS full auth — sends cleartext password over encrypted connection when fast auth cache miss occurs
  • CLIENT_PLUGIN_AUTH capability flag and plugin name serialization in Auth packet
  • Plain TCP connections throw an informative AuthException when full auth is required (RSA not yet implemented)
  • Portable password change test — uses ALTER USER syntax (works on both MariaDB and MySQL 8.0; SET PASSWORD = PASSWORD(...) was removed in MySQL 8.0)
  • MySQL 8.0 SELECT 1 compat — accepts both MySQLInt32 and MySQLInt64 (MySQL 8.0 returns 64-bit for integer literals)

Test plan

The same integration binary runs on both MariaDB and MySQL 8.0. The caching_sha2_password tests are conditionally included when the server version starts with 8. or 9..

  • nix-build nix/ci.nix -A build — compiles cleanly
  • nix-build nix/ci.nix -A integrated-checks — MariaDB: all 4 tests passed
  • nix-build nix/ci.nix -A integrated-checks-mysql80 — MySQL 8.0: all 6 tests passed
    • SelectOne, RoundtripBit, RoundtripYear, MysqlTests (with password change), SHA256 fast auth, AuthSwitchRequest

Closes #65

🤖 Generated with Claude Code

@jappeace-sloth jappeace-sloth force-pushed the caching-sha2-password-support branch from 8c475a3 to 06cf8e6 Compare March 7, 2026 19:19
@jappeace-sloth jappeace-sloth changed the title Support caching_sha2_password auth and fix MySQL 8.0 / MariaDB 11.4 compat Add caching_sha2_password authentication support Mar 7, 2026
@jappeace-sloth jappeace-sloth force-pushed the caching-sha2-password-support branch from 06cf8e6 to a36bdf2 Compare March 7, 2026 19:29
…9#65)

MySQL 8.0+ defaults to caching_sha2_password instead of mysql_native_password.
This adds support for:
- SHA256 scramble for caching_sha2_password fast auth path
- AuthMoreData (0x01) handling for fast auth success / full auth request
- AuthSwitchRequest (0xFE) handling when server switches auth plugin
- TLS full auth (cleartext password over encrypted connection)
- CLIENT_PLUGIN_AUTH capability flag and plugin name in Auth packet

Plain TCP connections throw an informative AuthException when full auth
is required (RSA not yet implemented). Use TLS or ensure the password
verifier is cached (fast auth path).

Tested against both MariaDB 11.x and MySQL 8.0 in NixOS VM integration
tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jappeace-sloth jappeace-sloth force-pushed the caching-sha2-password-support branch from a36bdf2 to d089c8c Compare March 7, 2026 20:20
@jappeace jappeace merged commit fff5885 into winterland1989:master Mar 7, 2026
13 checks passed
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.

Support for the caching_sha2_password authentication protocol.

2 participants