mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
allow certificates to be written to any token
- consolidate token-select dialog - update changelog
This commit is contained in:
parent
6f5e1da5b6
commit
59f99fb33c
@ -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
|
||||
|
||||
@ -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<unsigned long> 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; i<p11_slots.count(); i++) {
|
||||
QStringList info = p11.tokenInfo(p11_slots[i]);
|
||||
slotnames << QString("%1 (#%2)").
|
||||
arg(info[0]).arg(info[2]);
|
||||
}
|
||||
Ui::SelectToken ui;
|
||||
QDialog *select_slot = new QDialog(mainwin);
|
||||
ui.setupUi(select_slot);
|
||||
ui.image->setPixmap(*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").
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <openssl/rand.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <ltdl.h>
|
||||
#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<unsigned long> 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; i<p11_slots.count(); i++) {
|
||||
QStringList info = tokenInfo(p11_slots[i]);
|
||||
slotnames << QString("%1 (#%2)").
|
||||
arg(info[0]).arg(info[2]);
|
||||
}
|
||||
Ui::SelectToken ui;
|
||||
QDialog *select_slot = new QDialog(w);
|
||||
ui.setupUi(select_slot);
|
||||
ui.image->setPixmap(*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)
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<CK_OBJECT_HANDLE> 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<CK_OBJECT_HANDLE> 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;
|
||||
|
||||
@ -143,7 +143,7 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="applyButton">
|
||||
<property name="text">
|
||||
<string>&Store</string>
|
||||
<string>&Select</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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<unsigned long> 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; i<p11_slots.count(); i++) {
|
||||
QStringList info = p11.tokenInfo(p11_slots[i]);
|
||||
slotnames << QString("%1 (#%2)").
|
||||
arg(info[0]).arg(info[2]);
|
||||
}
|
||||
Ui::SelectToken ui;
|
||||
QDialog *select_slot = new QDialog(this);
|
||||
ui.setupUi(select_slot);
|
||||
ui.image->setPixmap(*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);
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user