Skip to content

IllegalStateException "AuthMoreDataMessage is only supported for 'caching_sha2_password' method" when the handshake plugin differs from the account's plugin #441

Closed

Description

@kibo-andynunes

Summary

When the server's default authentication plugin differs from the account's plugin, jasync-sql fails every new connection while the server's caching_sha2_password cache is cold, with:

java.lang.IllegalStateException: AuthMoreDataMessage is only supported for 'caching_sha2_password' method
    at com.github.jasync.sql.db.mysql.MySQLConnection.onAuthMoreData(MySQLConnection.kt)

This is independent of sslMode (it fails the same with Disable and Prefer).

Cause

MySQLConnection stores authenticationMethod and authenticationSeed from the initial handshake only. If the handshake advertises mysql_native_password but the account uses caching_sha2_password, the server answers the handshake response with an authentication switch request. switchAuthentication() replies to it but doesn't record the plugin and seed it carries, so the AuthMoreData(0x04) ("full authentication required") that follows on a cold cache is checked against the stale handshake plugin and rejected. Even with that check fixed, the RSA path would scramble the password with the stale handshake seed.

When the server's cache is warm, the server sends AuthMoreData(0x03), which is accepted without looking at the plugin, so the problem only shows after a restart, FLUSH PRIVILEGES, ALTER USER, etc.

Reproduction (jasync-sql 2.2.4, and master)

docker run -d --name mysql-repro -e MYSQL_ROOT_PASSWORD=rootpw -p 33306:3306 \
  mysql:8.0.32 --default-authentication-plugin=mysql_native_password
# once it is up:
docker exec mysql-repro mysql -uroot -prootpw -e "
  CREATE DATABASE test;
  CREATE USER 'u'@'%' IDENTIFIED WITH caching_sha2_password BY 'pw';
  GRANT ALL ON *.* TO 'u'@'%';
  FLUSH PRIVILEGES;"

Then connect with Configuration("u", "127.0.0.1", 33306, "pw", "test", SSLConfiguration(Mode.Prefer)) (or Mode.Disable): the connection fails with the exception above. After one successful login by another client (e.g. mysql -uu -ppw --ssl-mode=REQUIRED) the cache is warm and the same configuration connects. The same server advertising caching_sha2_password in the handshake (the default) works, so this only affects servers whose default plugin is not caching_sha2_password, e.g. managed MySQL 8.0 services or servers started with --default-authentication-plugin=mysql_native_password.

Fix

Pull request: #440 (records the plugin and seed from the switch request, with tests against a real server and an in-process fake server).

Activity

  1. github-actions commented on Nov 4, 2026

    @github-actions

    Thank you for reporting an issue. See the wiki for documentation and gitter for questions.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions