MySQL 8.4.3
Source Code Documentation
client_async_authentication.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23#ifndef SQL_COMMON_CLIENT_ASYNC_AUTHENTICATION_H
24#define SQL_COMMON_CLIENT_ASYNC_AUTHENTICATION_H
25
26#define MAX_CIPHER_LENGTH 1024
27
28#include <openssl/ossl_typ.h>
29#include <openssl/pem.h>
30#include <openssl/rsa.h>
31
32#include "my_inttypes.h"
33#include "mysql/client_plugin.h"
35#include "mysql_async.h"
36#include "mysql_com.h"
37
38/* this is a "superset" of MYSQL_PLUGIN_VIO, in C++ I use inheritance */
39struct MCPVIO_EXT {
41 int (*write_packet)(MYSQL_PLUGIN_VIO *vio, const uchar *pkt, int pkt_len);
44 unsigned char **buf, int *result);
46 const unsigned char *pkt,
47 int pkt_len, int *result);
48
49 /* -= end of MYSQL_PLUGIN_VIO =- */
51 auth_plugin_t *plugin; /**< what plugin we're under */
52 const char *db;
53 struct {
54 uchar *pkt; /**< pointer into NET::buff */
55 uint pkt_len;
56 /** a flag indicating that pkt, pkt_len contain valid packet to be reused */
59 int packets_read, packets_written; /**< counters for send/received packets */
60 int mysql_change_user; /**< if it's mysql_change_user() */
61 int last_read_packet_len; /**< the length of the last *read* packet */
62};
63
64/* Our state machines have four simple return codes: */
66 STATE_MACHINE_FAILED, /* Completion with a failure. */
67 STATE_MACHINE_CONTINUE, /* Keep calling the state machine. */
68 STATE_MACHINE_WOULD_BLOCK, /* Needs to block to continue. */
69 STATE_MACHINE_DONE /* Completion with a success. */
70};
71
72/* state machine for native password autheintication API */
76};
77
84};
85
94};
95
96/* A state machine for authentication itself. */
97struct mysql_async_auth;
99
102#if OPENSSL_VERSION_NUMBER >= 0x30000000L
103 EVP_PKEY *public_key;
104#else /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
106#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
109};
110
114
115 char *data;
117 /** set to mysql_async_connect::scramble_plugin */
118 const char *data_plugin;
119 const char *db;
120
121 const char *auth_plugin_name;
125 int res;
126
129
130 /** Used by caching_sha256_password plugin */
134
136};
137
138/*
139 Connection is handled with a state machine. Each state is
140 represented by a function pointer (csm_function) which returns
141 a mysql_state_machine_status to indicate the state of the
142 connection.
143 This state machine has boundaries around network IO to allow
144 reuse between blocking and non-blocking clients.
145*/
148
149/*
150 define different states of an asynchronous SSL connection phase
151*/
156 SSL_NONE = 8103
158
159/*
160 Struct to track the state of a connection being established. Once
161 the connection is established, the context should be discarded and
162 relevant values copied out of it.
163*/
165 /* state for the overall connection process */
167 const char *host;
168 const char *user;
169 const char *passwd;
170 const char *db;
171 uint port;
172 const char *unix_socket;
175
181 /** The server sends the default plugin name in Protocol::HandshakeV10 */
182 const char *scramble_plugin;
185
186 /* context needed to establish asynchronous authentication */
188 /* state for running init_commands */
191
193 SSL *ssl;
194 /* state function that will be called next */
196};
197
198#endif /* SQL_COMMON_CLIENT_ASYNC_AUTHENTICATION_H */
client_auth_caching_sha2_password_plugin_status
Definition: client_async_authentication.h:86
@ CACHING_SHA2_REQUEST_PUBLIC_KEY
Definition: client_async_authentication.h:90
@ CACHING_SHA2_READ_PUBLIC_KEY
Definition: client_async_authentication.h:91
@ CACHING_SHA2_SEND_PLAIN_PASSWORD
Definition: client_async_authentication.h:93
@ CACHING_SHA2_SEND_ENCRYPTED_PASSWORD
Definition: client_async_authentication.h:92
@ CACHING_SHA2_READING_PASSWORD
Definition: client_async_authentication.h:87
@ CACHING_SHA2_CHALLENGE_RESPONSE
Definition: client_async_authentication.h:89
@ CACHING_SHA2_WRITING_RESPONSE
Definition: client_async_authentication.h:88
mysql_state_machine_status
Definition: client_async_authentication.h:65
@ STATE_MACHINE_FAILED
Definition: client_async_authentication.h:66
@ STATE_MACHINE_CONTINUE
Definition: client_async_authentication.h:67
@ STATE_MACHINE_DONE
Definition: client_async_authentication.h:69
@ STATE_MACHINE_WOULD_BLOCK
Definition: client_async_authentication.h:68
client_auth_native_password_plugin_status
Definition: client_async_authentication.h:73
@ NATIVE_READING_PASSWORD
Definition: client_async_authentication.h:74
@ NATIVE_WRITING_RESPONSE
Definition: client_async_authentication.h:75
client_auth_sha256_password_plugin_status
Definition: client_async_authentication.h:78
@ SHA256_REQUEST_PUBLIC_KEY
Definition: client_async_authentication.h:80
@ SHA256_SEND_ENCRYPTED_PASSWORD
Definition: client_async_authentication.h:82
@ SHA256_READING_PASSWORD
Definition: client_async_authentication.h:79
@ SHA256_READ_PUBLIC_KEY
Definition: client_async_authentication.h:81
@ SHA256_SEND_PLAIN_PASSWORD
Definition: client_async_authentication.h:83
#define MAX_CIPHER_LENGTH
Definition: client_async_authentication.h:26
mysql_state_machine_status(* csm_function)(mysql_async_connect *)
Definition: client_async_authentication.h:147
ssl_exchange_state
Definition: client_async_authentication.h:152
@ SSL_REQUEST
Definition: client_async_authentication.h:153
@ SSL_CONNECT
Definition: client_async_authentication.h:154
@ SSL_COMPLETE
Definition: client_async_authentication.h:155
@ SSL_NONE
Definition: client_async_authentication.h:156
mysql_state_machine_status(* authsm_function)(mysql_async_auth *)
Definition: client_async_authentication.h:98
MySQL Client Plugin API.
static char buf[MAX_BUF]
Definition: conf_to_src.cc:73
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
Declarations for asynchronous client communication.
Common definition between mysql server & client.
#define SCRAMBLE_LENGTH
Length of random string sent by server on handshake; this is also length of obfuscated password,...
Definition: mysql_com.h:128
#define NAME_LEN
Definition: mysql_com.h:67
#define USERNAME_LENGTH
Definition: mysql_com.h:69
struct result result
Definition: result.h:34
This file defines constants and data structures that are the same for both client- and server-side au...
net_async_status
Definition: plugin_auth_common.h:136
struct rsa_st RSA
Definition: sql_authentication.h:103
Definition: client_async_authentication.h:39
auth_plugin_t * plugin
what plugin we're under
Definition: client_async_authentication.h:51
uchar * pkt
pointer into NET::buff
Definition: client_async_authentication.h:54
int packets_read
Definition: client_async_authentication.h:59
void(* info)(MYSQL_PLUGIN_VIO *vio, MYSQL_PLUGIN_VIO_INFO *info)
Definition: client_async_authentication.h:42
net_async_status(* write_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *pkt, int pkt_len, int *result)
Definition: client_async_authentication.h:45
bool pkt_received
a flag indicating that pkt, pkt_len contain valid packet to be reused
Definition: client_async_authentication.h:57
const char * db
Definition: client_async_authentication.h:52
net_async_status(* read_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf, int *result)
Definition: client_async_authentication.h:43
uint pkt_len
Definition: client_async_authentication.h:55
MYSQL * mysql
Definition: client_async_authentication.h:50
struct MCPVIO_EXT::@34 cached_server_reply
int(* read_packet)(MYSQL_PLUGIN_VIO *vio, uchar **buf)
Definition: client_async_authentication.h:40
int(* write_packet)(MYSQL_PLUGIN_VIO *vio, const uchar *pkt, int pkt_len)
Definition: client_async_authentication.h:41
int last_read_packet_len
the length of the last read packet
Definition: client_async_authentication.h:61
int mysql_change_user
if it's mysql_change_user()
Definition: client_async_authentication.h:60
int packets_written
counters for send/received packets
Definition: client_async_authentication.h:59
Definition: plugin_auth_common.h:121
Provides plugin access to communication channel.
Definition: plugin_auth_common.h:146
Definition: mysql.h:300
Definition: client_plugin.h:123
Definition: client_async_authentication.h:111
bool non_blocking
Definition: client_async_authentication.h:113
const char * data_plugin
set to mysql_async_connect::scramble_plugin
Definition: client_async_authentication.h:118
sha2_async_auth sha2_auth
Definition: client_async_authentication.h:135
auth_plugin_t * auth_plugin
Definition: client_async_authentication.h:122
char * change_user_buff
Definition: client_async_authentication.h:127
int client_auth_plugin_state
Used by caching_sha256_password plugin.
Definition: client_async_authentication.h:131
MCPVIO_EXT mpvio
Definition: client_async_authentication.h:123
const char * auth_plugin_name
Definition: client_async_authentication.h:121
uint current_factor_index
Definition: client_async_authentication.h:133
MYSQL * mysql
Definition: client_async_authentication.h:112
char * data
Definition: client_async_authentication.h:115
authsm_function state_function
Definition: client_async_authentication.h:132
uint data_len
Definition: client_async_authentication.h:116
ulong pkt_length
Definition: client_async_authentication.h:124
int change_user_buff_len
Definition: client_async_authentication.h:128
const char * db
Definition: client_async_authentication.h:119
int res
Definition: client_async_authentication.h:125
Definition: client_async_authentication.h:164
const char * scramble_plugin
The server sends the default plugin name in Protocol::HandshakeV10.
Definition: client_async_authentication.h:182
char * scramble_data
Definition: client_async_authentication.h:180
char buff[NAME_LEN+USERNAME_LENGTH+100]
Definition: client_async_authentication.h:178
SSL * ssl
Definition: client_async_authentication.h:193
int scramble_data_len
Definition: client_async_authentication.h:179
csm_function state_function
Definition: client_async_authentication.h:195
ssl_exchange_state ssl_state
Definition: client_async_authentication.h:192
char ** current_init_command
Definition: client_async_authentication.h:190
MYSQL * mysql
Definition: client_async_authentication.h:166
char * host_info
Definition: client_async_authentication.h:177
ulong client_flag
Definition: client_async_authentication.h:173
uint port
Definition: client_async_authentication.h:171
struct mysql_async_auth * auth_context
Definition: client_async_authentication.h:187
bool scramble_buffer_allocated
Definition: client_async_authentication.h:184
bool non_blocking
Definition: client_async_authentication.h:174
ulong pkt_length
Definition: client_async_authentication.h:176
const char * user
Definition: client_async_authentication.h:168
bool saved_reconnect
Definition: client_async_authentication.h:189
const char * db
Definition: client_async_authentication.h:170
const char * passwd
Definition: client_async_authentication.h:169
const char * unix_socket
Definition: client_async_authentication.h:172
char * scramble_buffer
Definition: client_async_authentication.h:183
const char * host
Definition: client_async_authentication.h:167
Definition: client_async_authentication.h:100
int cipher_length
Definition: client_async_authentication.h:108
unsigned char encrypted_password[MAX_CIPHER_LENGTH]
Definition: client_async_authentication.h:101
unsigned char scramble_pkt[SCRAMBLE_LENGTH]
Definition: client_async_authentication.h:107
RSA * public_key
Definition: client_async_authentication.h:105