Results 1 to 6 of 6

Thread: QSslSocket toggle certificates

  1. #1
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QSslSocket toggle certificates

    Hi

    I've got one question. I have to write some code with SSL communication, but there is one big problem. I've got few different certificates and privates keys. I can get correct certificate after I receive from client some important info. After that I chose correct certificate, private key and start socket encryption.

    on server side I have

    Qt Code:
    1. QSslSocket* pSocket = new QSslSocket(this);
    2. pSocket->setSocketDescriptor(m_nextSocketDesc);
    3. pSocket->startServerEncryption();
    To copy to clipboard, switch view to plain text mode 

    on client side
    Qt Code:
    1. m_pSslSocket->connectToHost(address, port);
    To copy to clipboard, switch view to plain text mode 

    I was thinking, that after i receive some info i just add correct certificate and start client encryption.
    But after client connects to server, server immediately disconnects client and emits errors;
    Any suggestions?

  2. #2
    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: QSslSocket toggle certificates

    Shouldn't you be calling connectToHostEncrypted() on the client if the server starts encryption immediately after receiving the connection?
    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.


  3. #3
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket toggle certificates

    Yes, it works with connectToHostEncrypted() on the client, but only when server is configured with some certificate and key.
    But still it is not solution for my problem. I need to divide communication to unsecured mode and secured mode. In first step i received some info and after that I need to toggle to secure mode. But all communication should be on the same connection.

    On the first step I want to connect without encryption
    Qt Code:
    1. m_pSslSocket->connectToHost(address, port);
    To copy to clipboard, switch view to plain text mode 
    and after a while toggle client to encryption
    Qt Code:
    1. m_pSslSocket->startClientEncryption();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: QSslSocket toggle certificates

    Quote Originally Posted by raszewski View Post
    I need to divide communication to unsecured mode and secured mode.
    So don't call startServerEncryption() immediately.
    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.


  5. #5
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket toggle certificates

    It should works. But what should I used instead of startServerEncryption() ? QTcpServer->addPendingConnection(pSslSocket)?

  6. #6
    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: QSslSocket toggle certificates

    You don't have to do anything. The moment you set the socket descriptor on Qt's socket, you're ready to read/write data to it. Once you know all the details required to establish encryption, call startServerEncryption().
    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.


  7. The following user says thank you to wysota for this useful post:

    raszewski (30th November 2012)

Similar Threads

  1. SSLServer + certificates
    By eleanor in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2016, 20:09
  2. Qt getting client certificates from OS certificate store.
    By sargsyan.taron in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 16:39
  3. Getting p12 certificates already installed in system.
    By sargsyan.taron in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2011, 16:25
  4. Replies: 1
    Last Post: 5th October 2009, 16:40
  5. SSL handshaking without certificates
    By palas in forum Qt Programming
    Replies: 6
    Last Post: 5th August 2008, 22:46

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.