MySQL 9.6.0
Source Code Documentation
mysql_native_password.cc File Reference
#include <openssl/evp.h>
#include "my_dbug.h"
#include "my_ssl_algo_cache.h"
#include "my_sys.h"
#include "sql_common.h"

Macros

#define MYSQL_NATIVE_PASSWORD_PLUGIN_NAME   "mysql_native_password"
 
#define SHA1_HASH_SIZE   20 /* Hash size in bytes */
 

Functions

static void my_crypt (char *to, const uchar *s1, const uchar *s2, uint len)
 
static void compute_sha1_hash (uint8 *digest, const char *buf, size_t len)
 Wrapper function to compute SHA1 message digest. More...
 
static void compute_sha1_hash_multi (uint8 *digest, const char *buf1, int len1, const char *buf2, int len2)
 Wrapper function to compute SHA1 message digest for two messages in order to emulate sha1(msg1, msg2). More...
 
void compute_two_stage_sha1_hash (const char *password, size_t pass_len, uint8 *hash_stage1, uint8 *hash_stage2)
 Compute two stage SHA1 hash of the password : More...
 
void scramble (char *to, const char *message, const char *password)
 Produce an obscure octet sequence from password and random string, received from the server. More...
 
static int native_password_auth_client (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
 Client authentication plugin that does native MySQL authentication using a 20-byte (4.1+) scramble. More...
 
 mysql_declare_client_plugin (AUTHENTICATION) MYSQL_NATIVE_PASSWORD_PLUGIN_NAME
 

Variables

 MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE
 
MySQL Native Authentication Client
 
MySQL Native Authentication GPL
 
MySQL Native Authentication nullptr
 
MySQL Native Authentication native_password_auth_client
 
MySQL Native Authentication mysql_end_client_plugin
 

Macro Definition Documentation

◆ MYSQL_NATIVE_PASSWORD_PLUGIN_NAME

#define MYSQL_NATIVE_PASSWORD_PLUGIN_NAME   "mysql_native_password"

◆ SHA1_HASH_SIZE

#define SHA1_HASH_SIZE   20 /* Hash size in bytes */

Function Documentation

◆ compute_sha1_hash()

static void compute_sha1_hash ( uint8 digest,
const char *  buf,
size_t  len 
)
static

Wrapper function to compute SHA1 message digest.

Parameters
[out]digestComputed SHA1 digest
[in]bufMessage to be computed
[in]lenLength of the message

◆ compute_sha1_hash_multi()

static void compute_sha1_hash_multi ( uint8 digest,
const char *  buf1,
int  len1,
const char *  buf2,
int  len2 
)
static

Wrapper function to compute SHA1 message digest for two messages in order to emulate sha1(msg1, msg2).

Parameters
[out]digestComputed SHA1 digest
[in]buf1First message
[in]len1Length of first message
[in]buf2Second message
[in]len2Length of second message

◆ compute_two_stage_sha1_hash()

void compute_two_stage_sha1_hash ( const char *  password,
size_t  pass_len,
uint8 hash_stage1,
uint8 hash_stage2 
)
inline

Compute two stage SHA1 hash of the password :

hash_stage1=sha1("password") hash_stage2=sha1(hash_stage1)

Parameters
[in]passwordPassword string.
[in]pass_lenLength of the password.
[out]hash_stage1sha1(password)
[out]hash_stage2sha1(hash_stage1)

◆ my_crypt()

static void my_crypt ( char *  to,
const uchar s1,
const uchar s2,
uint  len 
)
static

◆ mysql_declare_client_plugin()

mysql_declare_client_plugin ( AUTHENTICATION  )

◆ native_password_auth_client()

static int native_password_auth_client ( MYSQL_PLUGIN_VIO vio,
MYSQL mysql 
)
static

Client authentication plugin that does native MySQL authentication using a 20-byte (4.1+) scramble.

Parameters
viothe channel to operate on
mysqlthe MYSQL structure to operate on
Return values
-1CR_OK : Success
1CR_ERROR : error reading
2012CR_SERVER_HANDSHAKE_ERR : malformed handshake data

◆ scramble()

void scramble ( char *  to,
const char *  message,
const char *  password 
)

Produce an obscure octet sequence from password and random string, received from the server.

This sequence corresponds to the password, but password can not be easily restored from it. The sequence is then sent to the server for validation. Trailing zero is not stored in the buf as it is not needed. This function is used by client to create authenticated reply to the server's greeting.

Parameters
[out]tostore scrambled string here. The buf must be at least SHA1_HASH_SIZE bytes long.
messagerandom message, must be exactly SCRAMBLE_LENGTH long and NULL-terminated.
passwordusers' password, NULL-terminated

Variable Documentation

◆ Client

MySQL Native Authentication Client

◆ GPL

MySQL Native Authentication GPL

◆ MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE

MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE

◆ mysql_end_client_plugin

MySQL Native Authentication mysql_end_client_plugin

◆ native_password_auth_client

MySQL Native Authentication native_password_auth_client

◆ nullptr

MySQL Native Authentication nullptr