MySQL 8.0.40
Source Code Documentation
classic_greeting_forwarder.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_CLASSIC_GREETING_FORWARDER_INCLUDED
27#define ROUTING_CLASSIC_GREETING_FORWARDER_INCLUDED
28
30
31/**
32 * classic protocol handshake between client<->router and router<->server.
33 */
35 public:
36 /**
37 * construct a server::greeting processor.
38 *
39 * c->r : ...
40 * r->s: connect()
41 * r<-s: server::greeting
42 *
43 * a server greeting may be sent as part of the initial connection
44 * setup between client<->router<->server (in_handshake=true) or
45 * when router starts a connection on its own.
46 *
47 * If `in_handshake` is true, the ServerGreetor expects it can send:
48 *
49 * - server::AuthMethodSwitch and
50 * - server::Ok
51 *
52 * to the client connection.
53 *
54 * @param conn the connection the greeting will be transferred on.
55 * @param in_handshake true if the greeting is part of the initial
56 * handshake.
57 * @param on_error callback called on failure.
58 */
60 MysqlRoutingClassicConnectionBase *conn, bool in_handshake,
61 std::function<void(const classic_protocol::message::server::Error &)>
62 on_error)
63 : ForwardingProcessor(conn),
64 in_handshake_{in_handshake},
65 on_error_(std::move(on_error)) {}
66
67 /**
68 * stages of the handshake flow.
69 *
70 * - Client stages are on the client<->router side.
71 * - Server stages are on the router<->server side.
72 */
73 enum class Stage {
85 AuthOk,
87
89 Error,
90 Ok,
91 };
92
94
96 [[nodiscard]] Stage stage() const { return stage_; }
97
98 private:
113
115 ClassicProtocolState *dst_protocol);
116
118
120
121 std::function<void(const classic_protocol::message::server::Error &err)>
123};
124
125/**
126 * classic protocol handshake between router<->server and client<->router.
127 *
128 * a server::greeting processor which fetches a server::greeting
129 * to send it to the client.
130 *
131 * c->r : accept()
132 * r->s: connect()
133 * r<-s: server::greeting
134 * c<-r : ...
135 *
136 */
138 public:
139 using ForwardingProcessor::ForwardingProcessor;
140
141 /**
142 * stages of the handshake flow.
143 */
144 enum class Stage {
145 Connect,
148
149 Error,
150 Ok,
151 };
152
154
156 [[nodiscard]] Stage stage() const { return stage_; }
157
158 private:
162
164};
165
166/**
167 * authenticates a server connection.
168 *
169 * Assumes the server
170 *
171 * 1. sent a server::greeting already
172 * 2. expects to receive a client::greeting
173 */
175 public:
178 std::function<void(const classic_protocol::message::server::Error &)>
179 on_error)
180 : ForwardingProcessor(conn), on_error_(std::move(on_error)) {}
181
182 /**
183 * stages of the handshake flow.
184 */
185 enum class Stage {
196 AuthOk,
197 AuthError,
198
199 Error,
200 Ok,
201 };
202
204
206 [[nodiscard]] Stage stage() const { return stage_; }
207
208 private:
221
223 ClassicProtocolState *dst_protocol);
224
229
231
232 std::function<void(const classic_protocol::message::server::Error &err)>
234};
235
236#endif
protocol state of a classic protocol connection.
Definition: classic_connection_base.h:52
a processor base class with helper functions.
Definition: forwarding_processor.h:34
Definition: classic_connection_base.h:221
authenticates a server connection.
Definition: classic_greeting_forwarder.h:174
stdx::expected< Result, std::error_code > tls_forward()
Definition: classic_greeting_forwarder.cc:1673
size_t server_last_recv_buf_size_
Definition: classic_greeting_forwarder.h:227
size_t server_last_send_buf_size_
Definition: classic_greeting_forwarder.h:228
stdx::expected< Result, std::error_code > auth_ok()
server-side: auth is ok.
Definition: classic_greeting_forwarder.cc:2007
stdx::expected< Result, std::error_code > client_greeting()
Definition: classic_greeting_forwarder.cc:1386
size_t client_last_send_buf_size_
Definition: classic_greeting_forwarder.h:226
stdx::expected< Result, std::error_code > tls_connect_init()
Definition: classic_greeting_forwarder.cc:1734
Stage stage_
Definition: classic_greeting_forwarder.h:230
stdx::expected< Result, std::error_code > client_greeting_full()
Definition: classic_greeting_forwarder.cc:1547
stdx::expected< Result, std::error_code > process() override
Definition: classic_greeting_forwarder.cc:1293
stdx::expected< Result, std::error_code > tls_forward_init()
Definition: classic_greeting_forwarder.cc:1715
stdx::expected< Result, std::error_code > tls_connect()
Definition: classic_greeting_forwarder.cc:1758
Stage stage() const
Definition: classic_greeting_forwarder.h:206
void client_greeting_server_adjust_caps(ClassicProtocolState *src_protocol, ClassicProtocolState *dst_protocol)
Definition: classic_greeting_forwarder.cc:1334
ServerFirstAuthenticator(MysqlRoutingClassicConnectionBase *conn, std::function< void(const classic_protocol::message::server::Error &)> on_error)
Definition: classic_greeting_forwarder.h:176
stdx::expected< Result, std::error_code > client_greeting_start_tls()
Definition: classic_greeting_forwarder.cc:1469
Stage
stages of the handshake flow.
Definition: classic_greeting_forwarder.h:185
stdx::expected< Result, std::error_code > auth_error()
router<-server: auth error.
Definition: classic_greeting_forwarder.cc:1978
stdx::expected< Result, std::error_code > initial_response()
Definition: classic_greeting_forwarder.cc:1918
size_t client_last_recv_buf_size_
Definition: classic_greeting_forwarder.h:225
stdx::expected< Result, std::error_code > final_response()
Definition: classic_greeting_forwarder.cc:1931
stdx::expected< Result, std::error_code > client_greeting_after_tls()
Definition: classic_greeting_forwarder.cc:1849
void stage(Stage stage)
Definition: classic_greeting_forwarder.h:205
std::function< void(const classic_protocol::message::server::Error &err)> on_error_
Definition: classic_greeting_forwarder.h:233
classic protocol handshake between router<->server and client<->router.
Definition: classic_greeting_forwarder.h:137
stdx::expected< Result, std::error_code > server_greeted()
received an server::greeting or server::error from the server.
Definition: classic_greeting_forwarder.cc:1261
stdx::expected< Result, std::error_code > process() override
Definition: classic_greeting_forwarder.cc:1190
Stage stage() const
Definition: classic_greeting_forwarder.h:156
stdx::expected< Result, std::error_code > server_greeting()
Definition: classic_greeting_forwarder.cc:1218
Stage stage_
Definition: classic_greeting_forwarder.h:163
stdx::expected< Result, std::error_code > connect()
Definition: classic_greeting_forwarder.cc:1211
void stage(Stage stage)
Definition: classic_greeting_forwarder.h:155
Stage
stages of the handshake flow.
Definition: classic_greeting_forwarder.h:144
classic protocol handshake between client<->router and router<->server.
Definition: classic_greeting_forwarder.h:34
stdx::expected< Result, std::error_code > error()
Definition: classic_greeting_forwarder.cc:343
void stage(Stage stage)
Definition: classic_greeting_forwarder.h:95
stdx::expected< Result, std::error_code > client_greeting_start_tls()
Definition: classic_greeting_forwarder.cc:693
stdx::expected< Result, std::error_code > client_greeting_after_tls()
a TLS client greeting.
Definition: classic_greeting_forwarder.cc:975
bool in_handshake_
Definition: classic_greeting_forwarder.h:117
stdx::expected< Result, std::error_code > process() override
Definition: classic_greeting_forwarder.cc:301
stdx::expected< Result, std::error_code > tls_connect_init()
Definition: classic_greeting_forwarder.cc:849
stdx::expected< Result, std::error_code > client_greeting_full()
send a non-TLS client greeting to the server.
Definition: classic_greeting_forwarder.cc:756
stdx::expected< Result, std::error_code > server_greeting_error()
received an server::error from the server.
Definition: classic_greeting_forwarder.cc:394
std::function< void(const classic_protocol::message::server::Error &err)> on_error_
Definition: classic_greeting_forwarder.h:122
Stage stage() const
Definition: classic_greeting_forwarder.h:96
ServerGreetor(MysqlRoutingClassicConnectionBase *conn, bool in_handshake, std::function< void(const classic_protocol::message::server::Error &)> on_error)
construct a server::greeting processor.
Definition: classic_greeting_forwarder.h:59
stdx::expected< Result, std::error_code > server_greeting_greeting()
received a server::greeting from the server.
Definition: classic_greeting_forwarder.cc:480
stdx::expected< Result, std::error_code > client_greeting()
Definition: classic_greeting_forwarder.cc:596
stdx::expected< Result, std::error_code > initial_response()
Definition: classic_greeting_forwarder.cc:1058
stdx::expected< Result, std::error_code > tls_connect()
Definition: classic_greeting_forwarder.cc:875
Stage
stages of the handshake flow.
Definition: classic_greeting_forwarder.h:73
Stage stage_
Definition: classic_greeting_forwarder.h:119
stdx::expected< Result, std::error_code > auth_ok()
server-side: auth is ok.
Definition: classic_greeting_forwarder.cc:1146
void client_greeting_server_adjust_caps(ClassicProtocolState *src_protocol, ClassicProtocolState *dst_protocol)
Definition: classic_greeting_forwarder.cc:424
stdx::expected< Result, std::error_code > server_greeting()
Definition: classic_greeting_forwarder.cc:367
stdx::expected< Result, std::error_code > auth_error()
router<-server: auth error.
Definition: classic_greeting_forwarder.cc:1117
stdx::expected< Result, std::error_code > final_response()
Definition: classic_greeting_forwarder.cc:1071
Definition: expected.h:944
borrowable::message::server::Error< false > Error
Definition: classic_protocol_message.h:1399
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:910
Definition: gcs_xcom_synode.h:64