Skip to content

Commit ceefe25

Browse files
committed
Bug#25526187: SSL CONNECTION FAILS WHEN SSL-CA IS SET BUT SSL-ENABLE IS
NOT SET
1 parent 909cf8a commit ceefe25

File tree

2 files changed

+59
-43
lines changed

2 files changed

+59
-43
lines changed

devapi/session.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ struct URI_parser
195195
if (key == "ssl-ca")
196196
{
197197
#ifdef WITH_SSL
198+
m_tls_opt.set_use_tls(true);
198199
m_tls_opt.set_ca(val);
199200
#else
200201
throw_error(

devapi/tests/session-t.cc

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,29 @@ TEST_F(Sess, ssl_session)
358358

359359
SKIP_IF_NO_XPLUGIN;
360360

361+
//Test if ssl is enabled using cipher
362+
auto check_ssl_impl = [](mysqlx::XSession &sess, bool enable, int line)
361363
{
362-
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
363-
SessionSettings::USER,get_user(),
364-
SessionSettings::PWD, get_password() ? get_password() : NULL ,
365-
SessionSettings::SSL_ENABLE, true);
366-
367364
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
368365

369366
auto row = res.fetchOne();
370-
cout << row[0] << ":" << row[1] << endl;
367+
cout << "Line "<< line << ": " << row[0] << ":" << row[1] << endl;
371368

372369
string cipher = row[1];
373370

374-
EXPECT_FALSE(cipher.empty());
371+
EXPECT_EQ(enable, !cipher.empty());
372+
};
373+
374+
#define check_ssl(x,y) check_ssl_impl(x, y, __LINE__)
375+
376+
377+
{
378+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
379+
SessionSettings::USER,get_user(),
380+
SessionSettings::PWD, get_password() ? get_password() : nullptr ,
381+
SessionSettings::SSL_ENABLE, true);
382+
383+
check_ssl(sess, true);
375384
}
376385

377386
{
@@ -380,14 +389,7 @@ TEST_F(Sess, ssl_session)
380389
SessionSettings::PWD, get_password() ? get_password() : nullptr ,
381390
SessionSettings::SSL_ENABLE, false);
382391

383-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
384-
385-
auto row = res.fetchOne();
386-
cout << row[0] << ":" << row[1] << endl;
387-
388-
string cipher = row[1];
389-
390-
EXPECT_TRUE(cipher.empty());
392+
check_ssl(sess, false);
391393
}
392394

393395
//Using URI
@@ -404,31 +406,17 @@ TEST_F(Sess, ssl_session)
404406
//URI without ssl_enable
405407
{
406408
mysqlx::XSession sess(uri.str());
407-
408-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
409-
410-
auto row = res.fetchOne();
411-
cout << row[0] << ":" << row[1] << endl;
412-
413-
string cipher = row[1];
414-
415-
EXPECT_TRUE(cipher.empty());
409+
check_ssl(sess, false);
416410
}
417411

418412

419-
//Enable SSL
420-
uri << "/?ssl-enable";
421413
{
422-
mysqlx::XSession sess(uri.str());
423-
424-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
414+
std::stringstream uri_ssl;
415+
//Enable SSL
416+
uri_ssl << uri.str() << "/?ssl-enable";
425417

426-
auto row = res.fetchOne();
427-
cout << row[0] << ":" << row[1] << endl;
428-
429-
string cipher = row[1];
430-
431-
EXPECT_FALSE(cipher.empty());
418+
mysqlx::XSession sess(uri_ssl.str());
419+
check_ssl(sess, true);
432420
}
433421

434422

@@ -437,7 +425,7 @@ TEST_F(Sess, ssl_session)
437425
EXPECT_THROW(
438426
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
439427
SessionSettings::USER,get_user(),
440-
SessionSettings::PWD, get_password() ? get_password() : NULL ,
428+
SessionSettings::PWD, get_password() ? get_password() : nullptr ,
441429
SessionSettings::SSL_ENABLE, true,
442430
SessionSettings::SSL_CA, "unknown")
443431
, mysqlx::Error);
@@ -448,7 +436,7 @@ TEST_F(Sess, ssl_session)
448436
//using wrong ssl-ca and ssl-ca-path on URI
449437
{
450438
std::stringstream bad_uri;
451-
bad_uri << uri.str() << "&ssl-ca=" << "unknown.file" << "&ssl-ca-path=" << "unknown.path";
439+
bad_uri << uri.str() << "/?ssl-ca=" << "unknown.file";
452440

453441
EXPECT_THROW(mysqlx::XSession sess(bad_uri.str()), mysqlx::Error);
454442
}
@@ -482,19 +470,46 @@ TEST_F(Sess, ssl_session)
482470
ssl_ca = datadir + ssl_ca;
483471
}
484472

485-
uri << "&ssl-ca=" << ssl_ca;
473+
uri << "/?ssl-ca=" << ssl_ca;
486474

487475
{
488476
mysqlx::XSession sess(uri.str());
477+
check_ssl(sess, true);
478+
}
489479

490-
SqlResult res = sess.bindToDefaultShard().sql("SHOW STATUS LIKE 'mysqlx_ssl_cipher'").execute();
480+
//using ssl-enable and ssl-ca as SessionSettings
481+
{
482+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
483+
SessionSettings::USER,get_user(),
484+
SessionSettings::PWD, get_password() ? get_password() : nullptr ,
485+
SessionSettings::SSL_ENABLE, true,
486+
SessionSettings::SSL_CA, ssl_ca);
491487

492-
auto row = res.fetchOne();
493-
cout << row[0] << ":" << row[1] << endl;
488+
check_ssl(sess, true);
494489

495-
string cipher = row[1];
490+
}
491+
492+
//using ssl-ca as SessionSettings
493+
{
494+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
495+
SessionSettings::USER,get_user(),
496+
SessionSettings::PWD, get_password() ? get_password() : nullptr ,
497+
SessionSettings::SSL_CA, ssl_ca);
498+
499+
check_ssl(sess, true);
500+
501+
}
502+
503+
//using ssl-ca but ssl-enable = false on SessionSettings
504+
{
505+
mysqlx::XSession sess(SessionSettings::PORT, get_port(),
506+
SessionSettings::USER,get_user(),
507+
SessionSettings::PWD, get_password() ? get_password() : nullptr ,
508+
SessionSettings::SSL_ENABLE, false,
509+
SessionSettings::SSL_CA, ssl_ca);
510+
511+
check_ssl(sess, false);
496512

497-
EXPECT_FALSE(cipher.empty());
498513
}
499514

500515
//using ssl-enable and ssl-ca as SessionSettings

0 commit comments

Comments
 (0)