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