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