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. QCA Windows segfault KeyStoreManager

QCA Windows segfault KeyStoreManager

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 2 Posters 3.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
    _whoiam_
    wrote on last edited by _whoiam_
    #1

    Hi,

    I need pgp support in my Qt Application. In linux everything is working but in windows I do not get it to work.
    First I have compiled QCA with my mingw64 compiler following this tutorial https://github.com/JPNaude/dev_notes/wiki/Using-the-Qt-Cryptographic-Architecture-with-Qt5.

    I am using Qt 5.4.2

    Everything seems to be ok but using the lib results in segfaults.
    The segfault appears in executing the line "QCA::KeyStoreManager::start();"

    #include <QtCore>
    #include <QtCrypto>
    
    int main(int argc, char **argv)
    {
    
        Q_UNUSED(argc);
        Q_UNUSED(argv);
    
        // the Initializer object sets things up, and
        // also does cleanup when it goes out of scope
        QCA::Initializer init;
    
        // must always check that an algorithm is supported before using it
        if(!QCA::isSupported("openpgp")) {
            qDebug() << "openpgp not supported!\n";
            return 0;
        } else {
            qDebug() << "openpgp supported!\n";
        }
    
        QCA::KeyStoreManager::start();
        QCA::KeyStoreManager ksm;
        ksm.waitForBusyFinished();
    
        return 0;
    
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      First thing that comes to mind is missing QApplication

      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
      • _ Offline
        _ Offline
        _whoiam_
        wrote on last edited by _whoiam_
        #3

        No that does not help.

        I have also tried to execute it if the eventloop is running.
        Same problem ... segfault in line KeyStoreManager::start()

        MainWindow::MainWindow()
        {
        
            button = new QPushButton("start", this);
        
            QObject::connect(button,&QPushButton::pressed,this,&MainWindow::onButtonPressed);
        
        }
        
        void MainWindow::onButtonPressed() {
        
            // must always check that an algorithm is supported before using it
            if(!QCA::isSupported("openpgp")) {
                qDebug() << "openpgp not supported!\n";
                QApplication::quit();
            } else {
                qDebug() << "openpgp supported!\n";
            }
        
            QCA::KeyStoreManager::start();
        
            qDebug() << "start";
        
            QCA::KeyStoreManager ksm;
            ksm.waitForBusyFinished();
        
            qDebug() << "finished";
        
        }
        

        The weired thing is that the same code is working on my linux machine. So I think it has to do with the compiled qca lib but I do not know how to find my issue or dive in the lib to find anything.

        I have tested the hex example of qca and this is working. So it is a specific problem with pgp only. (KeyStoreManager)

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

          Where are your GPG dlls located ?

          You are probably missing the path to them when running your application. If so, go to the Run part of the Project panel and add it to the PATH environment variable there.

          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
          • _ Offline
            _ Offline
            _whoiam_
            wrote on last edited by
            #5

            I have installed Gpg4win and it is located in C:\Program Files (x86)\GNU\GnuPG

            There are some dll's in the subdir pub and bin
            For safety I have added the root dir, pub and bin to my Path variable.

            If I run the shipped tool

            qcatool-qt5.exe keystore list-stores
            

            it also crashes.

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

              If you run it from the command line you probably have the Qt dll's missing from PATH

              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
              • _ Offline
                _ Offline
                _whoiam_
                wrote on last edited by
                #7

                Ok strange thing but doing a debug build of qca results in a working lib :D

                Dont know whats wrong with the normal build but adding the cmake flag CMAKE_BUILD_TYPE=Debug helped ?!?!

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

                  Where you trying to run a debug build of your application against a release build of QCA ?

                  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
                  • _ Offline
                    _ Offline
                    _whoiam_
                    wrote on last edited by _whoiam_
                    #9

                    Yes, now it's clear ;)

                    It does not come up a segfault if I link the debug lib to my debug build, same applies to the release build. Was not aware of this. I thought the lib is build in release mode and is a independetly thing that does not depend.

                    But now calling my encrypt function results in an empty string :(
                    The loop is finding the corresponding public key.

                    QString PGPClient::encrypt(QString toAddress, QString message)
                    {
                    
                    
                        // must always check that an algorithm is supported before using it
                        if(!QCA::isSupported("openpgp")) {
                            qDebug() << "openpgp not supported!\n";
                            QApplication::quit();
                        } else {
                            qDebug() << "openpgp supported!\n";
                        }
                    
                        QCA::KeyStoreManager::start();
                        QCA::KeyStoreManager ksm(this);
                        ksm.waitForBusyFinished();
                    
                        QCA::KeyStore pgpks( QString("qca-gnupg"), &ksm );
                    
                        QCA::SecureMessageKey to;
                        foreach(const QCA::KeyStoreEntry kse, pgpks.entryList()) {
                    
                            QString text = kse.name() + " // " + kse.id() + " // " + kse.storeId() + " // " + kse.storeName();
                            qDebug() << text;
                    
                            if(kse.name().contains(toAddress)) {
                                if(!kse.pgpPublicKey().isNull()) {
                                    to.setPGPPublicKey(kse.pgpPublicKey());
                                }
                            }
                    
                        }
                    
                        qDebug();
                        qDebug() << to.havePrivate();
                        qDebug() << to.name();
                    
                        QCA::OpenPGP pgp;
                        QCA::SecureMessage msg(&pgp);
                    
                        msg.setRecipient(to);
                        msg.setFormat(QCA::SecureMessage::Ascii);
                        
                        qDebug() << "ok? " << msg.canSignAndEncrypt();
                        qDebug() << message.toUtf8();
                    
                        msg.startEncrypt();
                        msg.update(message.toUtf8());
                        msg.end();
                        msg.waitForFinished(10000);
                    
                        QByteArray crpt = msg.read();
                        return QString::fromUtf8(crpt);
                    
                    }
                    
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      What output do you get from your qDebug statements ?

                      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
                      • _ Offline
                        _ Offline
                        _whoiam_
                        wrote on last edited by
                        #11

                        I only need a little of QCA so i decided to do it my own way and call the gpg binary myself.

                        But how could it be otherwise, linux is working windows NOT.

                        QString PGPProcess::encrypt(QString toAddress, QString message)
                        {
                        
                            this->start(QStringList() << "--trust-model always" << "-a" << "-e" << "-r " + toAddress);
                            this->waitForStarted(PROCESS_WAIT);
                            this->write(message.toUtf8());
                            this->waitForBytesWritten(PROCESS_WAIT);
                            this->closeWriteChannel();
                            this->waitForFinished(PROCESS_WAIT);
                        
                            if(this->exitCode()) {
                                qDebug() << this->exitCode();
                                return message;
                            } else {
                                return this->readAllStandardOutput();
                            }
                        
                        }
                        

                        getting an errorcode 2. If I do the same sequence with the same arguments on the commandline it is working. Do not know whats wrong here.

                        1 Reply Last reply
                        0
                        • _ Offline
                          _ Offline
                          _whoiam_
                          wrote on last edited by
                          #12

                          Ok simply changing the argument QStringList to the following does the trick

                          this->start(QStringList() << "--trust-model" << "always" << "-a" << "-e" << "-r" << toAddress);
                          

                          So every part as single String.

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

                            Good, that's also a solution :)

                            If you are still interested, you can try to re-run your QCA based application, with the PATH environment variable containing the path to the gpg executable. You can to that in Qt Creator by going to the Run part of the Project panel.

                            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