MySQL 8.3.0
Source Code Documentation
classic_auth.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2023, 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 also distributed 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 included with MySQL.
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 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*/
24
25#ifndef ROUTING_CLASSIC_AUTH_INCLUDED
26#define ROUTING_CLASSIC_AUTH_INCLUDED
27
28#include <memory> // unique_ptr
29#include <string_view>
30#include <system_error>
31
32#include <openssl/ssl.h>
33
36
37template <class T>
39
40template <>
41struct OsslDeleter<EVP_PKEY> {
42 void operator()(EVP_PKEY *k) { EVP_PKEY_free(k); }
43};
44
45using EvpPkey = std::unique_ptr<EVP_PKEY, OsslDeleter<EVP_PKEY>>;
46
47class AuthBase {
48 public:
50 public_key_from_ssl_ctx_as_pem(SSL_CTX *ssl_ctx);
51
53 std::string_view pubkey);
54
56 std::string plaintext, EVP_PKEY *pkey);
57
59 std::string_view ciphertext, EVP_PKEY *priv);
60
62 SSL_CTX *ssl_ctx, std::string_view encrypted, std::string_view nonce);
63
65 const EvpPkey &pkey, std::string_view password, std::string_view nonce);
66
67 static std::string_view strip_trailing_null(std::string_view s);
68
69 static bool connection_has_public_key(
71};
72
73#endif
Definition: classic_auth.h:47
static stdx::expected< std::string, std::error_code > public_key_encrypt(std::string plaintext, EVP_PKEY *pkey)
Definition: classic_auth.cc:124
static stdx::expected< std::string, std::error_code > private_key_decrypt(std::string_view ciphertext, EVP_PKEY *priv)
Definition: classic_auth.cc:165
static stdx::expected< std::string, std::error_code > rsa_encrypt_password(const EvpPkey &pkey, std::string_view password, std::string_view nonce)
Definition: classic_auth.cc:275
static stdx::expected< std::string, std::error_code > public_key_from_ssl_ctx_as_pem(SSL_CTX *ssl_ctx)
Definition: classic_auth.cc:85
static bool connection_has_public_key(MysqlRoutingClassicConnectionBase *connection)
Definition: classic_auth.cc:292
static std::string_view strip_trailing_null(std::string_view s)
remove trailing \0 in a string_view.
Definition: classic_auth.cc:44
static stdx::expected< std::string, std::error_code > rsa_decrypt_password(SSL_CTX *ssl_ctx, std::string_view encrypted, std::string_view nonce)
Definition: classic_auth.cc:245
static stdx::expected< EvpPkey, std::error_code > public_key_from_pem(std::string_view pubkey)
Definition: classic_auth.cc:111
Definition: classic_connection_base.h:257
std::unique_ptr< EVP_PKEY, OsslDeleter< EVP_PKEY > > EvpPkey
Definition: classic_auth.cc:75
Definition: expected.h:943
static char * password
Definition: mysql_secure_installation.cc:57
void operator()(EVP_PKEY *k)
Definition: classic_auth.h:42
Definition: classic_auth.h:38