Skip to content

Commit 9c47486

Browse files
committed
Merge branch 'wl14846-jdbc' into jdbc
2 parents 46df142 + 0b33f3e commit 9c47486

File tree

4 files changed

+143
-35
lines changed

4 files changed

+143
-35
lines changed

cppconn/connection.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@
6868
/*
6969
SSL related
7070
*/
71-
#define OPT_SSL_MODE "OPT_SSL_MODE"
72-
#define OPT_SSL_KEY "sslKey"
73-
#define OPT_SSL_CERT "sslCert"
74-
#define OPT_SSL_CA "sslCA"
75-
#define OPT_SSL_CAPATH "sslCAPath"
76-
#define OPT_SSL_CIPHER "sslCipher"
77-
#define OPT_SSL_CRL "sslCRL"
78-
#define OPT_SSL_CRLPATH "sslCRLPath"
71+
#define OPT_SSL_MODE "ssl-mode"
72+
#define OPT_SSL_KEY "ssl-key"
73+
#define OPT_SSL_CERT "ssl-cert"
74+
#define OPT_SSL_CA "ssl-ca"
75+
#define OPT_SSL_CAPATH "ssl-capath"
76+
#define OPT_SSL_CIPHER "ssl-cipher"
77+
#define OPT_SSL_CRL "ssl-crl"
78+
#define OPT_SSL_CRLPATH "ssl-crlpath"
7979
#define OPT_SERVER_PUBLIC_KEY "rsaKey"
80-
#define OPT_TLS_VERSION "OPT_TLS_VERSION"
80+
#define OPT_TLS_VERSION "tls-version"
8181

