Results 1 to 8 of 8

Thread: Changing QTcpServer to SSL Server

  1. #1
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5

    Default Changing QTcpServer to SSL Server

    Hello, after finishing my server/client project, i am concerned about the security of this system. I will run in an local/closed network which can be accessed via VPN. At the moment everybody can send data to the server via telnet or the written client application.

    Can somebody explain how to upgrade my server/client code to ssl?

    server:
    Qt Code:
    1. #include "myserver.h"
    2.  
    3. myServer::myServer(QObject *parent) :
    4. QTcpServer(parent)
    5. {
    6. }
    7.  
    8. void myServer::startServer()
    9. {
    10. if(listen(QHostAddress::Any,1234))
    11. {
    12. qDebug()<< "Server online";
    13. }
    14. else
    15. {
    16. qDebug() << "Server offline";
    17. }
    18. }
    19.  
    20. void myServer::incomingConnection(qintptr handle)
    21. {
    22. myClient *client = new myClient(this);
    23. client->setSocket(handle);
    24.  
    25. connect(client,SIGNAL(client_done()),this,SLOT(done()));
    26.  
    27. }
    28.  
    29. void myServer::done()
    30. {
    31. qDebug() << "Refresh";
    32. emit refreshing();
    33. }
    To copy to clipboard, switch view to plain text mode 

    client:
    Qt Code:
    1. #include "myclient.h"
    2. #include <iostream>
    3. #include <fstream>
    4. #include <string>
    5. #include <QFile>
    6. #include <QTextStream>
    7.  
    8. using namespace std;
    9.  
    10. myClient::myClient(QObject *parent) :
    11. QObject(parent)
    12. {
    13. socket = new QTcpSocket(this);
    14. socket->connectToHost("192.168.1.109", 1234);
    15.  
    16. qDebug() << "Connected to Server";
    17. }
    18.  
    19. void myClient::sendSocket()
    20. {
    21. string line;
    22.  
    23. ifstream myfile ("send.txt");
    24. if (myfile.is_open())
    25. {
    26. while (getline (myfile,line))
    27. {
    28. if( socket->waitForConnected() )
    29. {
    30. socket->write(line.c_str());
    31. qDebug() << QString::fromStdString(line);
    32. socket->write("\n");
    33. }
    34.  
    35. }
    36. myfile.close();
    37. }
    38.  
    39. qDebug() << "Data transfere completed";
    40. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Changing QTcpServer to SSL Server

    Use QSslsocket instead of QTcpSocket on both sides.

    On the client side, call connecToHostEncrypted() instead of connectToHost().
    On the server side, call startServerEncryption().

    See http://qt-project.org/doc/qt-5/QSslSocket.html#details

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    nnead (27th July 2014)

  4. #3
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5

    Default Re: Changing QTcpServer to SSL Server

    Hi thank you, if i just change mit TcpSocket to SslSocket und the way of connection, my server is giving me this error msg

    QSslSocket: cannot call unresolved function SSLv23_server_method
    QSslSocket: cannot call unresolved function SSL_CTX_new
    QSslSocket: cannot call unresolved function SSL_library_init
    QSslSocket: cannot call unresolved function ERR_get_error
    QSslSocket: cannot call unresolved function ERR_get_error

    when i try to connect via my client.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Changing QTcpServer to SSL Server

    Looks like the OpenSSL library is not found or not installed

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    nnead (27th July 2014)

  7. #5
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5

    Default Re: Changing QTcpServer to SSL Server

    I have just reinstalled OpenSSL for Win but the error is the same
    Last edited by nnead; 27th July 2014 at 18:39.

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Changing QTcpServer to SSL Server

    I am not exactly sure where Qt on Windows is looking for OpenSSL, maybe some of the people using Qt in that platform can help here?

    Cheers,
    _

  9. #7
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5

    Default Re: Changing QTcpServer to SSL Server

    Hi, just wanted to update you guys, i have written a simple encrytion myselfe and protected the server via a password. Its not as secure as ssl but it does the job.
    thanks for the help! this thread can be closed

  10. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,620
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Changing QTcpServer to SSL Server

    Quote Originally Posted by anda_skoa View Post
    I am not exactly sure where Qt on Windows is looking for OpenSSL, maybe some of the people using Qt in that platform can help here?
    Qt will call LoadLibrary to see if the OpenSSL library can be used. Windows will search the program binary folder then the PATH and Windows system directories looking for it (i.e. The standard Windows behaviour).

Similar Threads

  1. QTcpSocket/QTcpServer on a heavy load server
    By Eumcoz in forum Qt Programming
    Replies: 10
    Last Post: 7th August 2012, 19:36
  2. My server (using QTcpServer and QTcpSocket) crashes
    By supergillis in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2010, 15:32
  3. Replies: 1
    Last Post: 21st March 2010, 21:14
  4. Replies: 2
    Last Post: 10th August 2009, 09:45
  5. Replies: 1
    Last Post: 18th June 2006, 10:12

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.