MySQL 26.10.0
Source Code Documentation
destination_ssl_context.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2026, 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 MYSQL_ROUTING_DESTINATION_TLS_CONTEXT_INCLUDED
27#define MYSQL_ROUTING_DESTINATION_TLS_CONTEXT_INCLUDED
28
30
31#include <chrono>
32#include <map>
33#include <mutex>
34#include <string>
35
37#include "mysqlrouter/ssl_mode.h" // SslVerify
38
39/**
40 * TlsClientContext per destination.
41 */
43 public:
44 DestinationTlsContext(bool session_cache_mode, size_t ssl_session_cache_size,
45 unsigned int ssl_session_cache_timeout)
46 : session_cache_mode_(session_cache_mode),
47 ssl_session_cache_size_(ssl_session_cache_size),
48 ssl_session_cache_timeout_(ssl_session_cache_timeout) {}
49
50 /**
51 * set SslVerify.
52 */
53 void verify(SslVerify ssl_verify);
54
55 /**
56 * set CA file.
57 */
58 void ca_file(const std::string &file);
59
60 /**
61 * set CA path.
62 */
63 void ca_path(const std::string &path);
64
65 /**
66 * set CRL file.
67 */
68 void crl_file(const std::string &file);
69
70 /**
71 * set CRL path.
72 */
73 void crl_path(const std::string &path);
74
75 /**
76 * set allowed EC curves.
77 */
78 void curves(const std::string &curves);
79
80 /**
81 * set allowed ciphers.
82 */
83 void ciphers(const std::string &ciphers);
84
85 SslVerify get_verify();
86 const std::string &get_ca_file();
87 const std::string &get_ca_path();
88 const std::string &get_crl_file();
89 const std::string &get_crl_path();
90 const std::string &get_curves();
91 const std::string &get_ciphers();
92
93 /**
94 * set client-key and its cert.
95 */
96 void client_key_and_cert_file(std::string key, std::string cert);
97
98 /**
99 * get a TlsClientContent for a destination.
100 *
101 * If no TlsClientContext exists for the destination, creates a
102 * TlsClientContent based on:
103 *
104 * - verify()
105 * - ca_file()
106 * - ca_path()
107 * - crl_file()
108 * - crl_path()
109 * - curves()
110 * - ciphers()
111 *
112 * If that succeeds, the resulting TlsClientContext is cached and a shared
113 * reference to it is returned.
114 *
115 * If a TlsClientContext for the destination exists, a shared reference to it
116 * is returned.
117 *
118 * @param dest_id unique identifier of a destination
119 * @param hostname name of the destination host
120 */
121 std::shared_ptr<TlsClientContext> get(const std::string &dest_id,
122 const std::string &hostname);
123
124 /**
125 * Validate the configured TLS material before invalidating the cache.
126 *
127 * On success, discards the cached client contexts. The next get() lazily
128 * creates a context for its destination from the configured paths. On
129 * failure, existing cache entries remain available, while a cache miss still
130 * initializes a new context from the configured paths.
131 *
132 * @param out_error receives the validation error when false is returned.
133 */
134 bool reload(std::string &out_error);
135
136 private:
138 std::string ca_file_;
139 std::string ca_path_;
140 std::string crl_file_;
141 std::string crl_path_;
142 std::string curves_;
143 std::string ciphers_;
144
145 std::string cert_file_;
146 std::string key_file_;
147
148 std::map<std::string, std::shared_ptr<TlsClientContext>> tls_contexts_;
149
150 std::mutex mtx_;
151
152 bool session_cache_mode_{true};
153 size_t ssl_session_cache_size_{};
154 std::chrono::seconds ssl_session_cache_timeout_{std::chrono::seconds(0)};
155};
156
157#endif
TlsClientContext per destination.
Definition: destination_ssl_context.h:42
std::string curves_
Definition: destination_ssl_context.h:142
std::string crl_file_
Definition: destination_ssl_context.h:140
std::mutex mtx_
Definition: destination_ssl_context.h:150
std::string ciphers_
Definition: destination_ssl_context.h:143
std::string ca_file_
Definition: destination_ssl_context.h:138
std::string key_file_
Definition: destination_ssl_context.h:146
std::string ca_path_
Definition: destination_ssl_context.h:139
DestinationTlsContext(bool session_cache_mode, size_t ssl_session_cache_size, unsigned int ssl_session_cache_timeout)
Definition: destination_ssl_context.h:44
std::string crl_path_
Definition: destination_ssl_context.h:141
std::map< std::string, std::shared_ptr< TlsClientContext > > tls_contexts_
Definition: destination_ssl_context.h:148
std::string cert_file_
Definition: destination_ssl_context.h:145
static char * path
Definition: mysqldump.cc:153
Definition: os0file.h:89
std::chrono::seconds seconds
Definition: authorize_manager.cc:71
static mysql_service_status_t get(THD **thd) noexcept
Definition: mysql_current_thread_reader_all_empty.cc:31
bool verify(const std::string &digest, const std::string &message, const std::string &public_key_content)
Verify a message signed by the private key pair of the provided public key.
Definition: my_base64_encode.cc:113
required string key
Definition: replication_asynchronous_connection_failover.proto:60
static bool reload(MYSQL_THD thd)
Reloads the rules into the in-memory table.
Definition: rewriter_plugin.cc:333
#define ROUTING_EXPORT
Definition: routing_export.h:15
SslVerify
Definition: ssl_mode.h:38