Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handling of ssl_mode connection parameter to MySQL session #1104

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/backends/mysql/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ void parse_connect_string(const string & connectString,
string *charset, bool *charset_p, bool *reconnect_p,
unsigned int *connect_timeout, bool *connect_timeout_p,
unsigned int *read_timeout, bool *read_timeout_p,
unsigned int *write_timeout, bool *write_timeout_p)
unsigned int *write_timeout, bool *write_timeout_p,
unsigned int *ssl_mode, bool *ssl_mode_p)
{
*host_p = false;
*user_p = false;
Expand All @@ -217,6 +218,7 @@ void parse_connect_string(const string & connectString,
*connect_timeout_p = false;
*read_timeout_p = false;
*write_timeout_p = false;
*ssl_mode_p = false;
string err = "Malformed connection string.";
string::const_iterator i = connectString.begin(),
end = connectString.end();
Expand Down Expand Up @@ -335,6 +337,15 @@ void parse_connect_string(const string & connectString,
char *endp;
*write_timeout = std::strtoul(val.c_str(), &endp, 10);
*write_timeout_p = true;
} else if (par == "ssl_mode" && !*ssl_mode_p)
{
if (val=="DISABLED") *ssl_mode = SSL_MODE_DISABLED;
else if (val=="PREFERRED") *ssl_mode = SSL_MODE_PREFERRED;
else if (val=="REQUIRED") *ssl_mode = SSL_MODE_REQUIRED;
else if (val=="VERIFY_CA") *ssl_mode = SSL_MODE_VERIFY_CA;
else if (val=="VERIFY_IDENTITY") *ssl_mode = SSL_MODE_VERIFY_IDENTITY;
else throw soci_error(err);
vadz marked this conversation as resolved.
Show resolved Hide resolved
*ssl_mode_p = true;
}
else
{
Expand Down Expand Up @@ -365,18 +376,19 @@ mysql_session_backend::mysql_session_backend(
string host, user, password, db, unix_socket, ssl_ca, ssl_cert, ssl_key,
charset;
int port, local_infile;
unsigned int connect_timeout, read_timeout, write_timeout;
unsigned int connect_timeout, read_timeout, write_timeout, ssl_mode;
bool host_p, user_p, password_p, db_p, unix_socket_p, port_p,
ssl_ca_p, ssl_cert_p, ssl_key_p, local_infile_p, charset_p, reconnect_p,
connect_timeout_p, read_timeout_p, write_timeout_p;
connect_timeout_p, read_timeout_p, write_timeout_p, ssl_mode_p;
parse_connect_string(parameters.get_connect_string(), &host, &host_p, &user, &user_p,
&password, &password_p, &db, &db_p,
&unix_socket, &unix_socket_p, &port, &port_p,
&ssl_ca, &ssl_ca_p, &ssl_cert, &ssl_cert_p, &ssl_key, &ssl_key_p,
&local_infile, &local_infile_p, &charset, &charset_p, &reconnect_p,
&connect_timeout, &connect_timeout_p,
&read_timeout, &read_timeout_p,
&write_timeout, &write_timeout_p);
&write_timeout, &write_timeout_p,
&ssl_mode, &ssl_mode_p);
conn_ = mysql_init(NULL);
if (conn_ == NULL)
{
Expand Down Expand Up @@ -442,6 +454,14 @@ mysql_session_backend::mysql_session_backend(
throw soci_error("mysql_options(MYSQL_OPT_WRITE_TIMEOUT) failed.");
}
}
if (ssl_mode_p)
{
if (0 != mysql_options(conn_, MYSQL_OPT_SSL_MODE, &ssl_mode))
{
clean_up();
throw soci_error("mysql_options(MYSQL_OPT_SSL_MODE) failed.");
}
}
if (mysql_real_connect(conn_,
host_p ? host.c_str() : NULL,
user_p ? user.c_str() : NULL,
Expand Down
Loading