Problem with SSL handshaking between browser and my HTTPS ProxyServer
-
Hi guys, recently I have written a HTTPS Proxy Server that works perfectly. Now to learn more Im trying to write a Man In the Middle Proxy Server. So I created a SslCertificate and I'm trying to give myself certificate to browser. But I face with this Socket Error :
QAbstractSocket::SslHandshakeFailedError 13
The SSL/TLS handshake failed, so the connection was closedI cant understand whats wrong there. I cant focus on it. I need some help in this case. Thanks alot
here is the code:main.cpp
@
#include <QtCore/QCoreApplication>
#include "server.h"int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Server myServer; return a.exec(); }
@
Server.h
@ #ifndef SERVER_H
#define SERVER_H#include <QTcpServer> #include <QSslSocket> #include <QSslKey> #include <QDebug> #include <QAbstractSocket> class Server : public QTcpServer { Q_OBJECT public: explicit Server(QObject *parent = 0); signals: public slots: private slots: void sltEncrypted(); void sltReadFromClient(); void sltSslErrors(QList<QSslError> errList); void sltSslModeChanged(QSslSocket::SslMode); void sltStateChanged(QAbstractSocket::SocketState); void sltSocketError(QAbstractSocket::SocketError); protected: void incomingConnection(int socketDescriptor); }; #endif // SERVER_H
@
Server.cpp
@ #include "server.h"
Server::Server(QObject *parent) : QTcpServer(parent) { this->listen(QHostAddress::Any,3555); if(this->isListening()) { qDebug()<<"Is listening to port 3555"; }else{ qDebug()<<"Listen nemikone"; } qDebug()<<"___________________________________________________"; qDebug()<<"___________________________________________________"; } //************************************************************************************************ void Server::incomingConnection(int socketDescriptor) { QSslSocket *mySslSocket = new QSslSocket(this); if(mySslSocket->setSocketDescriptor(socketDescriptor)) { connect(mySslSocket,SIGNAL(encrypted()),this,SLOT(sltEncrypted())); connect(mySslSocket,SIGNAL(readyRead()),this,SLOT(sltReadFromClient())); connect(mySslSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sltSslErrors(QList<QSslError>))); connect( mySslSocket, SIGNAL(modeChanged(QSslSocket::SslMode)), this,SLOT(sltSslModeChanged(QSslSocket::SslMode))); connect( mySslSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(sltStateChanged(QAbstractSocket::SocketState))); connect(mySslSocket,SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(sltSocketError(QAbstractSocket::SocketError))); }else{ delete mySslSocket; } mySslSocket->setLocalCertificate("D://server.pem",QSsl::Pem); mySslSocket->setPrivateKey("D://server.pem",QSsl::Rsa,QSsl::Pem); if(mySslSocket->localCertificate().isNull()) { qDebug()<<"localCertificate is null"; }else{ qDebug()<<"localCertificate is Ok"; } if(mySslSocket->privateKey().isNull()) { qDebug()<<"PrivateKey is null"; } else{ qDebug()<<"PrivateKey is Ok"; } mySslSocket->startServerEncryption(); } //*************************************************************************************************** void Server::sltEncrypted() { qDebug()<<"........................encrypted........................."; //some code } //*************************************************************************************************** void Server::sltReadFromClient() { qDebug()<<"read from client"; // some code } //*************************************************************************************************** void Server::sltSslErrors(QList<QSslError> errList) { qDebug() << "MySslServer::sslErrors("; foreach( QSslError err, errList ) qDebug() << " " << err.errorString(); qDebug() << ")"; } //*************************************************************************************************** void Server::sltSslModeChanged(QSslSocket::SslMode mode) { qDebug() << "MySslServer::sslModeChanged(" << (int)mode << ")"; } //**************************************************************************************************** void Server::sltSocketError(QAbstractSocket::SocketError socketErr) { qDebug() << "MySslServer::SocketErrors(" <<(int)socketErr << ")"; } //**************************************************************************************************** void Server::sltStateChanged(QAbstractSocket::SocketState state) { qDebug() << "MySslServer::stateChanged(" << (int)state << ")"; }
@