Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: How to set x509 on a QSqlDatabase Connection?

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set x509 on a QSqlDatabase Connection?

    Can we see complete code of yours used for establishing the connection using mysql_ssl_set?

    Ok, I have analyzed Qt's code regarding connecting to MySql. With current implementation you won't be able to call mysql_ssl_set between mysql_init and mysql_real_connect. You should probably report it as a bug. mysql_init() should be called earlier (probably as a result to QSqlDatabase::addDatabase()) so that one can manipulate the structure before opening the connection.
    Last edited by wysota; 3rd January 2012 at 13:17.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #22
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to set x509 on a QSqlDatabase Connection?

    Wow beyond expectation, I like you will-never-give-up mentality! Of course I will post my code. Be it tomorrow - having guests now...
    Thanks so much!

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set x509 on a QSqlDatabase Connection?

    Before I forget... What I think you should do is that you should either subclass the MySql driver Qt has and reimplement the method for opening the database (which is a bit of work) or you should copy the source code for the plugin, rename the classes and modify the open() routine so that you have the ability to call mysql_ssl_set between mysql_init and mysql_real_connect. Then you can build the new plugin --- either as a plugin (and then deploy it in the proper directory) or as part of your application (and then call QSqlDatabase::registerSqlDriver() to register it). Of course these are only workarounds, the real solution is to modify Qt's MySql driver directly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to set x509 on a QSqlDatabase Connection?

    I have dug deeper into plugins and "all" there is to do to make it work... seems to me like a nice project for Nokia, or for me in a somewhat quite week. You are right, QSqlDriver should be programmed for more flexibility. Is Nokia reading this?
    Thanks for all the help.

  5. #25
    Join Date
    Feb 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set x509 on a QSqlDatabase Connection?

    Hi!
    I looked into the code of mysql driver and QSqlDatabase to make sure that mysql_real_connect() is executed only in the driver->open() function and not before.
    So, I used this code to connect to the DB:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. QVariant v = db.driver()->handle();
    3. if (v.isValid() && qstrcmp(v.typeName(), "MYSQL*")==0)
    4. {
    5. MYSQL *handle = static_cast<MYSQL *>(v.data());
    6. if (handle != NULL)
    7. {
    8. mysql_ssl_set(handle, "client-key.pem",
    9. "client-cert.pem", "ca-cert.pem",
    10. NULL, "DHE-RSA-AES256-SHA");
    11. }
    12. }
    13.  
    14. db.setHostName(settings.value("database/host").toString());
    15. db.setDatabaseName(settings.value("database/databaseName").toString());
    16. db.setUserName(settings.value("database/userName").toString());
    17. db.setPassword(crypto.decryptToString(settings.value("database/password").toString()));
    18. db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
    19. db.open();
    To copy to clipboard, switch view to plain text mode 
    Well, it works somehow. First, I had problems with certs on the side of the server (at first, apparmor blocked the access to the cert files, then this problem occured. So, the last time I generated the new certs by tinyca, exported it to zip (key+cert), then removed the pass from the key, and only then it finally works.
    The user is set up with REQUIRE SSL option, for some reason the server doesn't accept the user when REQUIRE X509 is selected. The strange thing - it connects even when i change all the parameters to NULL. If I call "mysql --ssl -u test -h 192.168.1.8 -p" it does not authorize.
    Server runs on Ubuntu Server 11.10, client - on Mint 12, Qt version 4.7.4, MySQL - 5.1.58-1ubuntu1, OpenSSL 1.0.0e.
    Last edited by aleyer; 21st February 2012 at 04:36.

Similar Threads

  1. Replies: 0
    Last Post: 18th September 2011, 08:58
  2. QSqlDatabase Connection Close on Destruction
    By Sanuden in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2011, 15:32
  3. QSqlDatabase connection timeout?
    By joseprl89 in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2011, 01:43
  4. QSqlDatabase PSQL connection options
    By leknarf in forum Qt Programming
    Replies: 0
    Last Post: 17th March 2010, 16:06
  5. Replies: 3
    Last Post: 22nd June 2006, 16:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.