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' #2

Open
swapniil opened this issue Mar 13, 2018 · 0 comments
Open

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

swapniil opened this issue Mar 13, 2018 · 0 comments

Comments

@swapniil
Copy link

swapniil commented Mar 13, 2018

I was trying to setup sha256_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 here are 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.

Please update on it if I'm doing anything wrong in the code below:

bool
connect_with_sha256_to_db(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, "DHE-RSA-AES256-SHA")) {
        printf("Real connect: %d:\n", errno);
        printf("Real connect: %d: %s\n", drvr->errnum(), drvr->error());
        return false;
    }
    if (conn.connect("mysql", "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