MySQL 26.7.0
Source Code Documentation
sslopt-vars.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SSLOPT_VARS_INCLUDED
25#define SSLOPT_VARS_INCLUDED
26
27#include <stddef.h>
28#include <stdio.h>
29#include <sys/types.h>
30#include <functional>
31
32#ifdef MYSQL_SERVER
33#error This header is supposed to be used only in the client
34#endif
35
36#include "my_inttypes.h"
37#include "my_macros.h"
38#include "mysql.h"
39#include "nulls.h"
40#include "template_utils.h"
41#include "typelib.h"
42
43const char *ssl_mode_names_lib[] = {"DISABLED", "PREFERRED", "REQUIRED",
44 "VERIFY_CA", "VERIFY_IDENTITY", NullS};
46 ssl_mode_names_lib, nullptr};
47
48const char *ssl_fips_mode_names_lib[] = {"OFF", "ON", "STRICT", NullS};
50 "", ssl_fips_mode_names_lib, nullptr};
51
53static char *opt_ssl_ca = nullptr;
54static char *opt_ssl_capath = nullptr;
55static char *opt_ssl_cert = nullptr;
56static char *opt_ssl_cipher = nullptr;
57static char *opt_tls_ciphersuites = nullptr;
58static char *opt_ssl_key = nullptr;
59static char *opt_ssl_crl = nullptr;
60static char *opt_ssl_crlpath = nullptr;
61static char *opt_tls_version = nullptr;
62static char *opt_tls_kex = nullptr;
64static bool opt_force_pqc = false;
65static bool opt_use_pqc_sign = false;
66static bool ssl_mode_set_explicitly = false;
67static char *opt_ssl_session_data = nullptr;
69static char *opt_tls_sni_servername = nullptr;
70
71static inline int set_client_ssl_options(MYSQL *mysql) {
72 /*
73 Print a warning if explicitly defined combination of --ssl-mode other than
74 VERIFY_CA or VERIFY_IDENTITY with explicit --ssl-ca or --ssl-capath values.
75 */
78 fprintf(stderr,
79 "WARNING: no verification of server certificate will be done. "
80 "Use --ssl-mode=VERIFY_CA or VERIFY_IDENTITY.\n");
81 }
82
83 /* Set SSL parameters: key, cert, ca, capath, cipher, clr, clrpath. */
90 } else {
93 }
98 if (opt_ssl_fips_mode > 0) {
100 if (mysql_errno(mysql) == CR_SSL_FIPS_MODE_ERR) return 1;
101 }
108 FILE *fi = fopen(opt_ssl_session_data, "rb");
109 char buff[4096], *bufptr = &buff[0];
110 size_t read = 0;
111
112 if (!fi) {
113 fprintf(stderr, "Error: Can't open the ssl session data file.\n");
114 return 1;
115 }
116 long file_length = sizeof(buff) - 1;
117 if (0 == fseek(fi, 0, SEEK_END)) {
118 file_length = ftell(fi);
119 if (file_length > 0)
120 file_length = std::min(file_length, 65536L);
121 else
122 file_length = sizeof(buff) - 1;
123 fseek(fi, 0, SEEK_SET);
124 }
125 if (file_length > (long)(sizeof(buff) - 1)) {
126 bufptr = (char *)malloc(file_length + 1);
127 if (bufptr)
128 bufptr[file_length] = 0;
129 else {
130 bufptr = &buff[0];
131 file_length = sizeof(buff) - 1;
132 }
133 }
134 read = fread(bufptr, 1, file_length, fi);
135 if (!read) {
136 fprintf(stderr, "Error: Can't read the ssl session data file.\n");
137 fclose(fi);
138 if (bufptr != &buff[0]) free(bufptr);
139 return 1;
140 }
141 assert(read <= (size_t)file_length);
142 bufptr[read] = 0;
143 fclose(fi);
144
145 int ret = 0;
147 if (bufptr != &buff[0]) free(bufptr);
148 return ret;
149 }
150 return 0;
151}
152
154 MYSQL *mysql, std::function<void(const char *)> report_error) {
158 "--ssl-session-data specified but the session was not reused.");
159 return true;
160 }
161 return false;
162}
163
164#define SSL_SET_OPTIONS(mysql) set_client_ssl_options(mysql)
165
166const char *SSL_SET_OPTIONS_ERROR = "Failed to set ssl related options.\n";
167
168#endif /* SSLOPT_VARS_INCLUDED */
#define CR_SSL_FIPS_MODE_ERR
Definition: errmsg.h:126
static bool report_error(THD *thd, int error_code, Sql_condition::enum_severity_level level, Args... args)
Definition: error_handler.cc:291
#define malloc(A)
Definition: lexyy.cc:914
#define free(A)
Definition: lexyy.cc:915
Some integer typedefs for easier portability.
Some common macros.
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
unsigned int STDCALL mysql_errno(MYSQL *mysql)
Definition: client.cc:9524
@ MYSQL_OPT_SSL_CIPHER
Definition: mysql.h:194
@ MYSQL_OPT_TLS_SNI_SERVERNAME
Definition: mysql.h:217
@ MYSQL_OPT_USE_PQC_SIGN
Definition: mysql.h:220
@ MYSQL_OPT_FORCE_PQC
Definition: mysql.h:219
@ MYSQL_OPT_SSL_CA
Definition: mysql.h:192
@ MYSQL_OPT_TLS_VERSION
Definition: mysql.h:205
@ MYSQL_OPT_SSL_KEY
Definition: mysql.h:190
@ MYSQL_OPT_SSL_FIPS_MODE
Definition: mysql.h:210
@ MYSQL_OPT_TLS_KEX
Definition: mysql.h:218
@ MYSQL_OPT_SSL_CRLPATH
Definition: mysql.h:196
@ MYSQL_OPT_SSL_CERT
Definition: mysql.h:191
@ MYSQL_OPT_SSL_SESSION_DATA
Definition: mysql.h:216
@ MYSQL_OPT_SSL_MODE
Definition: mysql.h:206
@ MYSQL_OPT_SSL_CAPATH
Definition: mysql.h:193
@ MYSQL_OPT_SSL_CRL
Definition: mysql.h:195
@ MYSQL_OPT_TLS_CIPHERSUITES
Definition: mysql.h:211
bool STDCALL mysql_get_ssl_session_reused(MYSQL *mysql)
Check if the current ssl session is reused.
Definition: client.cc:3873
int STDCALL mysql_options(MYSQL *mysql, enum mysql_option option, const void *arg)
Definition: client.cc:8855
@ SSL_MODE_PREFERRED
Definition: mysql.h:277
@ SSL_MODE_VERIFY_CA
Definition: mysql.h:279
@ SSL_FIPS_MODE_OFF
Definition: mysql.h:284
const std::string FILE("FILE")
Definition: instrumented_condition_variable.h:32
stdx::expected< size_t, std::error_code > read(SyncReadStream &stream, const MutableBufferSequence &buffers)
Definition: buffer.h:835
#define NullS
Definition of the null string (a null pointer of type char *), used in some of our string handling co...
Definition: nulls.h:33
static char * opt_ssl_session_data
Definition: sslopt-vars.h:67
static bool opt_use_pqc_sign
Definition: sslopt-vars.h:65
static int set_client_ssl_options(MYSQL *mysql)
Definition: sslopt-vars.h:71
static bool opt_ssl_session_data_continue_on_failed_reuse
Definition: sslopt-vars.h:68
static char * opt_ssl_cipher
Definition: sslopt-vars.h:56
const char * ssl_mode_names_lib[]
Definition: sslopt-vars.h:43
static char * opt_ssl_ca
Definition: sslopt-vars.h:53
static char * opt_tls_version
Definition: sslopt-vars.h:61
static bool opt_force_pqc
Definition: sslopt-vars.h:64
const char * SSL_SET_OPTIONS_ERROR
Definition: sslopt-vars.h:166
static char * opt_ssl_capath
Definition: sslopt-vars.h:54
static char * opt_ssl_crlpath
Definition: sslopt-vars.h:60
TYPELIB ssl_fips_mode_typelib
Definition: sslopt-vars.h:49
static char * opt_tls_ciphersuites
Definition: sslopt-vars.h:57
const char * ssl_fips_mode_names_lib[]
Definition: sslopt-vars.h:48
static char * opt_tls_sni_servername
Definition: sslopt-vars.h:69
static ulong opt_ssl_fips_mode
Definition: sslopt-vars.h:63
static uint opt_ssl_mode
Definition: sslopt-vars.h:52
static char * opt_tls_kex
Definition: sslopt-vars.h:62
static bool ssl_mode_set_explicitly
Definition: sslopt-vars.h:66
static char * opt_ssl_cert
Definition: sslopt-vars.h:55
TYPELIB ssl_mode_typelib
Definition: sslopt-vars.h:45
static char * opt_ssl_crl
Definition: sslopt-vars.h:59
static char * opt_ssl_key
Definition: sslopt-vars.h:58
static bool ssl_client_check_post_connect_ssl_setup(MYSQL *mysql, std::function< void(const char *)> report_error)
Definition: sslopt-vars.h:153
Definition: mysql.h:303
Definition: typelib.h:35
#define array_elements(A)
Definition: validate_password_imp.cc:50