PDA

View Full Version : Changing QTcpServer to SSL Server



nnead
27th July 2014, 13:28
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:


#include "myserver.h"

myServer::myServer(QObject *parent) :
QTcpServer(parent)
{
}

void myServer::startServer()
{
if(listen(QHostAddress::Any,1234))
{
qDebug()<< "Server online";
}
else
{
qDebug() << "Server offline";
}
}

void myServer::incomingConnection(qintptr handle)
{
myClient *client = new myClient(this);
client->setSocket(handle);

connect(client,SIGNAL(client_done()),this,SLOT(don e()));

}

void myServer::done()
{
qDebug() << "Refresh";
emit refreshing();
}


client:


#include "myclient.h"
#include <iostream>
#include <fstream>
#include <string>
#include <QFile>
#include <QTextStream>

using namespace std;

myClient::myClient(QObject *parent) :
QObject(parent)
{
socket = new QTcpSocket(this);
socket->connectToHost("192.168.1.109", 1234);

qDebug() << "Connected to Server";
}

void myClient::sendSocket()
{
string line;

ifstream myfile ("send.txt");
if (myfile.is_open())
{
while (getline (myfile,line))
{
if( socket->waitForConnected() )
{
socket->write(line.c_str());
qDebug() << QString::fromStdString(line);
socket->write("\n");
}

}
myfile.close();
}

qDebug() << "Data transfere completed";
}

anda_skoa
27th July 2014, 17:03
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,
_

nnead
27th July 2014, 17:38
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.

anda_skoa
27th July 2014, 17:54
Looks like the OpenSSL library is not found or not installed

Cheers,
_

nnead
27th July 2014, 18:17
I have just reinstalled OpenSSL for Win but the error is the same :(

anda_skoa
27th July 2014, 19:55
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,
_

nnead
2nd August 2014, 01:28
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

ChrisW67
2nd August 2014, 23:13
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).