void SslServer::incomingConnection(int socketDescriptor){ QSslSocket *serverSocket=new QSslSocket(this); if(serverSocket->setSocketDescriptor(socketDescriptor)) { QObject::connect(serverSocket, SIGNAL(encrypted()), this, SLOT(socketReady())); QObject::connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(socketSslErrors(const QList<QSslError> &))); QObject::connect(serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError))); serverSocket->startServerEncryption(); } else { delete serverSocket; }}
socket=new QSslSocket(this); QObject::connect(socket, SIGNAL(encrypted()), this, SLOT(socketReady())); QObject::connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(socketSslErrors(const QList<QSslError> &))); QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError))); socket->connectToHostEncrypted(this->serverHost, this->serverPort);
#include "sslserver.h"#include <QSslConfiguration>#include <QFile>SslServer::SslServer(QObject *parent): QTcpServer(parent){}void SslServer::socketReady(){ qDebug("Connected!");}void SslServer::socketSslErrors(const QList<QSslError> &errors){ emit logString(qobject_cast<QSslSocket*>(sender())->errorString(), SSLSERVER_LOG_ERROR);}void SslServer::socketError(QAbstractSocket::SocketError socketError){ emit logString(qobject_cast<QSslSocket*>(sender())->errorString(), SSLSERVER_LOG_ERROR);}void SslServer::incomingConnection(int socketDescriptor){ QSslSocket *serverSocket=new QSslSocket(this); if(serverSocket->setSocketDescriptor(socketDescriptor)) { QSslConfiguration a; QFile *f=new QFile("./RSA/server.crt"); QFile *f1=new QFile("./RSA/server.key"); f->open(QIODevice::ReadWrite); f1->open(QIODevice::ReadWrite); a.setCaCertificates(QSslCertificate::fromDevice(f)); a.setPrivateKey(QSslKey(f1, QSsl::Rsa)); f->close(); f1->close(); serverSocket->setSslConfiguration(a); serverSocket->setCiphers("DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA:EDH-RSA-DES-CBC3-SHA:EDH-DSS-DES-CBC3-SHA:DES-CBC3-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:AES128-SHA:RC4-SHA:RC4-MD5:EDH-RSA-DES-CBC-SHA:EDH-DSS-DES-CBC-SHA:DES-CBC-SHA:EXP-EDH-RSA-DES-CBC-SHA:EXP-EDH-DSS-DES-CBC-SHA:EXP-DES-CBC-SHA:EXP-RC2-CBC-MD5:EXP-RC4-MD5"); QObject::connect(serverSocket, SIGNAL(encrypted()), this, SLOT(socketReady())); QObject::connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(socketSslErrors(const QList<QSslError> &))); QObject::connect(serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError))); serverSocket->startServerEncryption(); } else { delete serverSocket; }}
MegaConnector::MegaConnector(){ socket=new QSslSocket(this); QObject::connect(socket, SIGNAL(encrypted()), this, SLOT(socketReady())); QObject::connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(socketSslErrors(const QList<QSslError> &))); QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));}MegaConnector::~MegaConnector(){ delete socket;}void MegaConnector::connect(){ socket->connectToHostEncrypted(this->serverHost, this->serverPort);}void MegaConnector::socketReady(){ qDebug("Ready!");}void MegaConnector::socketSslErrors(const QList<QSslError> &errors){ qDebug("SSL error");}void MegaConnector::socketError(QAbstractSocket::SocketError socketError){ qDebug("Error"); qDebug(QVariant(socketError).toString().toAscii()); qDebug(socket->errorString().toAscii());}