diff --git a/changelog b/changelog index fdc08179..e9332f0f 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,10 @@ + * PIN and PUK changing implemented + * apply partial template-contents + - applying the subject only or the extensions only is possible now + * add informational messageboxes + - whenever an item was successfully created or imported + * add support for random serial numbers * improve messages, usability and german translation * improve token support - token initializing diff --git a/lib/db_key.cpp b/lib/db_key.cpp index aeaf754f..0c89ef82 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -21,7 +21,6 @@ #include "exception.h" #include "ui_NewKey.h" -#include "ui_SelectToken.h" #include "pkcs11.h" #include "widgets/MainWindow.h" @@ -186,29 +185,10 @@ void db_key::toToken() return; try { pkcs11 p11; - QList p11_slots = p11.getSlotList(); - if (p11_slots.count() == 0) { - QMessageBox::warning(mainwin, XCA_TITLE, - tr("No Security token found")); + unsigned long slot; + + if (!p11.selectToken(&slot, mainwin)) return; - } - QStringList slotnames; - for (int i=0; isetPixmap(*MainWindow::scardImg); - ui.tokenBox->addItems(slotnames); - if (select_slot->exec() == 0) { - delete select_slot; - return; - } - unsigned int slot = p11_slots[ui.tokenBox->currentIndex()]; - delete select_slot; pki_scard *card = new pki_scard(key->getIntName()); card->store_token(slot, key->decryptKey()); QString msg = tr("Shall the original key '%1' be replaced by the key on the token?\nThis will delete the key '%1' and make it unexportable"). diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 99dfc597..1822fcb2 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -627,7 +627,7 @@ void db_x509::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) canSign = cert->canSign(); hasTemplates = mainwin->temps->getDesc().count() > 0 ; privkey = cert->getRefKey(); - hasScard = privkey && privkey->isToken() && pkcs11::loaded(); + hasScard = pkcs11::loaded(); itemRevoke->setEnabled(parentCanSign); itemExtend->setEnabled(parentCanSign); diff --git a/lib/pkcs11.cpp b/lib/pkcs11.cpp index c161e9b1..27ddd746 100644 --- a/lib/pkcs11.cpp +++ b/lib/pkcs11.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "ui_SelectToken.h" CK_FUNCTION_LIST *pkcs11::p11 = NULL; lt_dlhandle pkcs11::dl_handle = NULL; @@ -190,6 +191,35 @@ QString pkcs11::tokenLogin(QString name, bool so, bool force) return QString::fromLocal8Bit(pin, pinlen); } +bool pkcs11::selectToken(unsigned long *slot, QWidget *w) +{ + QList p11_slots = getSlotList(); + if (p11_slots.count() == 0) { + QMessageBox::warning(w, XCA_TITLE, + QObject::tr("No Security token found")); + return false; + } + QStringList slotnames; + for (int i=0; isetPixmap(*MainWindow::scardImg); + ui.tokenBox->addItems(slotnames); + if (select_slot->exec() == 0) { + delete select_slot; + return false; + } + int selected = ui.tokenBox->currentIndex(); + *slot = p11_slots[selected]; + delete select_slot; + return true; +} + void pkcs11::setPin(unsigned char *oldPin, unsigned long oldPinLen, unsigned char *pin, unsigned long pinLen) { diff --git a/lib/pkcs11.h b/lib/pkcs11.h index 9f96da03..0265e2b0 100644 --- a/lib/pkcs11.h +++ b/lib/pkcs11.h @@ -60,6 +60,7 @@ class pkcs11 int deleteObjects(pk11_attlist &atts); void initToken(unsigned long slot, unsigned char *pin, int pinlen, QString label); + bool selectToken(unsigned long *slot, QWidget *w); }; #endif diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index 04e6898e..ba2262eb 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -242,16 +242,21 @@ QByteArray pki_x509::i2d() void pki_x509::store_token() { - pki_scard *card = (pki_scard *)privkey; - unsigned long slot; + pki_scard *card = NULL; + unsigned long slot = 0; x509name xname; QList objects; - if (!privkey || !privkey->isToken()) - throw errorEx(tr("No associated security token")); + pkcs11 p11; - if (!card->prepare_card(&slot)) - return; + if (!privkey || !privkey->isToken()) { + if (!p11.selectToken(&slot, NULL)) + return; + } else { + card = (pki_scard *)privkey; + if (!card->prepare_card(&slot)) + return; + } pk11_attlist p11_atts; p11_atts << @@ -259,7 +264,6 @@ void pki_x509::store_token() pk11_attr_ulong(CKA_CERTIFICATE_TYPE, CKC_X_509) << pk11_attr_data(CKA_VALUE, i2d()); - pkcs11 p11; p11.startSession(slot, true); QList objs = p11.objectList(p11_atts); @@ -268,11 +272,12 @@ void pki_x509::store_token() tr("This certificate is already on the security token")); return; } + p11_atts << pk11_attr_bool(CKA_TOKEN, true) << pk11_attr_data(CKA_SUBJECT, getSubject().i2d()) << pk11_attr_data(CKA_LABEL, desc.toUtf8()) << - card->getIdAttr(); + (card ? card->getIdAttr() : p11.findUniqueID(CKO_CERTIFICATE)); if (p11.tokenLogin(getIntName(), false).isNull()) return; diff --git a/ui/SelectToken.ui b/ui/SelectToken.ui index 1d023824..c2de3c3d 100644 --- a/ui/SelectToken.ui +++ b/ui/SelectToken.ui @@ -143,7 +143,7 @@ - &Store + &Select diff --git a/widgets/MW_menu.cpp b/widgets/MW_menu.cpp index 65a3e94e..5f20b3c1 100644 --- a/widgets/MW_menu.cpp +++ b/widgets/MW_menu.cpp @@ -31,8 +31,10 @@ void MainWindow::init_menu() SLOT(close_database())); acList += file->addAction(tr("&Dump DataBase"), this, SLOT(dump_database())); - acList += file->addAction(tr("&Init Security token"), this, + if (pkcs11::loaded()) { + acList += file->addAction(tr("&Init Security token"), this, SLOT(initToken())); + } acList += file->addAction(tr("C&hange DataBase password"), this, SLOT(changeDbPass())); acList += file->addAction(tr("&Import old db_dump"), this, diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index ab38270e..124c38f0 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -35,7 +35,6 @@ #include "ui_PassRead.h" #include "ui_PassWrite.h" #include "ui_About.h" -#include "ui_SelectToken.h" QPixmap *MainWindow::keyImg = NULL, *MainWindow::csrImg = NULL, @@ -371,35 +370,18 @@ void MainWindow::initToken() return; try { pkcs11 p11; - QList p11_slots = p11.getSlotList(); - if (p11_slots.count() == 0) { - QMessageBox::warning(this, XCA_TITLE, - tr("No Security token found")); + unsigned long slot; + + if (!p11.selectToken(&slot, this)) return; - } - QStringList slotnames; - for (int i=0; isetPixmap(*MainWindow::scardImg); - ui.tokenBox->addItems(slotnames); - ui.applyButton->setText(tr("Select")); - if (select_slot->exec() == 0) { - delete select_slot; - return; - } - int selected = ui.tokenBox->currentIndex(); - unsigned int slot = p11_slots[selected]; - delete select_slot; + + QStringList info = p11.tokenInfo(slot); + QString slotname = QString("%1 (#%2)"). + arg(info[0]).arg(info[2]); pass_info p(XCA_TITLE, tr("Please enter the SO PIN (PUK) of the token '%1'"). - arg(slotnames[selected])); + arg(slotname)); p.setPin(); char pin[MAX_PASS_LENGTH]; int pinlen = passWrite(pin, MAX_PASS_LENGTH, 0, &p); @@ -407,7 +389,7 @@ void MainWindow::initToken() return; QString label = QInputDialog::getText(this, XCA_TITLE, tr("The new label of the token '%1'"). - arg(slotnames[selected])); + arg(slotname)); p11.initToken(slot, (unsigned char*)pin, pinlen, label); p11.startSession(slot, true); p11.login((unsigned char*)pin, pinlen, true); diff --git a/widgets/NewX509.cpp b/widgets/NewX509.cpp index 59089621..3054a498 100644 --- a/widgets/NewX509.cpp +++ b/widgets/NewX509.cpp @@ -507,7 +507,6 @@ void NewX509::templateChanged(pki_temp *templ) pki_temp *NewX509::currentTemplate() { - pki_temp *temp = NULL; if (!tempList->isEnabled()) return NULL; QString name = tempList->currentText();