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