22#include "pkcs11configdlg.h"
24#include "ui_pkcs11config.h"
34class Pkcs11ProviderConfig
37 bool allow_protected_authentication;
44 int slotevent_timeout;
46 Pkcs11ProviderConfig()
47 : allow_protected_authentication(true)
51 , slotevent_method(
"auto")
52 , slotevent_timeout(0)
56 QVariantMap toVariantMap()
const
59 out[
"allow_protected_authentication"] = allow_protected_authentication;
60 out[
"cert_private"] = cert_private;
61 out[
"enabled"] = enabled;
62 out[
"library"] = library;
64 out[
"private_mask"] = private_mask;
65 out[
"slotevent_method"] = slotevent_method;
66 out[
"slotevent_timeout"] = slotevent_timeout;
70 bool fromVariantMap(
const QVariantMap &in)
72 allow_protected_authentication = in[
"allow_protected_authentication"].toBool();
73 cert_private = in[
"cert_private"].toBool();
74 enabled = in[
"enabled"].toBool();
75 library = in[
"library"].toString();
76 name = in[
"name"].toString();
77 private_mask = in[
"private_mask"].toInt();
78 slotevent_method = in[
"slotevent_method"].toString();
79 slotevent_timeout = in[
"slotevent_timeout"].toInt();
90 bool allow_load_rootca;
91 bool allow_protected_authentication;
96 QVariantMap orig_config;
99 : allow_load_rootca(false)
100 , allow_protected_authentication(true)
106 QVariantMap toVariantMap()
const
108 QVariantMap out = orig_config;
111 out[
"formtype"] =
"http://affinix.com/qca/forms/qca-pkcs11#1.0";
114 out[
"allow_load_rootca"] = allow_load_rootca;
115 out[
"allow_protected_authentication"] = allow_protected_authentication;
116 out[
"log_level"] = log_level;
117 out[
"pin_cache"] = pin_cache;
123 Pkcs11ProviderConfig provider;
127 QVariantMap subconfig = provider.toVariantMap();
129 while (it.hasNext()) {
131 out.insert(prefix + it.key(), it.value());
138 bool fromVariantMap(
const QVariantMap &in)
140 if (in[
"formtype"] !=
"http://affinix.com/qca/forms/qca-pkcs11#1.0")
143 allow_load_rootca = in[
"allow_load_rootca"].toBool();
144 allow_protected_authentication = in[
"allow_protected_authentication"].toBool();
145 log_level = in[
"log_level"].toInt();
146 pin_cache = in[
"pin_cache"].toInt();
148 for (
int n = 0;; ++n) {
154 QVariantMap subconfig;
156 while (it.hasNext()) {
158 if (it.key().startsWith(prefix))
159 subconfig.insert(it.key().mid(prefix.
length()), it.value());
163 if (subconfig.isEmpty())
166 Pkcs11ProviderConfig provider;
167 if (!provider.fromVariantMap(subconfig))
175 bool have_name_already =
false;
176 foreach (
const Pkcs11ProviderConfig &i, providers) {
177 if (i.name == provider.name) {
178 have_name_already =
true;
182 if (have_name_already)
243 emit editFailed(
index,
tr(
"Module name cannot be blank."));
247 bool have_name_already =
false;
250 const Pkcs11ProviderConfig &i =
list[n];
257 have_name_already =
true;
261 if (have_name_already) {
262 emit editFailed(
index,
tr(
"There is already a module with this name."));
283 void addItem(
const Pkcs11ProviderConfig &i)
290 void removeItem(
int at)
304static QCA::Provider *get_pkcs11_provider(QVariantMap *_config = 0)
313 if (!config.isEmpty() && config[
"formtype"] ==
"http://affinix.com/qca/forms/qca-pkcs11#1.0") {
319 if (provider && _config)
325class Pkcs11ConfigDlg::Private :
public QObject
332 ModuleListModel *model;
341 bool ignore_dataChanged;
343 Private(Pkcs11ConfigDlg *_q,
const QString &_providerName,
const QVariantMap &configmap)
346 , providerName(_providerName)
350 , ignore_dataChanged(true)
355 model =
new ModuleListModel(
this);
356 qRegisterMetaType<QModelIndex>(
"QModelIndex");
371 ui.rb_pincache_nolimit->setChecked(
true);
372 ui.sb_pincache_time->setEnabled(
false);
373 ui.sb_pincache_time->setValue(300);
374 ui.lv_modules->setModel(model);
377 ui.pb_remove->setEnabled(
false);
378 ui.tb_details->setEnabled(
false);
379 ui.gb_poll->setEnabled(
false);
380 ui.rb_polldefault->setChecked(
true);
381 ui.sb_pollcustom->setEnabled(
false);
382 ui.sb_pollcustom->setValue(5);
383 ui.ck_modeauto->setChecked(
true);
389 connect(ui.ck_allowroot, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
390 connect(ui.ck_allowprotected, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
391 connect(ui.sb_loglevel, SIGNAL(valueChanged(
int)), SLOT(dataChanged()));
392 connect(ui.gb_pincache, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
393 connect(ui.rb_pincache_nolimit, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
394 connect(ui.rb_pincache_time, SIGNAL(toggled(
bool)), ui.sb_pincache_time, SLOT(
setEnabled(
bool)));
395 connect(ui.rb_pincache_time, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
396 connect(ui.sb_pincache_time, SIGNAL(valueChanged(
int)), SLOT(dataChanged()));
400 connect(ui.lv_modules->selectionModel(),
403 connect(ui.pb_add, SIGNAL(clicked()), SLOT(module_add()));
404 connect(ui.pb_remove, SIGNAL(clicked()), SLOT(module_remove()));
405 connect(ui.le_library, SIGNAL(textChanged(
const QString &)), SLOT(dataChanged()));
406 connect(ui.pb_browse, SIGNAL(clicked()), SLOT(library_browse()));
407 connect(ui.cb_slotmethod, SIGNAL(currentIndexChanged(
int)), SLOT(slotmethod_currentIndexChanged(
int)));
408 connect(ui.rb_polldefault, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
409 connect(ui.rb_pollcustom, SIGNAL(toggled(
bool)), ui.sb_pollcustom, SLOT(
setEnabled(
bool)));
410 connect(ui.rb_pollcustom, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
411 connect(ui.sb_pollcustom, SIGNAL(valueChanged(
int)), SLOT(dataChanged()));
412 connect(ui.ck_modallowprotected, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
413 connect(ui.ck_certprivate, SIGNAL(toggled(
bool)), SLOT(dataChanged()));
414 connect(ui.ck_modeauto, SIGNAL(toggled(
bool)), SLOT(modeauto_toggled(
bool)));
415 connect(ui.ck_modesign, SIGNAL(toggled(
bool)), SLOT(modenonauto_toggled(
bool)));
416 connect(ui.ck_modesignrecover, SIGNAL(toggled(
bool)), SLOT(modenonauto_toggled(
bool)));
417 connect(ui.ck_modedecrypt, SIGNAL(toggled(
bool)), SLOT(modenonauto_toggled(
bool)));
418 connect(ui.ck_modeunwrap, SIGNAL(toggled(
bool)), SLOT(modenonauto_toggled(
bool)));
421 if (!providerName.
isEmpty() && config.fromVariantMap(configmap)) {
423 ui.ck_allowroot->setChecked(config.allow_load_rootca);
424 ui.ck_allowprotected->setChecked(config.allow_protected_authentication);
425 ui.sb_loglevel->setValue(config.log_level);
426 if (config.pin_cache != 0) {
427 ui.gb_pincache->setChecked(
true);
428 if (config.pin_cache <= -1)
429 ui.rb_pincache_nolimit->setChecked(
true);
431 ui.rb_pincache_time->setChecked(
true);
432 ui.sb_pincache_time->setValue(config.pin_cache);
436 model->addItems(config.providers);
439 ui.lv_modules->setCurrentIndex(index);
440 ui.lv_modules->selectionModel()->select(
443 ui.buttonBox->setFocus();
447 ui.gb_general->setEnabled(
false);
448 ui.gb_modules->setEnabled(
false);
449 ui.buttonBox->setFocus();
453 ignore_dataChanged =
false;
456 void save_module(
int at)
459 Pkcs11ProviderConfig &i = model->list[at];
461 i.library = ui.le_library->text();
464 int x = ui.cb_slotmethod->currentIndex();
466 i.slotevent_method =
"auto";
468 i.slotevent_method =
"trigger";
470 i.slotevent_method =
"poll";
472 if (ui.rb_polldefault->isChecked())
473 i.slotevent_timeout = 0;
475 i.slotevent_timeout = ui.sb_pollcustom->value();
477 i.slotevent_timeout = 0;
479 i.allow_protected_authentication = ui.ck_modallowprotected->isChecked();
480 i.cert_private = ui.ck_certprivate->isChecked();
483 if (ui.ck_modesign->isChecked())
485 if (ui.ck_modesignrecover->isChecked())
487 if (ui.ck_modedecrypt->isChecked())
489 if (ui.ck_modeunwrap->isChecked())
496 QItemSelection selection = ui.lv_modules->selectionModel()->selection();
497 if (!selection.
indexes().isEmpty()) {
499 save_module(index.
row());
502 config.allow_load_rootca = ui.ck_allowroot->isChecked();
503 config.allow_protected_authentication = ui.ck_allowprotected->isChecked();
504 config.log_level = ui.sb_loglevel->value();
505 if (ui.gb_pincache->isChecked()) {
506 if (ui.rb_pincache_nolimit->isChecked())
507 config.pin_cache = -1;
509 config.pin_cache = ui.sb_pincache_time->value();
511 config.pin_cache = 0;
513 config.providers = model->list;
515 QVariantMap configmap = config.toVariantMap();
537 ui.lv_modules->setFocus();
538 ui.lv_modules->setCurrentIndex(index);
539 ui.lv_modules->selectionModel()->select(
541 ui.lv_modules->edit(index);
546 if (ignore_dataChanged)
558 if (!deselected.
indexes().isEmpty()) {
560 save_module(index.
row());
563 ignore_dataChanged =
true;
565 if (!selected.
indexes().isEmpty()) {
566 if (deselected.
indexes().isEmpty()) {
567 ui.pb_remove->setEnabled(
true);
568 ui.tb_details->setEnabled(
true);
572 const Pkcs11ProviderConfig &i = model->list[index.
row()];
574 ui.le_library->setText(i.library);
576 if (i.slotevent_method ==
"trigger")
577 ui.cb_slotmethod->setCurrentIndex(1);
578 else if (i.slotevent_method ==
"poll") {
579 ui.cb_slotmethod->setCurrentIndex(2);
580 if (i.slotevent_timeout <= 0)
581 ui.rb_polldefault->setChecked(
true);
583 ui.rb_pollcustom->setChecked(
true);
584 ui.sb_pollcustom->setValue(i.slotevent_timeout);
587 ui.cb_slotmethod->setCurrentIndex(0);
588 if (i.slotevent_method !=
"poll") {
589 ui.rb_polldefault->setChecked(
true);
590 ui.sb_pollcustom->setValue(5);
593 ui.ck_modallowprotected->setChecked(i.allow_protected_authentication);
594 ui.ck_certprivate->setChecked(i.cert_private);
596 if (i.private_mask == 0)
597 ui.ck_modeauto->setChecked(
true);
599 ui.ck_modesign->setChecked(i.private_mask & 1);
600 ui.ck_modesignrecover->setChecked(i.private_mask & 2);
601 ui.ck_modedecrypt->setChecked(i.private_mask & 4);
602 ui.ck_modeunwrap->setChecked(i.private_mask & 8);
604 }
else if (selected.
indexes().isEmpty() && !deselected.
indexes().isEmpty()) {
606 ui.le_library->setText(
QString());
607 ui.cb_slotmethod->setCurrentIndex(0);
608 ui.rb_polldefault->setChecked(
true);
609 ui.sb_pollcustom->setValue(5);
610 ui.ck_modallowprotected->setChecked(
false);
611 ui.ck_certprivate->setChecked(
false);
612 ui.ck_modeauto->setChecked(
true);
615 ui.tb_details->setCurrentIndex(0);
616 ui.pb_remove->setEnabled(
false);
617 ui.tb_details->setEnabled(
false);
620 ignore_dataChanged =
false;
627 for (
int n = 1;; ++n) {
633 bool have_name_already =
false;
634 for (
int n = 0; n < model->list.
count(); ++n) {
635 const Pkcs11ProviderConfig &i = model->list[n];
636 if (i.name == name) {
637 have_name_already =
true;
641 if (!have_name_already)
645 Pkcs11ProviderConfig i;
655 ui.tb_details->setCurrentIndex(0);
658 ui.lv_modules->setFocus();
659 ui.lv_modules->setCurrentIndex(index);
660 ui.lv_modules->selectionModel()->select(
662 ui.lv_modules->edit(index);
667 QItemSelection selection = ui.lv_modules->selectionModel()->selection();
668 if (selection.
indexes().isEmpty())
671 model->removeItem(index.
row());
676 void library_browse()
683 ui.le_library->setText(fileName);
686 void slotmethod_currentIndexChanged(
int index)
689 ui.gb_poll->setEnabled(
true);
691 ui.gb_poll->setEnabled(
false);
696 void modeauto_toggled(
bool checked)
699 if (ui.ck_modesign->isChecked())
700 ui.ck_modesign->setChecked(
false);
701 if (ui.ck_modesignrecover->isChecked())
702 ui.ck_modesignrecover->setChecked(
false);
703 if (ui.ck_modedecrypt->isChecked())
704 ui.ck_modedecrypt->setChecked(
false);
705 if (ui.ck_modeunwrap->isChecked())
706 ui.ck_modeunwrap->setChecked(
false);
708 if (!ui.ck_modesign->isChecked() && !ui.ck_modesignrecover->isChecked() &&
709 !ui.ck_modedecrypt->isChecked() && !ui.ck_modeunwrap->isChecked()) {
710 ui.ck_modesign->setChecked(
true);
711 ui.ck_modesignrecover->setChecked(
true);
712 ui.ck_modedecrypt->setChecked(
true);
713 ui.ck_modeunwrap->setChecked(
true);
720 void modenonauto_toggled(
bool checked)
723 if (ui.ck_modeauto->isChecked())
724 ui.ck_modeauto->setChecked(
false);
726 if (!ui.ck_modesign->isChecked() && !ui.ck_modesignrecover->isChecked() &&
727 !ui.ck_modedecrypt->isChecked() && !ui.ck_modeunwrap->isChecked()) {
728 ui.ck_modeauto->setChecked(
true);
736Pkcs11ConfigDlg::Pkcs11ConfigDlg(
QWidget *parent)
742 d =
new Private(
this, p->
name(), config);
744 d =
new Private(
this,
QString(), QVariantMap());
747Pkcs11ConfigDlg::Pkcs11ConfigDlg(
const QString &providerName,
const QVariantMap &config,
QWidget *parent)
750 d =
new Private(
this, providerName, config);
753Pkcs11ConfigDlg::~Pkcs11ConfigDlg()
758void Pkcs11ConfigDlg::done(
int r)
769bool Pkcs11ConfigDlg::isSupported()
771 return (get_pkcs11_provider() ?
true :
false);
774#include "pkcs11configdlg.moc"
virtual QString name() const =0
The name of the provider.
QString name(GameStandardAction id)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QCA_EXPORT Provider * defaultProvider()
Return the default provider.
QCA_EXPORT QVariantMap getProviderConfig(const QString &name)
Retrieve provider configuration.
QCA_EXPORT ProviderList providers()
Return a list of the current providers.
QCA_EXPORT void saveProviderConfig(const QString &name)
Save provider configuration to persistent storage.
QCA_EXPORT void setProviderConfig(const QString &name, const QVariantMap &config)
Set provider configuration.
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual Qt::ItemFlags flags(const QModelIndex &index) const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
QModelIndexList indexes() const const
qsizetype count() const const
bool isEmpty() const const
void removeAt(qsizetype i)
qsizetype size() const const
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
bool isEmpty() const const
qsizetype length() const const
QString toString() const const