Skip to content

Commit 7a8387d

Browse files
author
Bogdan Degtyariov
committed
Bug #26226502 Setting ssl-ca without ssl-mode does not trigger error
1 parent 4bef986 commit 7a8387d

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

xapi/session.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ void mysqlx_session_options_t::set_ssl_ca(const string &ca)
452452
}
453453
else
454454
{
455-
m_tls_options.set_ssl_mode(TLS::Options::SSL_MODE::VERIFY_CA);
455+
// When SSL CA is set the SSL MODE should already be set
456+
throw Mysqlx_exception("ssl-mode should be VERIFY_CA or VERIFY_IDENTITY "\
457+
"before setting ssl-ca");
456458
}
457459

458460
m_tls_options.set_ca(ca);

xapi/tests/xapi-t.cc

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,13 @@ TEST_F(xapi, conn_string_test)
830830

831831
cout << "CA file: " << conn_str_ca << endl;
832832

833-
conn_str_ca = conn_str_basic + "/?Ssl-cA=" + conn_str_ca;
834-
835833
/* If ssl-ca set ssl-mode can not be DISABLED or REQUIRED*/
836834

837835
for (unsigned i = 0; i < 2; ++i)
838836
{
839-
std::string conn_str = conn_str_ca;
840-
conn_str += (i > 0 ? "&ssl-mode=REQUIRED" : "&ssl-mode=DISABLED");
837+
std::string conn_str = conn_str_basic;
838+
conn_str += (i > 0 ? "/?ssl-mode=REQUIRED" : "/?ssl-mode=DISABLED");
839+
conn_str += "&Ssl-cA=" + conn_str_ca;
841840

842841
local_sess = mysqlx_get_session_from_url(
843842
conn_str.c_str(),
@@ -854,7 +853,9 @@ TEST_F(xapi, conn_string_test)
854853
/* Same thing with VERIFY_CA should work */
855854

856855
{
857-
std::string conn_str = conn_str_ca + "&ssl-mode=VERIFY_CA";
856+
std::string conn_str = conn_str_basic
857+
+ "/?ssl-mode=VERIFY_CA&ssl-ca="
858+
+ conn_str_ca;
858859

859860
local_sess = mysqlx_get_session_from_url(
860861
conn_str.c_str(),
@@ -873,7 +874,7 @@ TEST_F(xapi, conn_string_test)
873874
*/
874875

875876
{
876-
std::string conn_str = conn_str_basic + "?ssl-ca=wrong_ca.pem";
877+
std::string conn_str = conn_str_basic + "?ssl-mode=VERIFY_CA&ssl-ca=wrong_ca.pem";
877878

878879
local_sess = mysqlx_get_session_from_url(
879880
conn_str.c_str(),
@@ -1263,30 +1264,15 @@ TEST_F(xapi, conn_options_test)
12631264
{
12641265
mysqlx_session_options_t *opt2 = mysqlx_session_options_new();
12651266

1266-
EXPECT_EQ(RESULT_OK, mysqlx_session_option_set(opt2,
1267+
EXPECT_EQ(RESULT_ERROR, mysqlx_session_option_set(opt2,
12671268
OPT_SSL_CA(ca.c_str()), PARAM_END
12681269
));
1269-
12701270
/*
1271-
If ssl-ca is set without setting ssl-mode, the latter defaults
1272-
to VERIFY_CA.
1271+
If ssl-ca is set without setting ssl-mode, the error
1272+
should be returned
12731273
*/
1274-
1275-
unsigned int cur_ssl_mode = SSL_MODE_DISABLED;
1276-
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt2,
1277-
MYSQLX_OPT_SSL_MODE, &cur_ssl_mode
1278-
));
1279-
EXPECT_EQ(SSL_MODE_VERIFY_CA, cur_ssl_mode);
1280-
1281-
for (unsigned i = 0; i < 2; ++i)
1282-
{
1283-
EXPECT_EQ(RESULT_ERROR, mysqlx_session_option_set(opt2,
1284-
OPT_SSL_MODE(i > 0 ? SSL_MODE_DISABLED : SSL_MODE_REQUIRED),
1285-
PARAM_END
1286-
));
1287-
cout << "Expected error: "
1288-
<< mysqlx_error_message(mysqlx_error(opt2)) << std::endl;
1289-
}
1274+
cout << "Expected error: "
1275+
<< mysqlx_error_message(mysqlx_error(opt2)) << std::endl;
12901276

12911277
mysqlx_free_options(opt2);
12921278
}
@@ -1299,8 +1285,7 @@ TEST_F(xapi, conn_options_test)
12991285

13001286
{
13011287
/*
1302-
Check that setting SSL_CA also sets SSL_MODE to VERIFY_CA. Since we set
1303-
SSL_CA to wrong file, the connection should fail.
1288+
Since we set SSL_CA to wrong file, the connection should fail.
13041289
*/
13051290

13061291
mysqlx_session_options_t *opt1 = mysqlx_session_options_new();
@@ -1310,6 +1295,7 @@ TEST_F(xapi, conn_options_test)
13101295
OPT_USER(m_xplugin_usr),
13111296
OPT_PWD(m_xplugin_pwd),
13121297
OPT_PORT(m_port),
1298+
OPT_SSL_MODE(SSL_MODE_VERIFY_CA),
13131299
OPT_SSL_CA("wrong_ca.pem"),
13141300
PARAM_END
13151301
));

0 commit comments

Comments
 (0)