MySQL 9.1.0
Source Code Documentation
classic_auth_caching_sha2.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 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_AUTH_CACHING_SHA2_INCLUDED
27#define ROUTING_CLASSIC_AUTH_CACHING_SHA2_INCLUDED
28
29#include <optional>
30#include <string_view>
31#include <system_error>
32
33#include "basic_protocol_splicer.h" // TlsSwitchableConnection
34#include "classic_auth.h"
36
37// low-level routings for caching_sha2_password
39 public:
40 static constexpr const size_t kNonceLength{20};
41
42 static constexpr const std::string_view kName{"caching_sha2_password"};
43
44 static constexpr const std::string_view kPublicKeyRequest{"\x02"};
45 static constexpr const uint8_t kFastAuthDone{0x03};
46 static constexpr const uint8_t kPerformFullAuth{0x04};
47
48 static std::optional<std::string> scramble(std::string_view nonce,
49 std::string_view pwd);
50
52 Channel &dst_channel, ClassicProtocolState &dst_protocol);
53
54 template <class Proto>
57 return send_public_key_request(conn.channel(), conn.protocol());
58 }
59
61 Channel &dst_channel, ClassicProtocolState &dst_protocol,
62 const std::string &public_key);
63
64 template <class Proto>
66 TlsSwitchableConnection<Proto> &conn, const std::string &public_key) {
67 return send_public_key(conn.channel(), conn.protocol(), public_key);
68 }
69
72 ClassicProtocolState &dst_protocol);
73
75 Channel &dst_channel, ClassicProtocolState &dst_protocol,
76 const std::string &password);
77
78 template <class Proto>
80 TlsSwitchableConnection<Proto> &conn, const std::string &password) {
81 return send_plaintext_password(conn.channel(), conn.protocol(), password);
82 }
83
85 Channel &dst_channel, ClassicProtocolState &dst_protocol,
86 const std::string &password);
87
88 template <class Proto>
90 TlsSwitchableConnection<Proto> &conn, const std::string &password) {
91 return send_encrypted_password(conn.channel(), conn.protocol(), password);
92 }
93
94 static bool is_public_key_request(const std::string_view &data);
95 static bool is_public_key(const std::string_view &data);
96};
97
98#endif
Definition: classic_auth.h:48
Definition: classic_auth_caching_sha2.h:38
static constexpr const std::string_view kPublicKeyRequest
Definition: classic_auth_caching_sha2.h:44
static stdx::expected< size_t, std::error_code > send_plaintext_password_request(Channel &dst_channel, ClassicProtocolState &dst_protocol)
Definition: classic_auth_caching_sha2.cc:60
static constexpr const uint8_t kFastAuthDone
Definition: classic_auth_caching_sha2.h:45
static bool is_public_key_request(const std::string_view &data)
Definition: classic_auth_caching_sha2.cc:87
static stdx::expected< size_t, std::error_code > send_public_key(TlsSwitchableConnection< Proto > &conn, const std::string &public_key)
Definition: classic_auth_caching_sha2.h:65
static bool is_public_key(const std::string_view &data)
Definition: classic_auth_caching_sha2.cc:92
static stdx::expected< size_t, std::error_code > send_public_key_request(Channel &dst_channel, ClassicProtocolState &dst_protocol)
Definition: classic_auth_caching_sha2.cc:42
static std::optional< std::string > scramble(std::string_view nonce, std::string_view pwd)
Definition: classic_auth_caching_sha2.cc:36
static stdx::expected< size_t, std::error_code > send_public_key_request(TlsSwitchableConnection< Proto > &conn)
Definition: classic_auth_caching_sha2.h:55
static stdx::expected< size_t, std::error_code > send_encrypted_password(TlsSwitchableConnection< Proto > &conn, const std::string &password)
Definition: classic_auth_caching_sha2.h:89
static constexpr const std::string_view kName
Definition: classic_auth_caching_sha2.h:42
static constexpr const size_t kNonceLength
Definition: classic_auth_caching_sha2.h:40
static stdx::expected< size_t, std::error_code > send_plaintext_password(Channel &dst_channel, ClassicProtocolState &dst_protocol, const std::string &password)
Definition: classic_auth_caching_sha2.cc:69
static stdx::expected< size_t, std::error_code > send_plaintext_password(TlsSwitchableConnection< Proto > &conn, const std::string &password)
Definition: classic_auth_caching_sha2.h:79
static constexpr const uint8_t kPerformFullAuth
Definition: classic_auth_caching_sha2.h:46
static stdx::expected< size_t, std::error_code > send_public_key(Channel &dst_channel, ClassicProtocolState &dst_protocol, const std::string &public_key)
Definition: classic_auth_caching_sha2.cc:51
static stdx::expected< size_t, std::error_code > send_encrypted_password(Channel &dst_channel, ClassicProtocolState &dst_protocol, const std::string &password)
Definition: classic_auth_caching_sha2.cc:79
SSL aware socket buffers.
Definition: channel.h:65
protocol state of a classic protocol connection.
Definition: classic_protocol_state.h:40
a Connection that can be switched to TLS.
Definition: connection_base.h:264
Channel & channel()
Definition: connection_base.h:359
protocol_state_type & protocol()
Definition: connection_base.h:398
static char * password
Definition: mysql_secure_installation.cc:58