diff options
| author | myuzhobcplidtkieno <62526817+myuzhobcplidtkieno@users.noreply.github.com> | 2020-04-08 08:08:28 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-07 22:08:28 +0200 |
| commit | ae553f89664a4baade80020856c9ff66323de963 (patch) | |
| tree | 69b7dda1d45450008c237bcd39a63bc471ec7c0c /src/server/database/Database | |
| parent | dcd2ffdaf4c358dbbab7915ab744871e5a7cc4ad (diff) | |
Added the ability to use TLS when connecting to a database. (#24348)
* Added the ability to use TLS when connecting to a database.
* Trying to kickstart CI checks
* Revert the kickstart change
Co-authored-by: myuzhobcplidtkieno <myuzhobcplidtkieno@github.com>
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
Diffstat (limited to 'src/server/database/Database')
| -rw-r--r-- | src/server/database/Database/MySQLConnection.cpp | 15 | ||||
| -rw-r--r-- | src/server/database/Database/MySQLConnection.h | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/server/database/Database/MySQLConnection.cpp b/src/server/database/Database/MySQLConnection.cpp index 8205b70f38d..62876bacbba 100644 --- a/src/server/database/Database/MySQLConnection.cpp +++ b/src/server/database/Database/MySQLConnection.cpp @@ -34,7 +34,7 @@ MySQLConnectionInfo::MySQLConnectionInfo(std::string const& infoString) { Tokenizer tokens(infoString, ';'); - if (tokens.size() != 5) + if (tokens.size() != 5 && tokens.size() != 6) return; uint8 i = 0; @@ -44,6 +44,9 @@ MySQLConnectionInfo::MySQLConnectionInfo(std::string const& infoString) user.assign(tokens[i++]); password.assign(tokens[i++]); database.assign(tokens[i++]); + + if (tokens.size() == 6) + ssl.assign(tokens[i++]); } MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) : @@ -129,6 +132,16 @@ uint32 MySQLConnection::Open() } #endif + if (m_connectionInfo.ssl != "") + { + my_bool opt_use_ssl = false; + if (m_connectionInfo.ssl == "ssl") + { + opt_use_ssl = true; + } + mysql_options(mysqlInit, MYSQL_OPT_SSL_ENFORCE, (char const*)&opt_use_ssl); + } + m_Mysql = reinterpret_cast<MySQLHandle*>(mysql_real_connect(mysqlInit, m_connectionInfo.host.c_str(), m_connectionInfo.user.c_str(), m_connectionInfo.password.c_str(), m_connectionInfo.database.c_str(), port, unix_socket, 0)); diff --git a/src/server/database/Database/MySQLConnection.h b/src/server/database/Database/MySQLConnection.h index e4368db44ba..ea41ce3e0aa 100644 --- a/src/server/database/Database/MySQLConnection.h +++ b/src/server/database/Database/MySQLConnection.h @@ -49,6 +49,7 @@ struct TC_DATABASE_API MySQLConnectionInfo std::string database; std::string host; std::string port_or_socket; + std::string ssl; }; class TC_DATABASE_API MySQLConnection |
