PDA

View Full Version : Problem with connecting to MySql using SSL



moosa
18th October 2010, 22:40
Hi,

I am trying to connect MySql database using an SSL connection. Connecting without SSL works fine.

I created a database and a user with REQUIRE SSL option. When I try to connect I get: "SSL connection error QMYSQL: Unable to connect".

I am using Qt 4.7 64 bit on Ubuntu 10.04

The code looks like the following:



QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", m_connName);
if (!db.isValid())
{
return;
}
db.setDatabaseName(dbName);
db.setHostName("localhost");
db.setPort(3306);
db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
if (!db.open(userName, password))
{
qDebug()<<db.lastError().text();
return;
}


Was anyone able to work using this setup before?

Thank you

foxyproxy
19th October 2010, 08:36
I guess you have to configure server to support SSL (SSL permission on account, ciphers, certificate,etc.). You can read more here http://dev.mysql.com/doc/refman/5.0/en/secure-connections.html

Jarvis
25th July 2011, 02:49
In the other hand, client-side shoud be set up too :



db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
QVariant v = db.driver()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "MYSQL*")==0)
{
MYSQL *handle = static_cast<MYSQL *>(v.data());
if (handle != NULL)
{
mysql_ssl_set(handle, "./ssl/client-key.pem",
"./ssl/client-cert.pem", "./ssl/cacert.pem",
NULL, NULL);
}
}
db.open();



Refer to mysql_ssl_set() (http://dev.mysql.com/doc/refman/5.0/fr/mysql-ssl-set.html) for details.