24#include <QApplication>
25#include <QInputDialog>
31class Prompter::Private :
public QObject
44 QCA::EventHandler handler;
47 QMessageBox *token_prompt;
50 QCA::KeyStoreManager ksm;
51 QList<QCA::KeyStore *> keyStores;
61 connect(&handler, SIGNAL(eventReady(
int,
const QCA::Event &)), SLOT(ph_eventReady(
int,
const QCA::Event &)));
64 connect(&ksm, SIGNAL(keyStoreAvailable(
const QString &)), SLOT(ks_available(
const QString &)));
65 foreach (
const QString &keyStoreId, ksm.keyStores())
66 ks_available(keyStoreId);
71 qDeleteAll(keyStores);
73 while (!pending.isEmpty())
74 handler.reject(pending.takeFirst().id);
78 void ph_eventReady(
int id,
const QCA::Event &
event)
89 if (prompting || pending.isEmpty())
94 const Item &i = pending.first();
96 const QCA::Event &
event = i.
event;
99 QCA::SecureArray known = q->knownPassword(
event);
101 handler.submitPassword(
id, known);
114 QCA::KeyStoreEntry entry =
event.keyStoreEntry();
121 name =
event.keyStoreInfo().name();
124 }
else if (!
event.fileName().isEmpty()) {
125 QFileInfo fi(
event.fileName());
138 QCA::SecureArray password = pass.
toUtf8();
139 q->userSubmitted(password,
event);
140 handler.submitPassword(
id, password);
150 if (
event.keyStoreEntry().isNull()) {
151 foreach (QCA::KeyStore *ks, keyStores) {
152 if (ks->
id() ==
event.keyStoreInfo().id()) {
160 QCA::KeyStoreEntry kse =
event.keyStoreEntry();
162 QCA::KeyStore *ks = 0;
163 foreach (QCA::KeyStore *i, keyStores) {
164 if (i->
id() ==
event.keyStoreInfo().id()) {
171 foreach (
const QCA::KeyStoreEntry &e, list) {
181 handler.tokenOkay(
id);
185 QCA::KeyStoreEntry entry =
event.keyStoreEntry();
200 token_prompt = &msgBox;
203 handler.tokenOkay(
id);
211 pending.removeFirst();
214 if (!pending.isEmpty())
218 void ks_available(
const QString &keyStoreId)
220 QCA::KeyStore *ks =
new QCA::KeyStore(keyStoreId, &ksm);
221 connect(ks, SIGNAL(updated()), SLOT(ks_updated()));
222 connect(ks, SIGNAL(unavailable()), SLOT(ks_unavailable()));
228 pending.first().event.keyStoreEntry().isNull()) {
230 if (pending.first().event.keyStoreInfo().id() == keyStoreId) {
233 token_prompt->accept();
238 void ks_unavailable()
240 QCA::KeyStore *ks = (QCA::KeyStore *)
sender();
241 keyStores.removeAll(ks);
247 QCA::KeyStore *ks = (QCA::KeyStore *)
sender();
251 !pending.first().event.keyStoreEntry().isNull()) {
252 QCA::KeyStoreEntry kse = pending.first().event.keyStoreEntry();
255 if (pending.first().event.keyStoreInfo().id() == ks->
id()) {
259 foreach (
const QCA::KeyStoreEntry &e, list) {
260 if (e.
id() == kse.
id()) {
268 token_prompt->accept();
275Prompter::Prompter(
QObject *parent)
278 d =
new Private(
this);
289 return QCA::SecureArray();
298#include "prompter.moc"
@ KeyStore
KeyStore generated the event.
@ Password
Asking for a password, PIN or passphrase.
@ Token
Asking for a token.
@ StylePIN
User should be prompted for a "PIN".
@ StylePassphrase
User should be prompted for a "Passphrase".
bool isAvailable() const
Test if the key is available for use.
QString name() const
The name associated with the key stored in this object.
QString storeName() const
The name of the KeyStore for this key object.
QString id() const
The ID associated with the key stored in this object.
bool isNull() const
Test if this key is empty (null)
QString id() const
The ID associated with the KeyStore.
QList< KeyStoreEntry > entryList() const
A list of the KeyStoreEntry objects in this store.
void startAsynchronousMode()
Turns on asynchronous mode for this KeyStore instance.
@ SmartCard
for smartcards
bool isEmpty() const
Test if the array contains any bytes.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString name(StandardAction id)
const QList< QKeySequence > & end()
QCoreApplication * instance()
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
QObject * sender() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual bool event(QEvent *ev) override
QString arg(Args &&... args) const const
QByteArray toUtf8() const const