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#
- 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_passwordfor the MySQL dialect,mysql_native_passwordfor MariaDB). - 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.
- 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)). - If the client used a plugin the server does not speak (anything but
caching_sha2_passwordandmysql_native_password), or usedcaching_sha2_passwordfor an account that has no SHA-256 hash, the server sends an authentication switch tomysql_native_passwordwith a fresh nonce, and the client answers again. - The scramble is checked. A wrong one is error 1045.
- For
caching_sha2_passwordthe 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:
| Plugin | Value | Check |
|---|---|---|
mysql_native_password | SHA1(SHA1(password)) | SHA1(password) XOR SHA1(nonce + SHA1(SHA1(password))) from the client |
caching_sha2_password | SHA256(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 dialect | MariaDB dialect | |
|---|---|---|
| Offered first | caching_sha2_password | mysql_native_password |
Handshake capability bit CLIENT_MYSQL | set | cleared, so MariaDB connectors treat the server as MariaDB |
MariaDB-only plugins (ed25519, parsec, gssapi) | n/a | not offered |
| Client wants TLS | not offered | the MariaDB 11.4 command-line client needs --skip-ssl |
Remarks#
- The
SSLcapability 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_passwordis SHA-1 based. Prefercaching_sha2_passwordwhere the client supports it (the MySQL dialect offers it first).