Security

Authentication plugins

How the handshake and the two password plugins work in raftdb-mysql, why no TLS or RSA exchange is needed, and what the MariaDB dialect changes.

raftdb-mysql implements the two password plugins that MySQL and MariaDB clients use. The code for SHA-1, SHA-256 and the nonce is separate from the code for the handshake.

The handshake#

  1. The server sends a handshake with its version string, a connection id, a random 20-byte nonce and the plugin it offers first (caching_sha2_password for the MySQL dialect, mysql_native_password for MariaDB).
  2. The client answers with its user name, the plugin it used and a scramble: a value computed from the password and the nonce. The password itself is never sent.
  3. The server finds the account: first a bootstrap administrator of the configuration, then a stored account matched by host. No such account is error 1045 (Login refused for user ... (password supplied: YES|NO)).
  4. If the client used a plugin the server does not speak (anything but caching_sha2_password and mysql_native_password), or used caching_sha2_password for an account that has no SHA-256 hash, the server sends an authentication switch to mysql_native_password with a fresh nonce, and the client answers again.
  5. The scramble is checked. A wrong one is error 1045.
  6. For caching_sha2_password the server sends the "fast authentication succeeded" marker (0x01 0x03) before the OK packet.

A client has 10 seconds to complete the login.

What the server keeps to check a scramble#

Both plugins prove knowledge of the password without sending it, so the server needs a derived value, not the password's slow hash. The front-end derives and keeps:

PluginValueCheck
mysql_native_passwordSHA1(SHA1(password))SHA1(password) XOR SHA1(nonce + SHA1(SHA1(password))) from the client
caching_sha2_passwordSHA256(SHA256(password))SHA256(password) XOR SHA256(SHA256(SHA256(password)) + nonce) from the client

Bootstrap administrators' passwords are in the configuration file (the verifier is derived at start). Stored accounts keep both double hashes in the hidden account table. This is the same information a MySQL server keeps in mysql.user: anyone who can read the account table can impersonate the account in a login (a "pass-the-hash" risk of both plugins), though not recover the password directly from a SHA-256 double hash without a guess.

A Raft DB account of raftdb-server cannot be checked from a MySQL scramble, because Raft DB keeps only a slow PBKDF2 hash. That is why the MySQL users are the front-end's own.

Why no TLS or RSA is needed#

MySQL's caching_sha2_password normally ends in a "full authentication" over TLS or an RSA key exchange when the server has not cached the client's password hash. Here the front-end always holds the verifier, so every login succeeds on the fast path and the full path never occurs. The price: there is no TLS, so everything after the login is in clear text (TLS and encryption).

Dialects#

MySQL dialectMariaDB dialect
Offered firstcaching_sha2_passwordmysql_native_password
Handshake capability bit CLIENT_MYSQLsetcleared, so MariaDB connectors treat the server as MariaDB
MariaDB-only plugins (ed25519, parsec, gssapi)n/anot offered
Client wants TLSnot offeredthe MariaDB 11.4 command-line client needs --skip-ssl

Remarks#

  • The SSL capability is not offered in the handshake; a client set to require TLS cannot connect.
  • No delay is added after a failed login and nothing counts failures: guessing is limited only by the network and CPU. Limit who can reach listen.
  • mysql_native_password is SHA-1 based. Prefer caching_sha2_password where the client supports it (the MySQL dialect offers it first).

See also#