8282
/*
8383
Connection related

driver/mysql_connection.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ static const String2IntMap intOptions[]=
291291
{OPT_NET_BUFFER_LENGTH, MYSQL_OPT_NET_BUFFER_LENGTH, false},
292292
#endif
293293
{OPT_SSL_MODE, MYSQL_OPT_SSL_MODE , false},
294+
{"OPT_SSL_MODE", MYSQL_OPT_SSL_MODE , false},
294295
#if MYCPPCONN_STATIC_MYSQL_VERSION_ID >= 80000
295296
{OPT_RETRY_COUNT, MYSQL_OPT_RETRY_COUNT, false},
296297
#endif
@@ -305,7 +306,9 @@ static const String2IntMap stringOptions[]=
305306
{OPT_SSL_CAPATH, MYSQL_OPT_SSL_CAPATH, true},
306307
{OPT_SSL_CIPHER, MYSQL_OPT_SSL_CIPHER, true},
307308
{OPT_SSL_CRL, MYSQL_OPT_SSL_CRL, false},
309+
{"sslCRL", MYSQL_OPT_SSL_CRL, false},
308310
{OPT_SSL_CRLPATH, MYSQL_OPT_SSL_CRLPATH, false},
311+
{"sslCRLPath", MYSQL_OPT_SSL_CRLPATH, false},
309312
{OPT_SERVER_PUBLIC_KEY, MYSQL_SERVER_PUBLIC_KEY, false},
310313
{OPT_SET_CHARSET_DIR, MYSQL_SET_CHARSET_DIR, false},
311314
{OPT_PLUGIN_DIR, MYSQL_PLUGIN_DIR, false},
@@ -316,6 +319,7 @@ static const String2IntMap stringOptions[]=
316319
{OPT_CHARSET_NAME, MYSQL_SET_CHARSET_NAME, true},
317320
#if MYCPPCONN_STATIC_MYSQL_VERSION_ID >= 50700
318321
{OPT_TLS_VERSION, MYSQL_OPT_TLS_VERSION, true},
322+
{"OPT_TLS_VERSION", MYSQL_OPT_TLS_VERSION, true},
319323
#endif
320324
{OPT_LOAD_DATA_LOCAL_DIR, MYSQL_OPT_LOAD_DATA_LOCAL_DIR, false}
321325
};
@@ -708,67 +712,67 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
708712
} else {
709713
throw sql::InvalidArgumentException("No string value passed for characterSetResults");
710714
}
711-
} else if (!it->first.compare(OPT_SSL_KEY)) {
715+
} else if (!it->first.compare(OPT_SSL_KEY) || !it->first.compare("sslKey")) {
712716
try {
713717
p_s = (it->second).get< sql::SQLString >();
714718
} catch (sql::InvalidArgumentException&) {
715-
throw sql::InvalidArgumentException("Wrong type passed for sslKey expected sql::SQLString");
719+
throw sql::InvalidArgumentException("Wrong type passed for ssl-key expected sql::SQLString");
716720
}
717721
if (p_s) {
718722
sslKey = *p_s;
719723
} else {
720-
throw sql::InvalidArgumentException("No string value passed for sslKey");
724+
throw sql::InvalidArgumentException("No string value passed for ssl-key");
721725
}
722726
ssl_used = true;
723-
} else if (!it->first.compare(OPT_SSL_CERT)) {
727+
} else if (!it->first.compare(OPT_SSL_CERT) || !it->first.compare("sslCert")) {
724728
try {
725729
p_s = (it->second).get< sql::SQLString >();
726730
} catch (sql::InvalidArgumentException&) {
727-
throw sql::InvalidArgumentException("Wrong type passed for sslCert expected sql::SQLString");
731+
throw sql::InvalidArgumentException("Wrong type passed for ssl-cert expected sql::SQLString");
728732
}
729733
if (p_s) {
730734
sslCert = *p_s;
731735
} else {
732-
throw sql::InvalidArgumentException("No string value passed for sslCert");
736+
throw sql::InvalidArgumentException("No string value passed for ssl-cert");
733737
}
734738
ssl_used = true;
735-
} else if (!it->first.compare(OPT_SSL_CA)) {
739+
} else if (!it->first.compare(OPT_SSL_CA) || !it->first.compare("sslCA") ) {
736740
try {
737741
p_s = (it->second).get< sql::SQLString >();
738742
} catch (sql::InvalidArgumentException&) {
739-
throw sql::InvalidArgumentException("Wrong type passed for sslCA expected sql::SQLString");
743+
throw sql::InvalidArgumentException("Wrong type passed for ssl-ca expected sql::SQLString");
740744
}
741745
if (p_s) {
742746
sslCA = *p_s;
743747
} else {
744-
throw sql::InvalidArgumentException("No string value passed for sslCA");
748+
throw sql::InvalidArgumentException("No string value passed for ssl-ca");
745749
}
746750
ssl_used = true;
747-
} else if (!it->first.compare(OPT_SSL_CAPATH)) {
751+
} else if (!it->first.compare(OPT_SSL_CAPATH) || !it->first.compare("sslCAPath")) {
748752
try {
749753
p_s = (it->second).get< sql::SQLString >();
750754
} catch (sql::InvalidArgumentException&) {
751-
throw sql::InvalidArgumentException("Wrong type passed for sslCAPath expected sql::SQLString");
755+
throw sql::InvalidArgumentException("Wrong type passed for ssl-capath expected sql::SQLString");
752756
}
753757
if (p_s) {
754758
sslCAPath = *p_s;
755759
} else {
756-
throw sql::InvalidArgumentException("No string value passed for sslCAPath");
760+
throw sql::InvalidArgumentException("No string value passed for ssl-capath");
757761
}
758762
ssl_used = true;
759-
} else if (!it->first.compare(OPT_SSL_CIPHER)) {
763+
} else if (!it->first.compare(OPT_SSL_CIPHER) || !it->first.compare("sslCipher")) {
760764
try {
761765
p_s = (it->second).get< sql::SQLString >();
762766
} catch (sql::InvalidArgumentException&) {
763-
throw sql::InvalidArgumentException("Wrong type passed for sslCipher expected sql::SQLString");
767+
throw sql::InvalidArgumentException("Wrong type passed for ssl-cipher expected sql::SQLString");
764768
}
765769
if (p_s) {
766770
sslCipher = *p_s;
767771
} else {
768-
throw sql::InvalidArgumentException("No string value passed for sslCipher");
772+
throw sql::InvalidArgumentException("No string value passed for ssl-cipher");
769773
}
770774
ssl_used = true;
771-
} else if (!it->first.compare(OPT_TLS_VERSION)) {
775+
} else if (!it->first.compare(OPT_TLS_VERSION) || !it->first.compare("OPT_TLS_VERSION")) {
772776
try {
773777
p_s = (it->second).get< sql::SQLString >();
774778
} catch (sql::InvalidArgumentException&) {
@@ -1077,6 +1081,10 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
10771081

10781082
it = properties.find(OPT_SSL_MODE);
10791083

1084+
//Use legacy option
1085+
if(it == properties.end())
1086+
it = properties.find("OPT_SSL_MODE");
1087+
10801088
if (it != properties.end())
10811089
{
10821090
PROCESS_CONN_OPTION(int, intOptions);

test/unit/classes/connection.cpp

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,7 @@ void connection::ssl_mode()
34553455
connection_properties["userName"]=user;
34563456
connection_properties["password"]=passwd;
34573457

3458-
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
3458+
connection_properties[OPT_SSL_MODE] = sql::SSL_MODE_DISABLED;
34593459

34603460
created_objects.clear();
34613461
con.reset(driver->connect(connection_properties));
@@ -3482,7 +3482,7 @@ void connection::ssl_mode()
34823482

34833483
ASSERT_EQUALS(0, static_cast<int>(res->getString(2).length()));
34843484

3485-
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_REQUIRED;
3485+
connection_properties[OPT_SSL_MODE] = sql::SSL_MODE_REQUIRED;
34863486

34873487
try
34883488
{
@@ -3510,12 +3510,12 @@ void connection::ssl_mode()
35103510
connection_properties["userName"]="ssluser";
35113511
connection_properties["password"]="sslpass";
35123512

3513-
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_REQUIRED;
3513+
connection_properties[OPT_SSL_MODE] = sql::SSL_MODE_REQUIRED;
35143514

35153515
created_objects.clear();
35163516
con.reset(driver->connect(connection_properties));
35173517

3518-
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
3518+
connection_properties[OPT_SSL_MODE] = sql::SSL_MODE_DISABLED;
35193519

35203520
//only to trigger setssl which changes SSL_MODE
35213521
connection_properties["sslCA"] = "invalid_path";
@@ -3543,7 +3543,7 @@ void connection::tls_version()
35433543
connection_properties["userName"]=user;
35443544
connection_properties["password"]=passwd;
35453545

3546-
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
3546+
connection_properties[OPT_SSL_MODE] = sql::SSL_MODE_DISABLED;
35473547

35483548
created_objects.clear();
35493549
con.reset(driver->connect(connection_properties));
@@ -3570,10 +3570,10 @@ void connection::tls_version()
35703570
tls_versions.push_back(tls_available.substr(begin_pos, end_pos-begin_pos));
35713571
}
35723572

3573-
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_REQUIRED;
3573+
connection_properties[OPT_SSL_MODE] = sql::SSL_MODE_REQUIRED;
35743574

35753575
// Using ALL TLS version... should connect
3576-
connection_properties["OPT_TLS_VERSION"] = tls_available;
3576+
connection_properties[OPT_TLS_VERSION] = tls_available;
35773577

35783578
created_objects.clear();
35793579
try
@@ -3588,7 +3588,7 @@ void connection::tls_version()
35883588

35893589

35903590
// Using wrong TLS version... should fail to connect
3591-
connection_properties["OPT_TLS_VERSION"] = sql::SQLString("TLSv999");
3591+
connection_properties[OPT_TLS_VERSION] = sql::SQLString("TLSv999");
35923592

35933593
created_objects.clear();
35943594
try
@@ -3608,7 +3608,7 @@ void connection::tls_version()
36083608
version != tls_versions.end();
36093609
++version)
36103610
{
3611-
connection_properties["OPT_TLS_VERSION"] = sql::SQLString(*version);
3611+
connection_properties[OPT_TLS_VERSION] = sql::SQLString(*version);
36123612

36133613
created_objects.clear();
36143614
try
@@ -3656,7 +3656,7 @@ void connection::cached_sha2_auth()
36563656
opts["userName"] = "doomuser";
36573657
opts["password"] = "!sha2user_pass";
36583658
opts["OPT_GET_SERVER_PUBLIC_KEY"] = false;
3659-
opts["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
3659+
opts[OPT_SSL_MODE] = sql::SSL_MODE_DISABLED;
36603660

36613661
try {
36623662

@@ -4163,5 +4163,98 @@ void connection::fido_test()
41634163
std::cout << "Success\n";
41644164
}
41654165

4166+
4167+
//Test if ssl is enabled using cipher
4168+
auto check_ssl_impl = [](std::shared_ptr<sql::Connection> sess, bool enable, int line)
4169+
{
4170+
std::unique_ptr<sql::Statement> stmt(sess->createStatement());
4171+
std::unique_ptr<sql::ResultSet> res(stmt->executeQuery("SHOW STATUS LIKE 'Ssl_cipher'"));
4172+
4173+
res->next();
4174+
std::cout << "Line "<< line << ": " << res->getString(1) << ":" << res->getString(2) << std::endl;
4175+
4176+
std::string cipher = res->getString(2);
4177+
4178+
ASSERT_EQUALS(enable, !cipher.empty());
4179+
};
4180+
4181+
#define check_ssl(x,y) check_ssl_impl(x, y, __LINE__)
4182+
4183+
4184+
void connection::normalize_ssl_options()
4185+
{
4186+
4187+
std::vector<std::string> options =
4188+
{
4189+
OPT_SSL_MODE,
4190+
OPT_SSL_CA,
4191+
OPT_SSL_CAPATH,
4192+
OPT_SSL_CRL,
4193+
OPT_SSL_CRLPATH,
4194+
OPT_TLS_VERSION,
4195+
"sslKey",
4196+
"sslCert",
4197+
"sslCA",
4198+
"sslCAPath",
4199+
"sslCipher",
4200+
"sslCRL",
4201+
"sslCRLPath",
4202+
"rsaKey",
4203+
"OPT_SSL_MODE",
4204+
"OPT_TLS_VERSION"
4205+
};
4206+
4207+
for(auto &opt : options)
4208+
{
4209+
{
4210+
std::cout << "Option: " << opt << std::endl;
4211+
4212+
sql::ConnectOptionsMap sess_opt;
4213+
4214+
if(opt == "OPT_SSL_MODE" || opt == OPT_SSL_MODE)
4215+
{
4216+
sess_opt[opt]=sql::SSL_MODE_DISABLED;
4217+
}
4218+
else
4219+
{
4220+
sess_opt[opt] ="BAD";
4221+
sess_opt[opt] ="GOOD";
4222+
sess_opt[OPT_SSL_MODE]=sql::SSL_MODE_DISABLED;
4223+
}
4224+
4225+
4226+
std::shared_ptr<sql::Connection> s(getConnection(&sess_opt));
4227+
check_ssl(s, false);
4228+
4229+
if(opt != "OPT_SSL_MODE" && opt != OPT_SSL_MODE)
4230+
ASSERT_EQUALS("GOOD", sess_opt[opt].get<std::string>());
4231+
}
4232+
4233+
}
4234+
4235+
//Defined Twice. Last one wins
4236+
{
4237+
sql::ConnectOptionsMap sess_opt;
4238+
4239+
sess_opt[OPT_SSL_MODE] = sql::SSL_MODE_DISABLED;
4240+
sess_opt[OPT_SSL_MODE] = sql::SSL_MODE_REQUIRED;
4241+
4242+
std::shared_ptr<sql::Connection> s(getConnection(&sess_opt));
4243+
check_ssl(s, true);
4244+
}
4245+
{
4246+
sql::ConnectOptionsMap sess_opt;
4247+
4248+
sess_opt[OPT_SSL_MODE] = sql::SSL_MODE_REQUIRED;
4249+
sess_opt[OPT_SSL_MODE] = sql::SSL_MODE_DISABLED;
4250+
4251+
std::shared_ptr<sql::Connection> s(getConnection(&sess_opt));
4252+
check_ssl(s, false);
4253+
}
4254+
4255+
}
4256+
4257+
4258+
41664259
} /* namespace connection */
41674260
} /* namespace testsuite */

test/unit/classes/connection.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class connection : public unit_fixture
9797
TEST_CASE(mfa);
9898
TEST_CASE(tls_deprecation);
9999
TEST_CASE(fido_test);
100+
TEST_CASE(normalize_ssl_options);
100101
}
101102

102103
/**
@@ -301,6 +302,12 @@ class connection : public unit_fixture
301302
*/
302303
void tls_deprecation();
303304

305+
/*
306+
* Test of MySQL_Connection::normalize_ssl_options()
307+
*
308+
*/
309+
void normalize_ssl_options();
310+
304311
/*
305312
* Test for checking fido connection.
306313
*

0 commit comments

Comments
 (0)