The code below shows to implement a client side handler for password / passphrase / PIN and token requests from QCA and any associated providers.
#include <QtCrypto>
#include <QCoreApplication>
#include <iostream>
#ifdef QT_STATICPLUGIN
#include "import_plugins.h"
#endif
class ClientPassphraseHandler :
public QObject
{
Q_OBJECT
public:
ClientPassphraseHandler(
QObject *parent =
nullptr)
{
m_handler.start();
}
private Q_SLOTS:
void my_eventReady(
int id,
const QCA::Event &event)
{
return;
}
std::cout << "Event is associated with a key store operation" << std::endl;
std::cout << "Event is associated with a file or some other data" << std::endl;
std::cout <<
" Filename: " << qPrintable(event.
fileName()) << std::endl;
} else {
std::cout << "Unexpected Source for Event" << std::endl;
}
std::cout << "Request for token" << std::endl;
m_handler.tokenOkay(id);
std::cout << "Request for password, passphrase or PIN" << std::endl;
std::cout << " [Password request]" << std::endl;
std::cout << " [Passphrase request]" << std::endl;
std::cout << " [PIN request]" << std::endl;
} else {
std::cout << " [unexpect request style]" << std::endl;
}
} else {
std::cout << "Unexpected event type" << std::endl;
}
}
private:
};
void asker_procedure();
{
Q_OBJECT
protected:
void run() override
{
asker_procedure();
}
};
int main(int argc, char **argv)
{
QCoreApplication exampleApp(argc, argv);
ClientPassphraseHandler cph;
AskerThread askerThread;
QObject::connect(&askerThread, &AskerThread::finished, &exampleApp, &QCoreApplication::quit);
askerThread.start();
exampleApp.exec();
return 0;
}
void asker_procedure()
{
std::cout << std::endl << "Now do token:" << std::endl;
nullptr);
std::cout << "Token was accepted" << std::endl;
} else {
std::cout << "Token was not accepted" << std::endl;
}
}
#include "eventhandlerdemo.moc"
Interface class for password / passphrase / PIN and token handlers.
Definition: qca_core.h:1579
void eventReady(int id, const QCA::Event &context)
signal emitted when an Event requires attention.
An asynchronous event.
Definition: qca_core.h:1391
@ Data
File or bytearray generated the event.
Definition: qca_core.h:1419
@ KeyStore
KeyStore generated the event.
Definition: qca_core.h:1418
QString fileName() const
Name or other identifier for the file or byte array associated with this event.
PasswordStyle passwordStyle() const
the style of password required.
Type type() const
the Type of this event
bool isNull() const
test if this event has been setup correctly
Source source() const
the Source of this event
@ Password
Asking for a password, PIN or passphrase.
Definition: qca_core.h:1400
@ Token
Asking for a token.
Definition: qca_core.h:1401
@ StylePIN
User should be prompted for a "PIN".
Definition: qca_core.h:1434
@ StylePassphrase
User should be prompted for a "Passphrase".
Definition: qca_core.h:1433
@ StylePassword
User should be prompted for a "Password".
Definition: qca_core.h:1432
Convenience method for initialising and cleaning up QCA.
Definition: qca_core.h:660
Single entry in a KeyStore.
Definition: qca_keystore.h:141
Key store information, outside of a KeyStore object.
Definition: qca_keystore.h:624
@ SmartCard
for smartcards
Definition: qca_keystore.h:428
User password / passphrase / PIN handler.
Definition: qca_core.h:1661
void waitForResponse()
Block until the password / passphrase request is completed.
void ask(Event::PasswordStyle pstyle, const KeyStoreInfo &keyStoreInfo, const KeyStoreEntry &keyStoreEntry, void *ptr)
queue a password / passphrase request associated with a key store
SecureArray password() const
The password / passphrase / PIN provided by the user in response to the asker request.
Secure array of bytes.
Definition: qca_tools.h:317
QByteArray toByteArray() const
Copy the contents of the secure array out to a standard QByteArray.
User token handler.
Definition: qca_core.h:1754
void waitForResponse()
Block until the token request is completed.
bool accepted() const
Test if the token request was accepted or not.
void ask(const KeyStoreInfo &keyStoreInfo, const KeyStoreEntry &keyStoreEntry, void *ptr)
queue a token request associated with a key store
QCA_EXPORT void init()
Initialise QCA.