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. SSL issues after upgrading Ubuntu
QtWS25 Last Chance

SSL issues after upgrading Ubuntu

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 6 Posters 4.7k Views
  • 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.
  • M Mark81
    9 May 2022, 12:32

    @jsulm Here the full scenario:

    #ifndef OPCUACONFIG_H
    #define OPCUACONFIG_H
    
    #include <QObject>
    #include <QOpcUaClient>
    
    class OpcUaConfig : public QObject
    {
        Q_OBJECT
    
    public:
        explicit OpcUaConfig(QObject *parent = nullptr);
        QOpcUaPkiConfiguration *pkiConfig() { return &_pkiConfig; }
    
    private:
        QOpcUaPkiConfiguration _pkiConfig;
    
        void setupPkiConfiguration();
        bool createPkiFolders();
        bool createPkiPath(const QString &path);
    };
    
    #endif // OPCUACONFIG_H
    
    #include "opcuaconfig.h"
    #include <QCoreApplication>
    #include <QHostInfo>
    #include <QDir>
    
    const QString ID("[OPCUA-CFG]");
    
    OpcUaConfig::OpcUaConfig(QObject *parent) : QObject(parent)
    {
        setupPkiConfiguration();
    }
    
    void OpcUaConfig::setupPkiConfiguration()
    {
        QString pkidir = QCoreApplication::applicationDirPath();
        pkidir += "/pki";
        _pkiConfig.setClientCertificateFile(pkidir + "/own/certs/project.der");
        _pkiConfig.setPrivateKeyFile(pkidir + "/own/private/project.pem");
        _pkiConfig.setTrustListDirectory(pkidir + "/trusted/certs");
        _pkiConfig.setRevocationListDirectory(pkidir + "/trusted/crl");
        _pkiConfig.setIssuerListDirectory(pkidir + "/issuers/certs");
        _pkiConfig.setIssuerRevocationListDirectory(pkidir + "/issuers/crl");
    
        createPkiFolders();
    }
    
    bool OpcUaConfig::createPkiPath(const QString &path)
    {
        const QString msg = ID + " Creating PKI path '%1': %2";
    
        QDir dir;
        return dir.mkpath(path);
    }
    
    bool OpcUaConfig::createPkiFolders()
    {
        bool result = createPkiPath(_pkiConfig.trustListDirectory());
        if (!result) return result;
    
        result = createPkiPath(_pkiConfig.revocationListDirectory());
        if (!result) return result;
    
        result = createPkiPath(_pkiConfig.issuerListDirectory());
        if (!result) return result;
    
        result = createPkiPath(_pkiConfig.issuerRevocationListDirectory());
        if (!result) return result;
    
        return result;
    }
    

    Then I pass the OpcUaConfig::pkiConfig() to the function above.
    I also added:

    if (pkiConfig == nullptr)
    {
        qWarning() << "Invalid config";
        return;
    }
    

    to the MyOpcUa::setConfiguration() function and it does not catch a null pointer.
    Here the screenshot of the seg fault:

    Screenshot from 2022-05-09 14-28-50.png

    And here the "detail" of the pointer:

    Screenshot from 2022-05-09 14-31-44.png

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 9 May 2022, 12:40 last edited by
    #8

    @Mark81 said in SSL issues after upgrading Ubuntu:

    I also added:
    if (pkiConfig == nullptr)

    A pointer can be != nullptr but still invalid (pointing to not allocated memory). Where is setConfiguration called?

    In the screen-shot I see FemtoOpcUi::setConfiguration but you write about MyOpcUa::setConfiguration()?

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

    M 2 Replies Last reply 9 May 2022, 12:47
    0
    • J jsulm
      9 May 2022, 12:40

      @Mark81 said in SSL issues after upgrading Ubuntu:

      I also added:
      if (pkiConfig == nullptr)

      A pointer can be != nullptr but still invalid (pointing to not allocated memory). Where is setConfiguration called?

      In the screen-shot I see FemtoOpcUi::setConfiguration but you write about MyOpcUa::setConfiguration()?

      M Offline
      M Offline
      Mark81
      wrote on 9 May 2022, 12:47 last edited by Mark81 5 Sept 2022, 12:48
      #9

      @jsulm ok, so how to check if a pointer is valid? I only knew about checking if != null.

      In another class I have this function:

      void Engine::initMachines()
      {
          QSqlQuery query = _machines.items();
          while (query.next())
          {
              QString name = query.value("name").toString();
              MyPlc *plc = new MyPlc(name);
              _mapPlc.insert(name, plc);
      
              QUrl url;
              url.setUrl(QString("opc.tcp://%1").arg(query.value("address").toString()));
              url.setPort(PLC_PORT);
              plc->setConfiguration(_opcUaConfig.pkiConfig());
              plc->connectToServer(url);
          }
      }
      

      and:

      class MyPlc : public QObject
      {
          Q_OBJECT
      
      public:
          explicit MyPlc(QString name, QObject *parent = nullptr);
          ~MyPlc();
      
          void setConfiguration(QOpcUaPkiConfiguration *pkiConfig) { _opcua.setConfiguration(pkiConfig); }
          // ...
      }
      
      private:
          FemtoOpcUa _opcua;
      

      where FemtoOpcUa::setConfiguration() is the function reported in the first message.

      Before upgrading to 22.04 all worked fine with this very same code.

      J J 2 Replies Last reply 9 May 2022, 13:12
      0
      • M Mark81
        9 May 2022, 12:47

        @jsulm ok, so how to check if a pointer is valid? I only knew about checking if != null.

        In another class I have this function:

        void Engine::initMachines()
        {
            QSqlQuery query = _machines.items();
            while (query.next())
            {
                QString name = query.value("name").toString();
                MyPlc *plc = new MyPlc(name);
                _mapPlc.insert(name, plc);
        
                QUrl url;
                url.setUrl(QString("opc.tcp://%1").arg(query.value("address").toString()));
                url.setPort(PLC_PORT);
                plc->setConfiguration(_opcUaConfig.pkiConfig());
                plc->connectToServer(url);
            }
        }
        

        and:

        class MyPlc : public QObject
        {
            Q_OBJECT
        
        public:
            explicit MyPlc(QString name, QObject *parent = nullptr);
            ~MyPlc();
        
            void setConfiguration(QOpcUaPkiConfiguration *pkiConfig) { _opcua.setConfiguration(pkiConfig); }
            // ...
        }
        
        private:
            FemtoOpcUa _opcua;
        

        where FemtoOpcUa::setConfiguration() is the function reported in the first message.

        Before upgrading to 22.04 all worked fine with this very same code.

        J Online
        J Online
        JonB
        wrote on 9 May 2022, 13:12 last edited by
        #10

        @Mark81 said in SSL issues after upgrading Ubuntu:

        @jsulm ok, so how to check if a pointer is valid? I only knew about checking if != null.

        You can't. Other than maybe poking around in a debugger.

        I'm not saying it will reveal much in this case, but when it crashes show the stack trace window,, which would tell us anything of interest about where what has been called from....

        M 1 Reply Last reply 9 May 2022, 13:18
        0
        • J JonB
          9 May 2022, 13:12

          @Mark81 said in SSL issues after upgrading Ubuntu:

          @jsulm ok, so how to check if a pointer is valid? I only knew about checking if != null.

          You can't. Other than maybe poking around in a debugger.

          I'm not saying it will reveal much in this case, but when it crashes show the stack trace window,, which would tell us anything of interest about where what has been called from....

          M Offline
          M Offline
          Mark81
          wrote on 9 May 2022, 13:18 last edited by
          #11

          @JonB sorry but where is the "stack trace" window? I only know the "call stack trace" window but as you can see above is filled of ??.

          J 1 Reply Last reply 9 May 2022, 13:43
          0
          • M Mark81
            9 May 2022, 13:18

            @JonB sorry but where is the "stack trace" window? I only know the "call stack trace" window but as you can see above is filled of ??.

            J Online
            J Online
            JonB
            wrote on 9 May 2022, 13:43 last edited by JonB 5 Sept 2022, 13:43
            #12

            @Mark81 Oh, yeah, I only just saw you have pinned at the bottom of your first screenshot. And sure enough no use....

            1 Reply Last reply
            0
            • J jsulm
              9 May 2022, 12:40

              @Mark81 said in SSL issues after upgrading Ubuntu:

              I also added:
              if (pkiConfig == nullptr)

              A pointer can be != nullptr but still invalid (pointing to not allocated memory). Where is setConfiguration called?

              In the screen-shot I see FemtoOpcUi::setConfiguration but you write about MyOpcUa::setConfiguration()?

              M Offline
              M Offline
              Mark81
              wrote on 11 May 2022, 06:27 last edited by
              #13

              @jsulm is the information provided enough to understand what's happening and how to fix it?

              1 Reply Last reply
              0
              • M Mark81
                9 May 2022, 12:47

                @jsulm ok, so how to check if a pointer is valid? I only knew about checking if != null.

                In another class I have this function:

                void Engine::initMachines()
                {
                    QSqlQuery query = _machines.items();
                    while (query.next())
                    {
                        QString name = query.value("name").toString();
                        MyPlc *plc = new MyPlc(name);
                        _mapPlc.insert(name, plc);
                
                        QUrl url;
                        url.setUrl(QString("opc.tcp://%1").arg(query.value("address").toString()));
                        url.setPort(PLC_PORT);
                        plc->setConfiguration(_opcUaConfig.pkiConfig());
                        plc->connectToServer(url);
                    }
                }
                

                and:

                class MyPlc : public QObject
                {
                    Q_OBJECT
                
                public:
                    explicit MyPlc(QString name, QObject *parent = nullptr);
                    ~MyPlc();
                
                    void setConfiguration(QOpcUaPkiConfiguration *pkiConfig) { _opcua.setConfiguration(pkiConfig); }
                    // ...
                }
                
                private:
                    FemtoOpcUa _opcua;
                

                where FemtoOpcUa::setConfiguration() is the function reported in the first message.

                Before upgrading to 22.04 all worked fine with this very same code.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 11 May 2022, 06:33 last edited by
                #14

                @Mark81 said in SSL issues after upgrading Ubuntu:

                plc->setConfiguration(_opcUaConfig.pkiConfig());

                What is _opcUaConfig? Was it initialized properly?

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

                M 1 Reply Last reply 11 May 2022, 06:36
                0
                • J jsulm
                  11 May 2022, 06:33

                  @Mark81 said in SSL issues after upgrading Ubuntu:

                  plc->setConfiguration(_opcUaConfig.pkiConfig());

                  What is _opcUaConfig? Was it initialized properly?

                  M Offline
                  M Offline
                  Mark81
                  wrote on 11 May 2022, 06:36 last edited by
                  #15

                  @jsulm is the local instance of the class OpcUaConfig above:

                  OpcUaConfig _opcUaConfig;
                  

                  until upgrade it didn't raised any issue.

                  1 Reply Last reply
                  0
                  • crashlogC Offline
                    crashlogC Offline
                    crashlog
                    wrote on 6 Jun 2022, 17:43 last edited by
                    #16

                    I think you needlessly delved into the debugger.
                    I came across the same bug. When upgrading ubuntu to version 22.04 LTS, I installed the current Qt 6.3.0, I got the same warnings as you.

                    qt.network.ssl: QSslSocket: cannot resolve EVP_PKEY_base_id
                    qt.network.ssl: QSslSocket: cannot resolve SSL_get_peer_certificate
                    

                    The most simple example of code that already issues a warning:

                    #include <QCoreApplication>
                    #include <QSslConfiguration>
                    
                    int main(int argc, char *argv[])
                    {
                        QCore Application a(argc, argv);
                    
                        qWarning()<<"QSslSocket supportsSsl =>"<<QSslSocket::supportsSsl();
                        qWarning()<<"QSslSocket build version =>"<<QSslSocket::sslLibraryBuildVersionString();
                        qWarning()<<"QSslSocket version =>"<<QSslSocket::sslLibraryVersionString();
                    
                        return a.exec();
                    }
                    

                    I checked the same code on another machine with ubuntu 21.04, there were no warnings.
                    The new ubuntu already has openssl 3.0.2-0ubuntu1.2 installed, while the previous ubuntu had openssl 1.1.1j installed
                    I believe QSslSocket incorrectly accesses the EVP_PKEY_base_id and SSL_get_peer_certificate keys

                    J 1 Reply Last reply 17 Jul 2023, 11:26
                    0
                    • crashlogC crashlog
                      6 Jun 2022, 17:43

                      I think you needlessly delved into the debugger.
                      I came across the same bug. When upgrading ubuntu to version 22.04 LTS, I installed the current Qt 6.3.0, I got the same warnings as you.

                      qt.network.ssl: QSslSocket: cannot resolve EVP_PKEY_base_id
                      qt.network.ssl: QSslSocket: cannot resolve SSL_get_peer_certificate
                      

                      The most simple example of code that already issues a warning:

                      #include <QCoreApplication>
                      #include <QSslConfiguration>
                      
                      int main(int argc, char *argv[])
                      {
                          QCore Application a(argc, argv);
                      
                          qWarning()<<"QSslSocket supportsSsl =>"<<QSslSocket::supportsSsl();
                          qWarning()<<"QSslSocket build version =>"<<QSslSocket::sslLibraryBuildVersionString();
                          qWarning()<<"QSslSocket version =>"<<QSslSocket::sslLibraryVersionString();
                      
                          return a.exec();
                      }
                      

                      I checked the same code on another machine with ubuntu 21.04, there were no warnings.
                      The new ubuntu already has openssl 3.0.2-0ubuntu1.2 installed, while the previous ubuntu had openssl 1.1.1j installed
                      I believe QSslSocket incorrectly accesses the EVP_PKEY_base_id and SSL_get_peer_certificate keys

                      J Offline
                      J Offline
                      julianoes
                      wrote on 17 Jul 2023, 11:26 last edited by
                      #17

                      @crashlog I'm having the same problem with Qt 5.15, and I creared a bug report here but I'm not quite sure what the resolution is yet: https://bugreports.qt.io/browse/QTBUG-115146

                      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