Encrypted connection support failure with error 'access denied'
I was trying to setup caching_sha2_password authentication login using this library and I was always getting "1045: access denied" error. I tried to build a sample application using naked C API "building mysql client library with ssl support" I worked fine for me. So I debugged the source and find out an issue that causes this error.
In function 'DBDriver::connect_prepare' file lib/dbdriver.cpp:109 there is a call to 'mysql_init(&mysql_);'
This call actually resets all the memory on which we enabled the ssl using 'DBDriver::enable_ssl'. I have commented out this call from there and moved it to 'DBDriver::enable_ssl' function call. This patch is working fine for me. Not sure whether this is fixing it or has some other issues get popped with this change. This patch is like working for SSL based connection only. For plain authentication it probably not going to work.
Please update on it if I'm doing anything wrong in the code below:
bool
caching_sha2_password(mysqlpp::Connection& conn) {
mysqlpp::DBDriver* drvr = conn.driver();
//key, cert, ca, capath, cipher
if (!drvr->enable_ssl("/etc/mysql-ssl/client-key.pem", "/etc/mysql-ssl/client-cert.pem", "/etc/mysql-ssl/ca-cert.pem", NULL, NULL)) {
printf("Real connect: %d:\n", errno);
printf("Real connect: %d: %s\n", drvr->errnum(), drvr->error());
return false;
}
if (conn.connect("test_db", "127.0.0.1", "user", "shapcli123")) {
printf("Connected: %d: %s\n", drvr->errnum(), drvr->error());
return true;
}
std::cout<<std::endl<<__LINE__<<"Connection refused"<<std::endl;
printf("Not Connected: %d: %s\n", drvr->errnum(), drvr->error());
return false;
}