Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with SSL handshaking between browser and my HTTPS ProxyServer
Qt 6.11 is out! See what's new in the release blog

Problem with SSL handshaking between browser and my HTTPS ProxyServer

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 5.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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 closed

    I 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&#40;&#41;;
    }
    

    @

    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 << ")";
    }
    

    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved