SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

Added handling of ssl_mode connection parameter to MySQL session #1104

Closed willw-git closed 6 months ago

willw-git commented 7 months ago

This PR allows SOCI users to pass the ssl-mode parameter described here when connecting to a MySQL database. The setting is passed as ssl_mode, with its value set to one of the name constants given in the above documentation: DISABLED, PREFERRED, REQUIRED, VERIFY_CA and VERIFY_IDENTITY. Used like this:

auto connection_str = "host=localhost db=mydb user=fred pass='12345' ssl_mode=DISABLED";
session sql(mysql, connection_str);

This patch implies that the documentation at https://soci.sourceforge.net/doc/master/backends/mysql/ needs to be fixed to include this parameter and its possible values.

Motivation: I found that a 32-bit client could not connect to a server, even though the server permitted unencrypted connections. The error returned was 2026. I believe this is because the default value of this parameter is PREFERRED, which implies that TLS protocol negotiations are initiated. Because the 32-bit client is no longer maintained, these fail - and no connection is made. The solution is to turn off SSL entirely (if the security situation permits it).

Of course, the parameter is also generally useful.

vadz commented 7 months ago

Oh, and you need to look into whether we can use mysql_options() instead of the deprecated function resulting in CI errors. If we can't, the warning would need to be disabled.

vadz commented 6 months ago

Thanks for the update, (squash) merged now!