I wrote that code:
Server:
//H
#ifndef POLACZENIESSL_H
#define POLACZENIESSL_H
#include <QTcpServer>
#include <QTcpSocket>
#include <QSslSocket>
#include <QFile>
#include <QSslKey>
#include <QAbstractSocket>
{
Q_OBJECT
public:
PolaczenieSSL
(QWidget *parent
= 0);
~PolaczenieSSL();
private:
void incomingConnection(int port);
private slots:
void gotowy();
};
#endif // POLACZENIESSL_H
//CPP
#include "polaczeniessl.h"
PolaczenieSSL
::PolaczenieSSL(QWidget *parent
){
}
PolaczenieSSL::~PolaczenieSSL()
{
}
void PolaczenieSSL::incomingConnection(int port)
{
qDebug()<<"incomingConnection";
QSslSocket *serverSocket = new QSslSocket;
serverSocket->setProtocol(QSsl::AnyProtocol);
serverSocket->ignoreSslErrors();
QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
serverSocket->setPrivateKey(key);
serverSocket->setLocalCertificate("server.csr");
serverSocket->addCaCertificates("/etc/ssl/certs");
if (serverSocket->setSocketDescriptor(port))
{
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
serverSocket->startServerEncryption();
qDebug()<<serverSocket->errorString();
}
else
{
delete serverSocket;
}
}
void PolaczenieSSL::gotowy()
{
qDebug()<<"gotowy";
}
//H
#ifndef POLACZENIESSL_H
#define POLACZENIESSL_H
#include <QTcpServer>
#include <QTcpSocket>
#include <QSslSocket>
#include <QFile>
#include <QSslKey>
#include <QAbstractSocket>
class PolaczenieSSL : public QTcpServer
{
Q_OBJECT
public:
PolaczenieSSL(QWidget *parent = 0);
~PolaczenieSSL();
private:
void incomingConnection(int port);
private slots:
void gotowy();
};
#endif // POLACZENIESSL_H
//CPP
#include "polaczeniessl.h"
PolaczenieSSL::PolaczenieSSL(QWidget *parent)
{
}
PolaczenieSSL::~PolaczenieSSL()
{
}
void PolaczenieSSL::incomingConnection(int port)
{
qDebug()<<"incomingConnection";
QSslSocket *serverSocket = new QSslSocket;
serverSocket->setProtocol(QSsl::AnyProtocol);
serverSocket->ignoreSslErrors();
QFile *file = new QFile("server.key");
QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
serverSocket->setPrivateKey(key);
serverSocket->setLocalCertificate("server.csr");
serverSocket->addCaCertificates("/etc/ssl/certs");
if (serverSocket->setSocketDescriptor(port))
{
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
serverSocket->startServerEncryption();
qDebug()<<serverSocket->errorString();
}
else
{
delete serverSocket;
}
}
void PolaczenieSSL::gotowy()
{
qDebug()<<"gotowy";
}
To copy to clipboard, switch view to plain text mode
On console, when client started connection:
incomingConnection
"Unknown error"
incomingConnection
"Unknown error"
To copy to clipboard, switch view to plain text mode
What is it wrong?
Bookmarks