MySQL 9.0.0
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 unacceptable_cipher_spec{
59 "!aNULL", "!eNULL", "!EXPORT", "!LOW", "!MD5", "!DES",
60 "!3DES", "!RC2", "!RC4", "!PSK", "!kDH", "!SSLv3",
61 };
62
63 /**
64 * construct a TLS Context for server-side.
65 */
67 TlsVersion max_version = TlsVersion::AUTO,
68 bool session_cache_mode = false,
69 size_t session_cache_size = 0,
70 unsigned int session_cache_timeout = 0);
71
72 /**
73 * init temporary DH parameters.
74 *
75 * @param dh_params filename of a PEM file with DH parameters
76 */
78 const std::string &dh_params);
79
80 /**
81 * set cipher-list.
82 *
83 * list is filtered for unacceptable_cipher_spec
84 *
85 * @param ciphers colon separated list of ciphers
86 *
87 * @see openssl ciphers
88 */
89 stdx::expected<void, std::error_code> cipher_list(const std::string &ciphers);
90
91 /**
92 * set how cerifiticates should be verified.
93 *
94 * @param verify NONE or PEER
95 * @param tls_opts extra options for PEER
96 * @throws std::illegal_argument if verify is NONE and tls_opts is != 0
97 */
100
101 /**
102 * get the security level.
103 *
104 * | sec-level | RSA-min-key-size |
105 * +-----------+------------------+
106 * | 1 | 1024 |
107 * | 2 | 2048 |
108 * | 3 | 3072 |
109 * | 4 | 7680 |
110 * | 5 | 15360 |
111 *
112 * @see SSL_CTX_get_security_level()
113 *
114 * @returns the security level of the ssl-ctx.
115 */
116 int security_level() const;
117
118 /**
119 * default ciphers.
120 */
121 static std::vector<std::string> default_ciphers();
122
123 /**
124 * set the session-id context for ssl-context reuse.
125 *
126 * unique identifier of the ssl-ctx.
127 *
128 * @param sid_ctx opaque string of size sid_ctx_len
129 * @param sid_ctx_len length of sid_ctx_len
130 */
131 stdx::expected<void, std::error_code> session_id_context(
132 const unsigned char *sid_ctx, unsigned int sid_ctx_len);
133};
134
135#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