MySQL 8.4.2
Source Code Documentation
tls_server_context.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 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 MYSQL_HARNESS_TLS_SERVER_CONTEXT_INCLUDED
27#define MYSQL_HARNESS_TLS_SERVER_CONTEXT_INCLUDED
28
29#include <array>
30#include <string>
31#include <vector>
32
37
38enum class TlsVerifyOpts {
40 kClientOnce = 1,
41};
42
43namespace stdx {
44template <>
45struct is_flags<TlsVerifyOpts> : std::true_type {};
46} // namespace stdx
47
48/**
49 * TLS Context for the server side.
50 */
52 public:
53 /**
54 * unacceptable ciphers.
55 *
56 * they are filtered out if set through cipher_list()
57 */
58 static constexpr std::array<const char *, 12> unacceptable_cipher_spec{
59 "!aNULL", "!eNULL", "!EXPORT", "!LOW", "!MD5", "!DES",
60 "!3DES", "!RC2", "!RC4", "!PSK", "!kDH", "!SSLv3"};
61
62 /**
63 * construct a TLS Context for server-side.
64 */
66 TlsVersion max_version = TlsVersion::AUTO,
67 bool session_cache_mode = false,
68 size_t session_cache_size = 0,
69 unsigned int session_cache_timeout = 0);
70
71 /**
72 * init temporary DH parameters.
73 *
74 * @param dh_params filename of a PEM file with DH parameters
75 */
77 const std::string &dh_params);
78
79 /**
80 * set cipher-list.
81 *
82 * list is filtered for unacceptable_cipher_spec
83 *
84 * @param ciphers colon separated list of ciphers
85 *
86 * @see openssl ciphers
87 */
88 stdx::expected<void, std::error_code> cipher_list(const std::string &ciphers);
89
90 /**
91 * set how cerifiticates should be verified.
92 *
93 * @param verify NONE or PEER
94 * @param tls_opts extra options for PEER
95 * @throws std::illegal_argument if verify is NONE and tls_opts is != 0
96 */
99
100 /**
101 * get the security level.
102 *
103 * | sec-level | RSA-min-key-size |
104 * +-----------+------------------+
105 * | 1 | 1024 |
106 * | 2 | 2048 |
107 * | 3 | 3072 |
108 * | 4 | 7680 |
109 * | 5 | 15360 |
110 *
111 * @see SSL_CTX_get_security_level()
112 *
113 * @returns the security level of the ssl-ctx.
114 */
115 int security_level() const;
116
117 /**
118 * default ciphers.
119 */
120 static std::vector<std::string> default_ciphers();
121
122 /**
123 * set the session-id context for ssl-context reuse.
124 *
125 * unique identifier of the ssl-ctx.
126 *
127 * @param sid_ctx opaque string of size sid_ctx_len
128 * @param sid_ctx_len length of sid_ctx_len
129 */
130 stdx::expected<void, std::error_code> session_id_context(
131 const unsigned char *sid_ctx, unsigned int sid_ctx_len);
132};
133
134#endif
wraps SSL_CTX.
Definition: tls_context.h:85
std::vector< std::string > cipher_list() const
get current cipher-list.
Definition: tls_context.cc:392
int security_level() const
get security_level.
Definition: tls_context.cc:515
TLS Context for the server side.
Definition: tls_server_context.h:51
Definition: expected.h:284
a type-safe flags type.
Definition: flags.h:115
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: ssl.cc:115
Definition: bit.h:32
Definition: flags.h:38
TlsVerify
Verification of Cerifiticates.
Definition: tls_context.h:62
TlsVersion
TLS Versions.
Definition: tls_context.h:54
#define HARNESS_TLS_EXPORT
Definition: tls_export.h:15
TlsVerifyOpts
Definition: tls_server_context.h:38