Skip to content

Commit 035f136

Browse files
committed
WL#15524 Patch #14 Add MGM TLS support to all remaining tools
Change-Id: Icc067d6e624dc6673f184919bdb58e161f68a8f7
1 parent a5d5fd0 commit 035f136

26 files changed

+114
-49
lines changed

mysql-test/suite/ndb_tls/no_path.cnf

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
!include suite/ndb_tls/my.cnf
22

3-
[ndb_mgmd.1.1]
3+
[mysql_cluster]
44
ndb-tls-search-path=
5-
6-
[ndbd.1.1]
7-
ndb-tls-search-path=
8-
9-
[ndbd.2.1]
10-
ndb-tls-search-path=
11-
12-
[mysqld]
13-
ndb-tls-search-path=
14-
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
!include suite/ndb_tls/my.cnf
22

3-
[ndbd.1.1]
3+
[mysql_cluster]
44
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
55

6-
[ndbd.2.1]
7-
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
8-
9-
[ndb_mgmd.1.1]
10-
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
11-
12-
[mysqld.1.1]
13-
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
14-
15-
16-

mysql-test/suite/ndb_tls/tls_required.cnf

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ RequireTls=true
66
[cluster_config.ndbd.2.1]
77
RequireTls=true
88

9-
[ndbd.1.1]
10-
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
11-
12-
[ndbd.2.1]
13-
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
14-
15-
[ndb_mgmd.1.1]
9+
[mysql_cluster]
1610
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
1711

1812
[mysqld.1.1]
19-
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
2013
ndb-cluster-connection-pool=2
2114
ndb-cluster-connection-pool-nodeids=51,52
2215

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright (c) 2023, 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 also distributed 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 included with MySQL.
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+
25+
#ifndef NDB_PORTLIB_SSL_APPLINK_H
26+
#define NDB_PORTLIB_SSL_APPLINK_H
27+
28+
#ifdef _WIN32
29+
#include "openssl/applink.c"
30+
#endif
31+
32+
#endif
33+

storage/ndb/src/kernel/main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <ndb_opts.h>
2727
#include <kernel/NodeBitmask.hpp>
2828
#include <portlib/ndb_daemon.h>
29+
#include "portlib/ssl_applink.h"
2930
#include "util/ndb_openssl_evp.h"
3031

3132
#include "my_alloc.h"
@@ -37,11 +38,6 @@
3738

3839
#include <EventLogger.hpp>
3940

40-
/* On Win32 applink.c must be included in one compilation unit */
41-
#ifdef _WIN32
42-
#include <openssl/applink.c>
43-
#endif
44-
4541
#define JAM_FILE_ID 485
4642

4743
#if defined VM_TRACE

storage/ndb/src/mgmclient/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <ndb_global.h>
2626
#include <ndb_opts.h>
2727
#include "my_getopt.h"
28+
#include "portlib/ssl_applink.h"
2829

2930
#include "my_alloc.h"
3031

storage/ndb/src/mgmsrv/main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <NdbConfig.h>
3737
#include <NdbSleep.h>
3838
#include <portlib/NdbDir.hpp>
39+
#include "portlib/ssl_applink.h"
3940
#include <ndb_version.h>
4041
#include <mgmapi_config_parameters.h>
4142
#include <NdbAutoPtr.hpp>
@@ -45,11 +46,6 @@
4546
#include <LogBuffer.hpp>
4647
#include <OutputStream.hpp>
4748

48-
/* On Win32 applink.c must be included in one compilation unit */
49-
#ifdef _WIN32
50-
#include <openssl/applink.c>
51-
#endif
52-
5349
#if defined VM_TRACE || defined ERROR_INSERT
5450
extern int g_errorInsert;
5551
#endif

