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

Encrypted connection support failure with error 'access denied' #11

Open
swapniil opened this issue Nov 12, 2021 · 0 comments
Open

Encrypted connection support failure with error 'access denied' #11

swapniil opened this issue Nov 12, 2021 · 0 comments

Comments

@swapniil
Copy link

swapniil commented Nov 12, 2021

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant