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. Create a SSl Connection only with Slots and Signals ...
Forum Updated to NodeBB v4.3 + New Features

Create a SSl Connection only with Slots and Signals ...

Scheduled Pinned Locked Moved Unsolved General and Desktop
ssl slot signal
15 Posts 4 Posters 3.8k 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.
  • R Offline
    R Offline
    Ritchie
    wrote on last edited by Ritchie
    #4

    @SGaist
    Which version of Qt are you using ? QT 5.9 (Free version)
    On which platform ? Kubuntu 17.04
    With which compiler ? gcc (64 bit)

    @J-Hilk
    Yes, this is a Class Member variable

    I have already the error handling in place, but the program did not run into this function up to now.

    After executing this code on the client, nothing happen.

    m_StateMachineState=TryToConnect;
    m_sslSocket->connectToHostEncrypted(m_ServerTCPIPAddress, m_ServerTCPIPPort);
    

    and the event "HostFound" is executed.

    On the server, the code of "incomingConnection" is executed and the Connection Thread is created and the socket handle is also
    handled over.
    This code is also executed on the server.

        m_tcpSocket.setPrivateKey(sPrivatSSLKey);
        m_tcpSocket.setLocalCertificate(sLocalSSLCertificate);
        m_tcpSocket.startServerEncryption();
    

    I changed the errorhandling into

    {
        m_LastErrorMessage=m_sslSocket->errorString();
        m_sslSocket->ignoreSslErrors( );
    }
    

    I also updated the error installation for the signal to

        connect(m_sslSocket,SIGNAL(sslErrors(const QList<QSslError> &errors)), this,SLOT(SSLError(const QList<QSslError> &errors)));
    

    But i get this error during execution of the program:

    QObject::connect: No such signal QSslSocket::sslErrors(const QList<QSslError> &error)
    

    But the member m_sslSocket if type "QSslSocket".

    I thought it should run at least into the error function, but it does not.

    Best regards
    R.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #5

      You should use the new connect syntax, this will give you compile time error rather than runtime error.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • R Offline
        R Offline
        Ritchie
        wrote on last edited by
        #6

        @SGaist
        Hi,
        I try to find the new way of using the "Connection" command and failed.
        I always used this documentation as a reference.
        http://doc.qt.io/qt-5/signalsandslots.html

        Is there a other, better documentation for QT ?
        Do you have an example, sorry asking for.

        Best regards
        R.

        jsulmJ 1 Reply Last reply
        0
        • R Ritchie

          @SGaist
          Hi,
          I try to find the new way of using the "Connection" command and failed.
          I always used this documentation as a reference.
          http://doc.qt.io/qt-5/signalsandslots.html

          Is there a other, better documentation for QT ?
          Do you have an example, sorry asking for.

          Best regards
          R.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #7

          @Ritchie There is nothing wrong with this documentation.
          In the link you posted the new way to connect signals and slots is described with examples:

           QObject::connect(&a, &Counter::valueChanged,
                            &b, &Counter::setValue);
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Ritchie
            wrote on last edited by
            #8

            @jsulm
            But what is about this

            You should use the new connect syntax, this will give you compile time error rather than runtime error

            Where is the "new connect syntax" descripted ?
            Best regards
            R.

            jsulmJ 1 Reply Last reply
            0
            • R Ritchie

              @jsulm
              But what is about this

              You should use the new connect syntax, this will give you compile time error rather than runtime error

              Where is the "new connect syntax" descripted ?
              Best regards
              R.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @Ritchie This is the new syntax:

              QObject::connect(&a, &Counter::valueChanged,
                               &b, &Counter::setValue);
              

              It does not use SIGNAL/SLOT macros, instead it uses function pointers.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #10

                The signals and slots chapter might be of interest.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Ritchie
                  wrote on last edited by
                  #11

                  Thanks, that was a misunderstanding from my side.

                  When I use the following code:

                  m_sslSocket->connectToHostEncrypted(m_ServerTCPIPAddress, m_ServerTCPIPPort);
                  

                  to start the SSL Communication, I do not get a "encrypted(void)" event.

                  But when I use the following lines

                  m_sslSocket->connectToHostEncrypted(m_ServerTCPIPAddress, m_ServerTCPIPPort);
                  m_sslSocket->waitForEncrypted(-1);
                  

                  I will get the "encrypted(void)" event. Additional line "waitForEncrypted(-1);", will start my communication. Why ?

                  I am using the following signals for the communication

                      connect(m_sslSocket,SIGNAL(disconnected(void)), this,SLOT(disconnected(void)));
                      connect(m_sslSocket,SIGNAL(hostFound(void)), this,SLOT(hostFound(void)));
                      connect(m_sslSocket,SIGNAL(encrypted(void)), this, SLOT(SSLReady(void)));
                      connect(m_sslSocket,SIGNAL(connected(void)), this,SLOT(connected(void)));
                      typedef void (QSslSocket::* sslErrorsSignal)(const QList<QSslError> &);
                      connect(m_sslSocket, static_cast<sslErrorsSignal>(&QSslSocket::sslErrors),this, &DataThread::SSLError);
                      connect(m_sslSocket,SIGNAL(readyRead(void)), this,SLOT(readyRead(void)));
                      connect(m_sslSocket,SIGNAL(aboutToClose(void)), this,SLOT(aboutToClose(void)));
                      connect(m_sslSocket,SIGNAL(bytesWritten(qint64)), this,SLOT(bytesWritten(qint64)));
                  

                  Where is my failure, because I wouldn't like to use the command "waitForEncrypted(-1);", because this is the reason
                  of the SLOTS and SIGNALS.

                  Best regards
                  R.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    I don't see a good reason for that.

                    Can you provide a minimal compilable example that shows the behaviour ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Ritchie
                      wrote on last edited by
                      #13

                      @SGaist
                      Hi,

                      Try the following, maybe You can understand the problem.
                      Download the sample ssl application from here
                      https://github.com/GuiTeK/Qt-SslServer

                      Modify the file "ClientExample.h"

                      public slots:
                          void run();
                          void                SSLReady(void);           <-------- Add this line
                      
                      

                      Add the following function file "ClientExample.cpp"

                      void ClientExample::SSLReady(void)
                      {
                          qDebug() << "SSL Ready Connected";
                      }
                      

                      Modify the void ClientExample::run()

                      
                          connect(&sslSocket,SIGNAL(encrypted(void)), this, SLOT(SSLReady(void)));  <---- Add
                      //    QThread::msleep(2000);
                      //    if (sslSocket.isEncrypted())    // Wait until encrypted connection is established, -1 means no timeout
                          if (sslSocket.waitForEncrypted(-1))    // Wait until encrypted connection is established, -1 means no timeout
                          {
                              qDebug() << "isEncrypted  Connected";
                      
                      

                      Remove and add the "//" depending on what you would like to see

                      This configuration show the The of the SSLReady

                      //    QThread::msleep(2000);
                      //    if (sslSocket.isEncrypted())    // Wait until encrypted connection is established, -1 means no timeout
                          if (sslSocket.waitForEncrypted(-1))    // Wait until encrypted connection is established, -1 means no timeout
                      

                      This does not give a connection

                          QThread::msleep(2000);
                          if (sslSocket.isEncrypted())    // Wait until encrypted connection is established, -1 means no timeout
                      //    if (sslSocket.waitForEncrypted(-1))    // Wait until encrypted connection is established, -1 means no timeout
                      

                      But I am not sure, if the is a good sample, but it a base code to show the problem (hopefully).

                      Best regards
                      R.

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Ritchie
                        wrote on last edited by Ritchie
                        #14

                        Hi,

                        still working on the problem.

                        Is this the correct way to ignore a error, when you are using a self registered ssl certficate ?

                           m_sslSocket=new QSslSocket(this);
                            m_sslSocket->addCaCertificates(ApplicationPath + "../config/" + m_LocalSSLCertificate);
                            m_sslSocket->ignoreSslErrors();
                        

                        Is this enough for disable the failure ?

                        How can I disable only the certification error and not all ?

                        Is this the correct way ?

                            m_sslSocket=new QSslSocket(this);
                            m_sslSocket->addCaCertificates(ApplicationPath + "../config/" + m_LocalSSLCertificate);
                        
                        
                            QList<QSslCertificate> cert = QSslCertificate::fromPath(ApplicationPath + "../config/" + m_LocalSSLCertificate);
                            QSslError error(QSslError::SelfSignedCertificate, cert.at(0));
                            QList<QSslError> expectedSslErrors;
                            expectedSslErrors.append(error);
                        
                            m_sslSocket->ignoreSslErrors(expectedSslErrors);
                        

                        I still did not get a event in the "sslErrors" and in the "encrypted".

                        And I get the Messages in the DebuggerConsole

                        "QSslSocket: cannot resolve SSLv2_client_method"
                        "QSslSocket: cannot resolve SSLv2_server_method"
                        

                        Best regards
                        R.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          What are you giving exactly to addCaCertificates ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          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