mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
improve PKCS#11 lib loading for Windows
This commit is contained in:
parent
e316ced8c8
commit
cceec6a700
@ -33,6 +33,20 @@ pkcs11::~pkcs11()
|
||||
p11->C_CloseSession(session);
|
||||
}
|
||||
|
||||
void pkcs11::initialize()
|
||||
{
|
||||
CK_RV rv = p11->C_Initialize(NULL);
|
||||
if (rv != CKR_OK && rv != CKR_CRYPTOKI_ALREADY_INITIALIZED)
|
||||
pk11error("C_Initialize", rv);
|
||||
}
|
||||
|
||||
void pkcs11::finalize()
|
||||
{
|
||||
CK_RV rv = p11->C_Finalize(NULL);
|
||||
if (rv != CKR_OK && rv != CKR_CRYPTOKI_NOT_INITIALIZED)
|
||||
pk11error("C_Finalize", rv);
|
||||
}
|
||||
|
||||
void pkcs11::startSession(unsigned long slot, bool rw)
|
||||
{
|
||||
CK_RV rv;
|
||||
@ -526,7 +540,7 @@ bool pkcs11::load_lib(QString file, bool silent)
|
||||
if (lt_dlclose(dl_handle) < 0) {
|
||||
if (silent)
|
||||
return false;
|
||||
throw errorEx("Failed to close PKCS11 library: " + file);
|
||||
throw errorEx(QObject::tr("Failed to close PKCS11 library: %1").arg(file));
|
||||
}
|
||||
}
|
||||
p11 = NULL;
|
||||
@ -534,14 +548,15 @@ bool pkcs11::load_lib(QString file, bool silent)
|
||||
if (file.isEmpty()) {
|
||||
if (silent)
|
||||
return false;
|
||||
throw errorEx("PKCS11 library filename empty");
|
||||
throw errorEx(QObject::tr("PKCS11 library filename empty"));
|
||||
}
|
||||
|
||||
dl_handle = lt_dlopen(QString2filename(file));
|
||||
if (dl_handle == NULL) {
|
||||
if (silent)
|
||||
return false;
|
||||
throw errorEx("Failed to open PKCS11 library: " + file);
|
||||
throw errorEx(QObject::tr("Failed to open PKCS11 library: %1").
|
||||
arg(file));
|
||||
}
|
||||
|
||||
/* Get the list of function pointers */
|
||||
@ -554,7 +569,8 @@ bool pkcs11::load_lib(QString file, bool silent)
|
||||
/* This state is always worth an error ! */
|
||||
if (lt_dlclose(dl_handle) == 0)
|
||||
dl_handle = NULL;
|
||||
throw errorEx("Failed to open PKCS11 library: " + file);
|
||||
throw errorEx(QObject::tr("Failed to open PKCS11 library: %1").
|
||||
arg(file));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -103,6 +103,8 @@ class pkcs11
|
||||
pkcs11();
|
||||
~pkcs11();
|
||||
static bool load_lib(QString file, bool silent);
|
||||
static void initialize();
|
||||
static void finalize();
|
||||
|
||||
tkInfo tokenInfo(CK_SLOT_ID slot);
|
||||
tkInfo tokenInfo();
|
||||
|
||||
@ -160,9 +160,11 @@ void MainWindow::setOptions()
|
||||
|
||||
opt->setStringOpt(string_opt);
|
||||
opt->pkcs11path->setText(pkcs11path);
|
||||
if (!opt->exec())
|
||||
if (!opt->exec()) {
|
||||
delete opt;
|
||||
enableTokenMenu(pkcs11::loaded());
|
||||
return;
|
||||
|
||||
}
|
||||
QString alg = opt->hashAlgo->currentHashName();
|
||||
db mydb(dbfile);
|
||||
mydb.set((const unsigned char *)CCHAR(alg), alg.length()+1, 1,
|
||||
@ -195,4 +197,5 @@ void MainWindow::setOptions()
|
||||
#endif
|
||||
}
|
||||
enableTokenMenu(pkcs11::loaded());
|
||||
delete opt;
|
||||
}
|
||||
|
||||
@ -92,6 +92,7 @@ void Options::on_tryLoadButton_clicked(void)
|
||||
QString lib = pkcs11path->text();
|
||||
#ifdef WIN32
|
||||
pkcs11::load_lib(lib, false);
|
||||
pkcs11::initialize();
|
||||
#else
|
||||
pki_scard::init_p11engine(lib, false);
|
||||
#endif
|
||||
@ -100,6 +101,10 @@ void Options::on_tryLoadButton_clicked(void)
|
||||
pkcs11 p11;
|
||||
info = p11.driverInfo();
|
||||
}
|
||||
#ifdef WIN32
|
||||
pkcs11::finalize();
|
||||
pkcs11::load_lib(QString(), true);
|
||||
#endif
|
||||
if (!lib.isEmpty()) {
|
||||
QMessageBox::information(this, XCA_TITLE,
|
||||
tr("Successfully loaded PKCS#11 library: %1\n").
|
||||
|
||||
Loading…
Reference in New Issue
Block a user