storage/ndb/test/tools/connect.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ static struct my_option my_long_options[] =
4343
NdbStdOpt::ndb_connectstring,
4444
NdbStdOpt::connectstring,
4545
NdbStdOpt::ndb_nodeid,
46+
NdbStdOpt::tls_search_path,
47+
NdbStdOpt::mgm_tls,
4648
NDB_STD_OPT_DEBUG
4749
{ "loop", 'l', "loops",
4850
&opt_loop, &opt_loop, 0,
@@ -77,6 +79,7 @@ int main(int argc, char** argv){
7779
for (int i = 0; i<opt_loop; i++)
7880
{
7981
Ndb_cluster_connection con(opt_ndb_connectstring, opt_ndb_nodeid);
82+
con.configure_tls(opt_tls_search_path, opt_mgm_tls);
8083
if(con.connect(12, 5, 1) != 0)
8184
{
8285
ndbout << "Unable to connect to management server."

storage/ndb/test/tools/hugoJoin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static struct my_option my_long_options[] =
5757
NdbStdOpt::ndb_nodeid,
5858
NdbStdOpt::connect_retry_delay,
5959
NdbStdOpt::connect_retries,
60+
NdbStdOpt::tls_search_path,
61+
NdbStdOpt::mgm_tls,
6062
NDB_STD_OPT_DEBUG
6163
{ "database", 'd', "Database",
6264
&_db, &_db,
@@ -109,6 +111,7 @@ int main(int argc, char** argv){
109111

110112
// Connect to Ndb
111113
Ndb_cluster_connection con;
114+
con.configure_tls(opt_tls_search_path, opt_mgm_tls);
112115
if(con.connect(12, 5, 1) != 0)
113116
{
114117
return NDBT_ProgramExit(NDBT_FAILED);

storage/ndb/tools/NdbImportImpl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
#include "util/ndb_math.h"
2626
#include "util/require.h"
2727
#include "NdbImportImpl.hpp"
28+
#include "util/TlsKeyManager.hpp"
2829
#include <inttypes.h>
2930
#include <new>
3031

32+
TlsKeyManager g_tlsKeyManager;
33+
3134
NdbImportImpl::NdbImportImpl(NdbImport& facade) :
3235
NdbImport(*this),
3336
m_facade(&facade),
@@ -36,6 +39,7 @@ NdbImportImpl::NdbImportImpl(NdbImport& facade) :
3639
{
3740
c_connectionindex = 0;
3841
log_debug(1, "ctor");
42+
g_tlsKeyManager.init_mgm_client(opt_tls_search_path);
3943
}
4044

4145
NdbImportImpl::~NdbImportImpl()
@@ -86,7 +90,8 @@ NdbImportImpl::Mgm::do_connect()
8690
ndb_mgm_set_connectstring(m_handle, opt_ndb_connectstring);
8791
int retries = opt_connect_retries;
8892
int delay = opt_connect_retry_delay;
89-
if (ndb_mgm_connect(m_handle, retries, delay, 0) == -1)
93+
ndb_mgm_set_ssl_ctx(m_handle, g_tlsKeyManager.ctx());
94+
if (ndb_mgm_connect_tls(m_handle, retries, delay, 0, opt_mgm_tls) == -1)
9095
{
9196
m_util.set_error_mgm(m_error, __LINE__, m_handle);
9297
return -1;
@@ -230,6 +235,7 @@ NdbImportImpl::do_connect()
230235
new Ndb_cluster_connection(opt_ndb_connectstring,
231236
c.m_mainconnection,
232237
nodeid);
238+
c.m_connections[i]->configure_tls(opt_tls_search_path, opt_mgm_tls);
233239
if (i == 0)
234240
c.m_mainconnection = c.m_connections[i];
235241
}

storage/ndb/tools/delete_all.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <NdbToolsProgramExitCodes.hpp>
3333

3434
#include "my_alloc.h"
35+
#include "portlib/ssl_applink.h"
3536

3637
static int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab,
3738
bool fetch_across_commit, int parallelism = 240);
@@ -52,6 +53,8 @@ static struct my_option my_long_options[] =
5253
NdbStdOpt::ndb_nodeid,
5354
NdbStdOpt::connect_retry_delay,
5455
NdbStdOpt::connect_retries,
56+
NdbStdOpt::tls_search_path,
57+
NdbStdOpt::mgm_tls,
5558
NDB_STD_OPT_DEBUG
5659
{ "database", 'd', "Name of database table is in",
5760
&_dbname, nullptr, nullptr, GET_STR, REQUIRED_ARG,
@@ -81,6 +84,7 @@ int main(int argc, char** argv)
8184
}
8285

8386
Ndb_cluster_connection con(opt_ndb_connectstring, opt_ndb_nodeid);
87+
con.configure_tls(opt_tls_search_path, opt_mgm_tls);
8488
con.set_name("ndb_delete_all");
8589
if (con.connect(opt_connect_retries - 1, opt_connect_retry_delay, 1) != 0)
8690
{

storage/ndb/tools/desc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <NdbSleep.h>
3131

3232
#include "my_alloc.h"
33+
#include "portlib/ssl_applink.h"
3334

3435
void desc_AutoGrowSpecification(struct NdbDictionary::AutoGrowSpecification ags);
3536
int desc_logfilegroup(Ndb *myndb, char const* name);
@@ -63,6 +64,8 @@ static struct my_option my_long_options[] =
6364
NdbStdOpt::ndb_nodeid,
6465
NdbStdOpt::connect_retry_delay,
6566
NdbStdOpt::connect_retries,
67+
NdbStdOpt::tls_search_path,
68+
NdbStdOpt::mgm_tls,
6669
NDB_STD_OPT_DEBUG
6770
{ "database", 'd', "Name of database table is in",
6871
&_dbname, nullptr, nullptr, GET_STR, REQUIRED_ARG,
@@ -112,6 +115,7 @@ int main(int argc, char** argv){
112115

113116
Ndb_cluster_connection con(opt_ndb_connectstring, opt_ndb_nodeid);
114117
con.set_name("ndb_desc");
118+
con.configure_tls(opt_tls_search_path, opt_mgm_tls);
115119
if(con.connect(opt_connect_retries - 1, opt_connect_retry_delay, 1) != 0)
116120
{
117121
ndbout << "Unable to connect to management server." << endl;

storage/ndb/tools/drop_index.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <NDBT.hpp>
3131

3232
#include "my_alloc.h"
33+
#include "portlib/ssl_applink.h"
3334

3435
static const char* _dbname = "TEST_DB";
3536

@@ -44,6 +45,8 @@ static struct my_option my_long_options[] =
4445
NdbStdOpt::ndb_nodeid,
4546
NdbStdOpt::connect_retry_delay,
4647
NdbStdOpt::connect_retries,
48+
NdbStdOpt::tls_search_path,
49+
NdbStdOpt::mgm_tls,
4750
NDB_STD_OPT_DEBUG
4851
{ "database", 'd', "Name of database table is in",
4952
&_dbname, nullptr, nullptr, GET_STR, REQUIRED_ARG,
@@ -63,6 +66,7 @@ int main(int argc, char** argv){
6366

6467
Ndb_cluster_connection con(opt_ndb_connectstring, opt_ndb_nodeid);
6568
con.set_name("ndb_drop_index");
69+
con.configure_tls(opt_tls_search_path, opt_mgm_tls);
6670
if(con.connect(opt_connect_retries - 1, opt_connect_retry_delay, 1) != 0)
6771
{
6872
return NDBT_ProgramExit(NDBT_FAILED);

storage/ndb/tools/drop_tab.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <NDBT.hpp>
3131

3232
#include "my_alloc.h"
33+
#include "portlib/ssl_applink.h"
3334

3435
static const char* _dbname = "TEST_DB";
3536

@@ -44,6 +45,8 @@ static struct my_option my_long_options[] =
4445
NdbStdOpt::ndb_nodeid,
4546
NdbStdOpt::connect_retry_delay,
4647
NdbStdOpt::connect_retries,
48+
NdbStdOpt::tls_search_path,
49+
NdbStdOpt::mgm_tls,
4750
NDB_STD_OPT_DEBUG
4851
{ "database", 'd', "Name of database table is in",
4952
&_dbname, nullptr, nullptr, GET_STR, REQUIRED_ARG,
@@ -68,6 +71,7 @@ int main(int argc, char** argv){
6871

6972
Ndb_cluster_connection con(opt_ndb_connectstring, opt_ndb_nodeid);
7073
con.set_name("ndb_drop_table");
74+
con.configure_tls(opt_tls_search_path, opt_mgm_tls);
7175
if(con.connect(opt_connect_retries - 1, opt_connect_retry_delay, 1) != 0)
7276
{
7377
ndbout << "Unable to connect to management server." << endl;

storage/ndb/tools/listTables.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <NdbOut.hpp>
4040

4141
#include <NdbToolsProgramExitCodes.hpp>
42+
#include "portlib/ssl_applink.h"
4243

4344
static int _fully_qualified = 0;
4445
static int _parsable = 0;
@@ -276,6 +277,8 @@ static struct my_option my_long_options[] =
276277
NdbStdOpt::ndb_nodeid,
277278
NdbStdOpt::connect_retry_delay,
278279
NdbStdOpt::connect_retries,
280+
NdbStdOpt::tls_search_path,
281+
NdbStdOpt::mgm_tls,
279282
NDB_STD_OPT_DEBUG
280283
{ "database", 'd',
281284
"Name of database table is in. Requires table-name in argument",
@@ -335,6 +338,7 @@ int main(int argc, char** argv) {
335338
}
336339

337340
ndb_cluster_connection->set_name("ndb_show_tables");
341+
ndb_cluster_connection->configure_tls(opt_tls_search_path, opt_mgm_tls);
338342

339343
if (ndb_cluster_connection->connect(opt_connect_retries - 1,
340344
opt_connect_retry_delay, 1)) {

storage/ndb/tools/ndb_blob_tool.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <ndb_global.h>
2525
#include <ndb_opts.h>
2626
#include <ndb_limits.h>
27+
#include "portlib/ssl_applink.h"
2728

2829
#include <NdbSleep.h>
2930
#include <NdbOut.hpp>
@@ -141,6 +142,7 @@ doconnect()
141142
do
142143
{
143144
g_ncc = new Ndb_cluster_connection(opt_ndb_connectstring);
145+
g_ncc->configure_tls(opt_tls_search_path, opt_mgm_tls);
144146
CHK2(g_ncc->connect(opt_connect_retries - 1, opt_connect_retry_delay) == 0, getNdbError(g_ncc));
145147
CHK2(g_ncc->wait_until_ready(30, 10) == 0, getNdbError(g_ncc));
146148

@@ -1055,6 +1057,8 @@ my_long_options[] =
10551057
NdbStdOpt::ndb_nodeid,
10561058
NdbStdOpt::connect_retry_delay,
10571059
NdbStdOpt::connect_retries,
1060+
NdbStdOpt::tls_search_path,
1061+
NdbStdOpt::mgm_tls,
10581062
NDB_STD_OPT_DEBUG
10591063
{ "database", 'd', "Name of database table is in",
10601064
&opt_dbname, nullptr, nullptr, GET_STR, REQUIRED_ARG,

storage/ndb/tools/ndb_config.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
#include "util/cstrbuf.h"
8585
#include "mgmcommon/ConfigRetriever.hpp"
8686
#include "mgmcommon/Config.hpp"
87+
#include "portlib/ssl_applink.h"
8788

8889
#include "my_alloc.h"
8990

@@ -119,6 +120,8 @@ static struct my_option my_long_options[] =
119120
NdbStdOpt::connectstring,
120121
NdbStdOpt::connect_retry_delay,
121122
NdbStdOpt::connect_retries,
123+
NdbStdOpt::tls_search_path,
124+
NdbStdOpt::mgm_tls,
122125
NDB_STD_OPT_DEBUG
123126
{ "nodes", NDB_OPT_NOSHORT, "Print nodes",
124127
&g_nodes, nullptr, nullptr, GET_BOOL, NO_ARG,
@@ -907,6 +910,8 @@ ConnectionTypeApply::apply(const ndb_mgm_configuration_iterator& iter)
907910
static ndb_mgm_configuration*
908911
fetch_configuration(int from_node)
909912
{
913+
TlsKeyManager tlsKeyManager;
914+
tlsKeyManager.init_mgm_client(opt_tls_search_path);
910915
ndb_mgm_configuration* conf = 0;
911916
NdbMgmHandle mgm = ndb_mgm_create_handle();
912917
if(mgm == NULL) {
@@ -926,7 +931,9 @@ fetch_configuration(int from_node)
926931
goto noconnect;
927932
}
928933

929-
if(ndb_mgm_connect(mgm, opt_connect_retries - 1, opt_connect_retry_delay, 1))
934+
ndb_mgm_set_ssl_ctx(mgm, tlsKeyManager.ctx());
935+
if(ndb_mgm_connect_tls(mgm, opt_connect_retries - 1, opt_connect_retry_delay,
936+
1, opt_mgm_tls))
930937
{
931938
fprintf(stderr, "Connect failed");
932939
fprintf(stderr, " code: %d, msg: %s\n",

0 commit comments

Comments
 (0)