All pages
Powered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

Connecting via sha256_password

The sha256_password plugin manages authentication using SHA-256 encryption, supporting both clear text passwords over SSL and RSA encrypted password exchange.

Overview

SHA256 authentication possible exchanges:

  • if connection use SSL (SSLRequest Packet sent):

    • Client sends a .

  • Else:

    • If client doesn't know server RSA public key:

      • Client sends a .

      • Server sends a .

Authentication

Client Clear Password Answer

  • password without encryption.

Public key request

  • fixed 0x01 value.

Public key response

  • fixed 0x01 value.

  • public key data.

RSA encrypted password

  • RSA encrypted password.

RSA encrypted value of XOR(password, seed) using server public key (RSA_PKCS1_OAEP_PADDING).

This page is licensed: CC BY-SA / Gnu FDL

Client sends an RSA encrypted password.

  • Ends with server sending either OK_Packet , ERR_Packet.

  • clear password answer
    public key request
    public key response
    string
    byte<1>
    byte<1>
    byte
    byte<256>

    1 - Connecting

    Learn about the connection phase in the client/server protocol. This section details how clients establish initial communication with the server, including handshaking and authentication processes.

    ConnectingConnecting via caching_sha2_passwordConnecting via sha256_password

    Connecting via caching_sha2_password

    This plugin implements the caching_sha2_password authentication method, using an in-memory cache for fast authentication or RSA encryption for full verification.

    Overview

    Caching SHA256 first sends an SHA256-encrypted password. MySQL server has an in-memory cache of SHA256 key for successful authentication. When a cache hit occurs, the connection is validated, if not, using some more steps to a process similar to sha256_password.

    Caching SHA256 authentication possible exchanges:

    • Client sends an .

    • Server result is either , or .

    • If fast authentication result:

      • If connection uses SSL ( Packet sent):

        • Client sends a .

      • Else:

    Authentication

    SHA-2 encrypted password

    Encryption is XOR(SHA256(password), SHA256(seed, SHA256(SHA256(password)))).

    • encrypted password.

    "fast" authentication result

    Result of fast authentication.

    • authentication result.

    0x03 value means success authentication. 0x04 value means continue.

    Client clear password answer

    • password without encryption.

    Public key request

    Value send is not 0x01 like sha256_password use, but 0x02.

    • fixed 0x02 value.

    Public key response

    • fixed 0x01 value.

    • public key data.

    RSA encrypted password

    • RSA encrypted password.

    RSA encrypted value of XOR(password, seed) using server public key (RSA_PKCS1_OAEP_PADDING).

    This page is licensed: CC BY-SA / Gnu FDL

    If client doesn't know server RSA public key:

    • Client sends a public key request.

    • Server sends a public key response.

  • Client sends an RSA encrypted password.

  • Ends with server sending either OK_Packet , ERR_Packet.

  • SHA-2 encrypted password
    OK_Packet
    ERR_Packet
    "fast" authentication result
    SSLRequest
    clear password answer
    byte<32>
    byte
    string
    byte<1>
    byte<1>
    byte
    byte<256>

    Connecting

    The connection phase involves an initial handshake where the client and server exchange capabilities, default settings, and authentication data to establish a session.

    Overview

    Connection is done by many exchanges:

    • (Create socket)

    • If first byte from server is 0xFF:

      • Packet is an , socket has to be closed.

    • Else:

      • Packet is an .

      • If SSL/TLS connection:

        • Client sends and switches to SSL mode for sending and receiving the following messages:

    Initial Handshake Packet

    • protocol version.

    • server version

      • MariaDB Server 10.X versions are by default prefixed "5.5.5-".

      • and later versions do not have a "5.5.5-" default prefix.

    Client Handshake Response

    If the client requests a TLS/SSL connection, the first response is an SSL connection request packet, followed by a handshake response packet. If no TLS is required, client directly sends a handshake response packet.

    SSLRequest Packet

    • client capabilities.

    • max packet size.

    • client's default character set and collation.

    • reserved.

    Zero-Configuration SSL Encryption

    Automatic Encrypted Connections (+):

    Previously, failed SSL connections due to self-signed certificates prevented communication. + introduces a secondary validation method that works for all servers.

    What Happens When SSL Validation Fails?

    Even without a valid SSL certificate, the connector can still authenticate by remembering the server's fingerprint (unique identifier). However, it needs to confirm the connection is secure.

    Verifying a Secure Connection:

    The confirmation method depends on the connection type. When using secure MitM-proof methods, like Unix sockets, connector can automatically validate the connection. Otherwise, a shared secret is used.

    Shared Secret for Secure Connection:

    The shared secret is only used if the authentication plugin password is hashable (for instance, mysql_native_password , client_ed25519, or parsec) and not empty.

    It's calculated by hashing the user's hash password with the authentication seed and the server fingerprint.

    Password hash is generated depending on authentication plugin:

    • ed25519 : identical to password encryption.

    • mysql_native_password : identical to password encryption.

    • parsec: ext-salt + raw ed25519 public key.

    Server 11.4+ Confirmation Details:

    For servers running or later, the final confirmation packet contains:

    • encryption (actually only 0x01 = SHA256 encryption)

    • shared secret.

    Matching the Shared Secret

    If the calculated shared secret matches the received one, the SSL connection is considered valid (host validation is not needed). Otherwise, the connection must be closed for security reasons.

    Handshake Response Packet

    • client capabilities.

    • max packet size.

    • client's default character set and collation.

    • reserved.

    Server Response to Handshake Response Packet

    If the authentication plugin needs further rounds of data exchange (like parsec), the server sends additional plugin authentication data (optionally prefixed with 0x01) to which the client sends an additional response. This can be repeated in multiple rounds. It ends with one of the following:

    The server responds with an , an , or an Authentication Switch Request packet.

    Authentication Switch Request

    (If client and server support CLIENT_AUTH capability):

    • 0xFE : Authentication switch request header.

    • authentication plugin name.

    • authentication plugin data.

    Plugin List

    mysql_old_password Plugin

    deprecated — send an 8 byte encrypted password.

    Authentication plugin data format:

    • 8-byte seed.

    Client response:

    • old format encrypted password.

    mysql_clear_password Plugin

    Since password is transmitted in clear, this has been used only when using SSL connection

    Send clear password to server.

    Client response:

    • password without encryption.

    mysql_native_password Plugin

    SHA-1 encrypted password with server seed.

    Authentication plugin data format:

    • seed.

    Client response:

    • SHA1-encrypted password.

    The password is encrypted with: SHA1( password ) ^ SHA1( seed + SHA1( SHA1( password ) ) ) .

    dialog Plugin (PAM)

    Interactive exchanges to permit fill passwords — for example for 2-step authentication.

    Authentication plugin data format:

    • password type.

    • prompt message.

    The server can send one or many requests. For each of them, the client must display this prompt message to the user, to permit the user to type requested information, then send it to the server in format. Password type indicates the answer format (2 means "read the input with the echo enabled", 4 means "password-like input, echo disabled")

    First authentication format (from authentication switch packet) can be empty.

    This end when the server sends an , or .

    auth_gssapi_client Plugin

    GSSAPI implementation.

    Authentication plugin data format:

    • serverPrincipalName (UTF-8 format).

    • mechanisms (UTF-8 format).

    Client must exchange packet with server until having a mutual authentication. The only difference compared to standard client-server GSSAPI authentication is that exchanges contain standard protocol with packet headers.

    client_ed25519 Plugin

    The ed25519 plugin uses the Elliptic Curve Digital Signature Algorithm to securely store users' passwords and to authenticate users.

    See .

    The server sends a random nonce that the client signs.

    authentication plugin data format:

    • seed.

    Client response:

    • ed25519 encrypted password.

    parsec Plugin

    Authentication plugin data format:

    • server nonce.

    Client has to send an empty packet to request "ext-salt".

    Format of ext-salt is:

    • 'P' (denotes KDF algorithm = PBKDF2).

    • iteration factor. number of iterations correspond to 1024 << iteration factor (0x0 means 1024, 0x1 means 2048, etc.).

    • salt.

    The client must then:

    • Generate derived key = hash password with PBKDF2 (sha512 digest) with iteration number and salt from ext-salt.

    • Generate a client 32 bytes nonce.

    • Generate the signature with ed25519 of an array concatenation of server nonce + client nonce with the generated derived key as private key.

    Client response:

    • client nonce.

    • signature.

    Capabilities

    Server and Client have different capabilities, here is the possibles values. client with capabilities CLIENT_MYSQL + CONNECT_WITH_DB will have a value of 9 (1 + 8).

    Capability
    Value
    Details

    Native Password Authentication

    The 20-byte string 'seed' is calculated by concatenating scramble first part (8 bytes) and scramble second part from . After that, the client calculates a password hash using the password and seed by using ^ (bitwise xor), + (string concatenation) and SHA1 as follows:

    This page is licensed: CC BY-SA / Gnu FDL

    Client sends Handshake response packet.

  • Server sends either:

    • An OK packet in case of success OK_Packet.

    • An error packet in case of error ERR_Packet.

    • Further authentication data, if requested by the authentication plugin.

      • The content of this authentication data is defined by the authentication plugin.

      • The server may send 0x01 byte first to escape the authentication data, particularly if the data starts with the 0x00 or 0xFE or 0XFF byte.

      • This optional first 0x01 byte must always be skipped by the client.

    • Authentication switch:

      • If the client or server doesn't have PLUGIN_AUTH capability:

        • Server sends 0xFE byte.

  • int<4> connection id.

  • string<8> authentication plugin data (1st part).

  • string<1> reserved byte.

  • int<2> server capabilities (1st part).

  • int<1> server default collation.

  • int<2> status flags.

  • int<2> server capabilities (2nd part).

  • If (server_capabilities & PLUGIN_AUTH):

    • int<1> plugin data length.

  • Else:

    • int<1> 0x00.

  • string<6> filler.

  • If (server_capabilities & CLIENT_MYSQL):

    • string<4> filler.

  • Else:

    • int<4> server capabilities 3rd part. MariaDB specific flags /* or later */.

  • If (server_capabilities & CLIENT_SECURE_CONNECTION):

    • string authentication plugin data 2nd part. Length = max(12, plugin data length - 9).

    • string<1> reserved byte.

  • If (server_capabilities & PLUGIN_AUTH):

    • string authentication plugin name.

  • If not (server_capabilities & CLIENT_MYSQL):

    • int<4> extended client capabilities

  • Else:

    • string<4> reserved.

  • If not (server_capabilities & CLIENT_MYSQL):

    • int<4> extended client capabilities.

  • Else:

    • string<4> reserved.

  • string username.

  • If (password):

    • If (server_capabilities & PLUGIN_AUTH_LENENC_CLIENT_DATA):

      • string authentication data.

    • Else if (server_capabilities & CLIENT_SECURE_CONNECTION):

      • length of authentication response.

      • authentication response (length is indicated by previous field).

    • Else:

      • authentication response null ended.

  • Else:

    • string<1>\0 (empty password).

  • If (server_capabilities & CLIENT_CONNECT_WITH_DB):

    • string default database name.

  • If (server_capabilities & CLIENT_PLUGIN_AUTH):

    • string authentication plugin name.

  • If (server_capabilities & CLIENT_CONNECT_ATTRS):

    • int size of connection attributes.

    • While packet has remaining data:

      • key.

      • value.

  • LOCAL_FILES

    128

    Can use .

    IGNORE_SPACE

    256

    Ignore spaces before (.

    CLIENT_PROTOCOL_41

    1 << 9

    4.1 protocol.

    CLIENT_INTERACTIVE

    1 << 10

    SSL

    1 << 11

    Can use SSL.

    TRANSACTIONS

    1 << 13

    SECURE_CONNECTION

    1 << 15

    4.1 authentication.

    MULTI_STATEMENTS

    1 << 16

    Enable/disable multi-statement support.

    MULTI_RESULTS

    1 << 17

    Enable/disable multi-results.

    PS_MULTI_RESULTS

    1 << 18

    Enable/disable multi-results for PrepareStatement.

    PLUGIN_AUTH

    1 << 19

    Client supports plugin authentication.

    CONNECT_ATTRS

    1 << 20

    Client sends connection attributes.

    PLUGIN_AUTH_LENENC_CLIENT_DATA

    1 << 21

    Enable authentication response packet to be larger than 255 bytes.

    CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS

    1 << 22

    Client can handle expired passwords.

    CLIENT_SESSION_TRACK

    1 << 23

    Enable/disable session tracking in OK_Packet.

    CLIENT_DEPRECATE_EOF

    1 << 24

    EOF_Packet deprecation: OK_Packet replace EOF_Packet at the end of the result set when in text format. EOF_Packet between columns definition and resultsetRows is deleted.

    CLIENT_OPTIONAL_RESULTSET_METADATA

    1 << 25

    Not in use for MariaDB.

    CLIENT_ZSTD_COMPRESSION_ALGORITHM

    1 << 26

    Support zstd protocol compression.

    CLIENT_CAPABILITY_EXTENSION

    1 << 29

    Reserved for future use.

    CLIENT_SSL_VERIFY_SERVER_CERT

    1 << 30

    Client verify server certificate. Deprecated, client has options to indicate if server certificate must be verified.

    CLIENT_REMEMBER_OPTIONS

    1 << 31

    MARIADB_CLIENT_PROGRESS

    1 << 32

    Client support progress indicator.

    MARIADB_CLIENT_COM_MULTI

    1 << 33

    Permit COM_MULTI protocol.

    MARIADB_CLIENT_STMT_BULK_OPERATIONS

    1 << 34

    Permit bulk insert.

    MARIADB_CLIENT_EXTENDED_METADATA

    1 << 35

    Add extended metadata information.

    MARIADB_CLIENT_CACHE_METADATA

    1 << 36

    Permit skipping metadata.

    MARIADB_CLIENT_BULK_UNIT_RESULTS

    1 << 37

    When enabled, indicate that bulk command can use STMT_BULK_FLAG_SEND_UNIT_RESULTS flag that permits to return a result set of all affected rows and auto-increment values.

    CLIENT_MYSQL

    1

    Set by older MariaDB versions. MySQL named this CLIENT_LONG_PASSWORD.

    FOUND_ROWS

    2

    CONNECT_WITH_DB

    8

    You can specify database on connect.

    COMPRESS

    32

    Can use compression protocol

    ERR_Packet
    Initial handshake packet
    SSLRequest packet
    int<1>
    string
    int<4>
    int<4>
    int<1>
    string<19>
    int<1>
    byte
    int<4>
    int<4>
    int<1>
    string<19>
    OK_packet
    ERR_packet
    int<1>
    string
    byte
    byte<8>
    string
    string
    string
    byte
    byte<1>
    string
    string
    EOF_Packet
    OK_Packet
    ERROR_packet
    string
    string
    GSSAPI
    plugin description
    byte
    byte
    string<32>
    string<1>
    byte<1>
    byte
    byte<32>
    byte<64>
    Initial handshake packet
    SHA1( passwd) ^ SHA1( seed + SHA1( SHA1( passwd ) ) )
    Client sends old_password.
  • Else:

    • Server sends Authentication switch request.

    • Client may have many exchanges with the server according to the Plugin.

  • Authentication switch ends with server sending either OK_Packet or ERR_Packet.

  • int<1>
    string
    string
    string
    string
    LOAD DATA LOCAL
    MariaDB 11.0
    MariaDB 11.4
    MariaDB 11.4
    MariaDB 11.4
    MariaDB 10.2