2005-07-28 12:41:07 +00:00
|
|
|
/*
|
2006-04-03 21:14:17 +00:00
|
|
|
* Copyright (C) 2004 Justin Karneges
|
2007-01-20 10:25:18 +00:00
|
|
|
* Copyright (C) 2006-2007 Alon Bar-Lev <alon.barlev@gmail.com>
|
2005-07-28 12:41:07 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2006-12-07 22:45:07 +00:00
|
|
|
* but WITHANY WARRANTY; without even the implied warranty of
|
2005-07-28 12:41:07 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2007-01-02 05:13:51 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-07-28 12:41:07 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtCrypto>
|
|
|
|
|
2006-12-07 20:17:50 +00:00
|
|
|
#include <pkcs11-helper-1.0/pkcs11h-token.h>
|
|
|
|
#include <pkcs11-helper-1.0/pkcs11h-certificate.h>
|
2005-07-28 12:41:07 +00:00
|
|
|
|
|
|
|
using namespace QCA;
|
|
|
|
|
2007-04-08 23:44:38 +00:00
|
|
|
// qPrintable is ASCII only!!!
|
2007-04-13 14:50:48 +00:00
|
|
|
#define myPrintable(s) (s).toUtf8 ().constData ()
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
QString
|
|
|
|
certificateHash (
|
|
|
|
const Certificate &cert
|
|
|
|
) {
|
|
|
|
return Hash ("sha1").hashToString (cert.toDER ());
|
|
|
|
}
|
2007-04-08 23:44:38 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// pkcs11Provider
|
|
|
|
//----------------------------------------------------------------------------
|
2007-04-11 08:34:28 +00:00
|
|
|
class pkcs11Provider : public Provider
|
2005-07-28 12:41:07 +00:00
|
|
|
{
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
2006-12-09 12:37:20 +00:00
|
|
|
static const int _CONFIG_MAX_PROVIDERS;
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
bool _fLowLevelInitialized;
|
|
|
|
bool _fSlotEventsActive;
|
|
|
|
bool _fSlotEventsLowLevelActive;
|
2006-12-09 12:37:20 +00:00
|
|
|
QStringList _providers;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
|
|
|
pkcs11Provider ();
|
|
|
|
~pkcs11Provider ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
2006-11-13 05:44:45 +00:00
|
|
|
virtual
|
|
|
|
int
|
|
|
|
version() const;
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
init ();
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
name () const;
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QStringList
|
|
|
|
features () const;
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
Context *
|
|
|
|
createContext (
|
|
|
|
const QString &type
|
|
|
|
);
|
|
|
|
|
|
|
|
void
|
|
|
|
startSlotEvents ();
|
|
|
|
|
|
|
|
void
|
|
|
|
stopSlotEvents ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-12-09 12:37:20 +00:00
|
|
|
virtual
|
|
|
|
QVariantMap
|
|
|
|
defaultConfig () const;
|
|
|
|
|
|
|
|
virtual
|
|
|
|
void
|
|
|
|
configChanged (const QVariantMap &config);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
protected:
|
|
|
|
static
|
|
|
|
void
|
|
|
|
_logHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const unsigned flags,
|
2006-12-07 22:45:07 +00:00
|
|
|
const char * const format,
|
2006-04-03 21:14:17 +00:00
|
|
|
va_list args
|
|
|
|
);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
static
|
|
|
|
void
|
|
|
|
_slotEventHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static
|
|
|
|
PKCS11H_BOOL
|
|
|
|
_tokenPromptHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data,
|
|
|
|
void * const user_data,
|
|
|
|
const pkcs11h_token_id_t token,
|
|
|
|
const unsigned retry
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
static
|
|
|
|
PKCS11H_BOOL
|
|
|
|
_pinPromptHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data,
|
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token,
|
2006-12-07 20:17:50 +00:00
|
|
|
const unsigned retry,
|
2006-12-07 22:45:07 +00:00
|
|
|
char * const pin,
|
|
|
|
const size_t pin_max
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
logHook (
|
|
|
|
const unsigned flags,
|
2006-12-07 22:45:07 +00:00
|
|
|
const char * const format,
|
2006-04-03 21:14:17 +00:00
|
|
|
va_list args
|
|
|
|
);
|
|
|
|
|
|
|
|
void
|
|
|
|
slotEventHook ();
|
|
|
|
|
|
|
|
PKCS11H_BOOL
|
2007-04-04 02:30:31 +00:00
|
|
|
tokenPromptHook (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token
|
|
|
|
);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
PKCS11H_BOOL
|
|
|
|
pinPromptHook (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token,
|
2006-12-07 22:45:07 +00:00
|
|
|
char * const pin,
|
|
|
|
const size_t pin_max
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
2005-07-28 12:41:07 +00:00
|
|
|
};
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
namespace pkcs11QCAPlugin {
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
class pkcs11KeyStoreEntryContext;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
// pkcs11KeyStoreListContext
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
class pkcs11KeyStoreListContext : public KeyStoreListContext
|
2005-07-28 12:41:07 +00:00
|
|
|
{
|
2006-04-03 21:14:17 +00:00
|
|
|
Q_OBJECT
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
2007-04-13 10:33:15 +00:00
|
|
|
struct pkcs11KeyStoreItem {
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
|
|
|
int id;
|
|
|
|
pkcs11h_token_id_t token_id;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11KeyStoreItem () {
|
2006-04-03 21:14:17 +00:00
|
|
|
id = 0;
|
|
|
|
token_id = NULL;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
~pkcs11KeyStoreItem () {
|
2006-04-03 21:14:17 +00:00
|
|
|
if (token_id != NULL) {
|
2006-12-07 20:17:50 +00:00
|
|
|
pkcs11h_token_freeTokenId (token_id);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
int _last_id;
|
2007-04-05 16:28:32 +00:00
|
|
|
typedef QList<pkcs11KeyStoreItem *> _stores_t;
|
2006-04-03 21:14:17 +00:00
|
|
|
_stores_t _stores;
|
2007-04-05 16:28:32 +00:00
|
|
|
QHash<int, pkcs11KeyStoreItem *> _storesById;
|
2006-04-03 21:14:17 +00:00
|
|
|
QMutex _mutexStores;
|
|
|
|
bool _initialized;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
|
|
|
public:
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext (Provider *p);
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
~pkcs11KeyStoreListContext ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
Provider::Context *
|
|
|
|
clone () const;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
|
|
|
virtual
|
|
|
|
void
|
|
|
|
start ();
|
|
|
|
|
|
|
|
virtual
|
|
|
|
void
|
|
|
|
setUpdatesEnabled (bool enabled);
|
|
|
|
|
|
|
|
virtual
|
|
|
|
KeyStoreEntryContext *
|
|
|
|
entry (
|
|
|
|
int id,
|
|
|
|
const QString &entryId
|
2006-11-22 20:18:40 +00:00
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
|
|
|
|
virtual
|
|
|
|
KeyStoreEntryContext *
|
|
|
|
entryPassive (
|
2007-04-13 10:33:15 +00:00
|
|
|
const QString &serialized
|
2006-11-22 20:18:40 +00:00
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
|
|
|
|
virtual
|
|
|
|
KeyStore::Type
|
|
|
|
type (int id) const;
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
storeId (int id) const;
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
name (int id) const;
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QList<KeyStoreEntry::Type>
|
|
|
|
entryTypes (int id) const;
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QList<int>
|
|
|
|
keyStores ();
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QList<KeyStoreEntryContext*>
|
|
|
|
entryList (int id);
|
|
|
|
|
2007-04-04 02:30:31 +00:00
|
|
|
bool
|
|
|
|
tokenPrompt (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2007-04-04 02:30:31 +00:00
|
|
|
const pkcs11h_token_id_t token_id
|
|
|
|
);
|
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
bool
|
2006-04-07 11:13:05 +00:00
|
|
|
pinPrompt (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token_id,
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray &pin
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
void
|
|
|
|
emit_diagnosticText (
|
|
|
|
const QString &t
|
|
|
|
);
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
private slots:
|
|
|
|
void
|
|
|
|
doReady ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
doUpdated ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11KeyStoreItem *
|
2006-04-03 21:14:17 +00:00
|
|
|
registerTokenId (
|
|
|
|
const pkcs11h_token_id_t token_id
|
|
|
|
);
|
|
|
|
|
|
|
|
void
|
|
|
|
clearStores ();
|
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreEntryContext *
|
|
|
|
keyStoreEntryByCertificateId (
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_certificate_id_t certificate_id,
|
2006-12-07 22:45:07 +00:00
|
|
|
bool has_private,
|
2007-04-13 14:50:48 +00:00
|
|
|
const QList<Certificate> &listIssuers,
|
|
|
|
const QString &description
|
2006-04-03 21:14:17 +00:00
|
|
|
) const;
|
|
|
|
|
|
|
|
QString
|
2006-04-10 08:00:07 +00:00
|
|
|
tokenId2storeId (
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token_id
|
|
|
|
) const;
|
|
|
|
|
|
|
|
QString
|
|
|
|
serializeCertificateId (
|
|
|
|
const pkcs11h_certificate_id_t certificate_id,
|
|
|
|
const CertificateChain &chain,
|
2006-12-07 22:45:07 +00:00
|
|
|
const bool has_private
|
2006-04-03 21:14:17 +00:00
|
|
|
) const;
|
|
|
|
|
|
|
|
void
|
|
|
|
deserializeCertificateId (
|
|
|
|
const QString &from,
|
|
|
|
pkcs11h_certificate_id_t * const p_certificate_id,
|
2006-12-07 22:45:07 +00:00
|
|
|
bool * const has_private,
|
2006-04-03 21:14:17 +00:00
|
|
|
QList<Certificate> *listIssuers
|
|
|
|
) const;
|
|
|
|
|
|
|
|
QString
|
|
|
|
escapeString (
|
|
|
|
const QString &from
|
|
|
|
) const;
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
|
|
|
unescapeString (
|
|
|
|
const QString &from
|
|
|
|
) const;
|
|
|
|
};
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
static pkcs11KeyStoreListContext *s_keyStoreList = NULL;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-05 16:28:32 +00:00
|
|
|
// pkcs11Exception
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-05 16:28:32 +00:00
|
|
|
class pkcs11Exception {
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
2007-04-05 16:28:32 +00:00
|
|
|
CK_RV _rv;
|
|
|
|
QString _msg;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11Exception () {}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
|
|
|
public:
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11Exception (CK_RV rv, const QString &msg) {
|
|
|
|
_rv = rv;
|
|
|
|
_msg = msg;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11Exception (const pkcs11Exception &other) {
|
2006-04-03 21:14:17 +00:00
|
|
|
*this = other;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11Exception &
|
|
|
|
operator = (const pkcs11Exception &other) {
|
|
|
|
_rv = other._rv;
|
|
|
|
_msg = other._msg;
|
2006-04-03 21:14:17 +00:00
|
|
|
return *this;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
CK_RV
|
2007-04-13 10:33:15 +00:00
|
|
|
rv () const {
|
2007-04-05 16:28:32 +00:00
|
|
|
return _rv;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
2007-04-13 10:33:15 +00:00
|
|
|
message () const {
|
2007-04-05 16:28:32 +00:00
|
|
|
return _msg + QString (" ") + pkcs11h_getMessage (_rv);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
// pkcs11RSAContext
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
class pkcs11RSAContext : public RSAContext
|
2005-07-28 12:41:07 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2006-12-07 22:45:07 +00:00
|
|
|
bool _has_privateKeyRole;
|
2006-04-03 21:14:17 +00:00
|
|
|
pkcs11h_certificate_id_t _pkcs11h_certificate_id;
|
|
|
|
pkcs11h_certificate_t _pkcs11h_certificate;
|
|
|
|
RSAPublicKey _pubkey;
|
2007-04-05 13:39:57 +00:00
|
|
|
QString _serialized_entry;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
struct _sign_data_s {
|
2006-04-03 21:14:17 +00:00
|
|
|
SignatureAlgorithm alg;
|
2007-04-11 08:34:28 +00:00
|
|
|
Hash *hash;
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray raw;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
_sign_data_s() {
|
2006-04-03 21:14:17 +00:00
|
|
|
hash = NULL;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
} _sign_data;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11RSAContext (
|
2006-04-03 21:14:17 +00:00
|
|
|
Provider *p,
|
|
|
|
pkcs11h_certificate_id_t pkcs11h_certificate_id,
|
|
|
|
RSAPublicKey pubkey
|
|
|
|
) : RSAContext (p) {
|
2007-04-12 14:12:02 +00:00
|
|
|
CK_RV rv;
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
_has_privateKeyRole = true;
|
2006-04-03 21:14:17 +00:00
|
|
|
_pkcs11h_certificate_id = NULL;
|
|
|
|
_pkcs11h_certificate = NULL;
|
|
|
|
_pubkey = pubkey;
|
|
|
|
clearSign ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-12 14:12:02 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_duplicateCertificateId (
|
|
|
|
&_pkcs11h_certificate_id,
|
|
|
|
pkcs11h_certificate_id
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
|
|
|
throw pkcs11Exception (rv, "Memory error");
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11RSAContext (const pkcs11RSAContext &from) : RSAContext (from.provider ()) {
|
2007-04-12 14:12:02 +00:00
|
|
|
CK_RV rv;
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
_has_privateKeyRole = from._has_privateKeyRole;
|
2006-04-03 21:14:17 +00:00
|
|
|
_pkcs11h_certificate_id = NULL;
|
|
|
|
_pkcs11h_certificate = NULL;
|
|
|
|
_pubkey = from._pubkey;
|
2007-04-05 13:39:57 +00:00
|
|
|
_serialized_entry = from._serialized_entry;
|
2007-04-05 16:28:32 +00:00
|
|
|
_sign_data.hash = NULL;
|
2006-04-03 21:14:17 +00:00
|
|
|
clearSign ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-12 14:12:02 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_duplicateCertificateId (
|
|
|
|
&_pkcs11h_certificate_id,
|
|
|
|
from._pkcs11h_certificate_id
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
|
|
|
throw pkcs11Exception (rv, "Memory error");
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
~pkcs11RSAContext () {
|
2006-04-03 21:14:17 +00:00
|
|
|
clearSign ();
|
2007-04-12 14:12:02 +00:00
|
|
|
|
|
|
|
if (_pkcs11h_certificate != NULL) {
|
|
|
|
pkcs11h_certificate_freeCertificate (_pkcs11h_certificate);
|
|
|
|
_pkcs11h_certificate = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pkcs11h_certificate_id != NULL) {
|
|
|
|
pkcs11h_certificate_freeCertificateId (_pkcs11h_certificate_id);
|
|
|
|
_pkcs11h_certificate_id = NULL;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
Provider::Context *
|
|
|
|
clone () const {
|
2007-04-13 10:33:15 +00:00
|
|
|
return new pkcs11RSAContext (*this);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 13:39:57 +00:00
|
|
|
public:
|
|
|
|
void
|
|
|
|
setSerializedEntry (
|
|
|
|
const QString &serialized_entry
|
|
|
|
) {
|
|
|
|
_serialized_entry = serialized_entry;
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
|
|
|
virtual
|
|
|
|
bool
|
|
|
|
isNull () const {
|
|
|
|
return _pubkey.isNull ();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
PKey::Type
|
|
|
|
type () const {
|
|
|
|
return _pubkey.type ();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
bool
|
|
|
|
isPrivate () const {
|
2006-12-07 22:45:07 +00:00
|
|
|
return _has_privateKeyRole;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
bool
|
|
|
|
canExport () const {
|
2006-12-07 22:45:07 +00:00
|
|
|
return !_has_privateKeyRole;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
convertToPublic () {
|
2006-12-07 22:45:07 +00:00
|
|
|
if (_has_privateKeyRole) {
|
2006-04-03 21:14:17 +00:00
|
|
|
if (_pkcs11h_certificate != NULL) {
|
2006-12-07 20:17:50 +00:00
|
|
|
pkcs11h_certificate_freeCertificate (_pkcs11h_certificate);
|
2006-04-03 21:14:17 +00:00
|
|
|
_pkcs11h_certificate = NULL;
|
|
|
|
}
|
2006-12-07 22:45:07 +00:00
|
|
|
_has_privateKeyRole = false;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
int
|
|
|
|
bits () const {
|
|
|
|
return _pubkey.bitSize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
int
|
|
|
|
maximumEncryptSize (
|
|
|
|
EncryptionAlgorithm alg
|
|
|
|
) const {
|
|
|
|
return _pubkey.maximumEncryptSize (alg);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray
|
2006-04-03 21:14:17 +00:00
|
|
|
encrypt (
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &in,
|
2006-04-03 21:14:17 +00:00
|
|
|
EncryptionAlgorithm alg
|
|
|
|
) {
|
|
|
|
return _pubkey.encrypt (in, alg);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
bool
|
|
|
|
decrypt (
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &in,
|
|
|
|
SecureArray *out,
|
2006-04-03 21:14:17 +00:00
|
|
|
EncryptionAlgorithm alg
|
|
|
|
) {
|
2006-12-07 23:31:19 +00:00
|
|
|
bool session_locked = false;
|
2007-04-12 14:12:02 +00:00
|
|
|
bool ret = false;
|
2006-12-07 23:31:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
|
|
|
CK_MECHANISM_TYPE mech;
|
|
|
|
CK_RV rv;
|
|
|
|
size_t my_size;
|
|
|
|
|
|
|
|
switch (alg) {
|
|
|
|
case EME_PKCS1v15:
|
|
|
|
mech = CKM_RSA_PKCS;
|
2005-07-28 12:41:07 +00:00
|
|
|
break;
|
2006-04-03 21:14:17 +00:00
|
|
|
case EME_PKCS1_OAEP:
|
|
|
|
mech = CKM_RSA_PKCS_OAEP;
|
|
|
|
break;
|
|
|
|
default:
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (CKR_FUNCTION_NOT_SUPPORTED, "Invalid algorithm");
|
2006-04-03 21:14:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
ensureCertificate ();
|
|
|
|
|
|
|
|
if (
|
2006-12-07 23:31:19 +00:00
|
|
|
(rv = pkcs11h_certificate_lockSession (
|
|
|
|
_pkcs11h_certificate
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot lock session");
|
2006-12-07 23:31:19 +00:00
|
|
|
}
|
|
|
|
session_locked = true;
|
|
|
|
|
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_decryptAny (
|
2006-04-03 21:14:17 +00:00
|
|
|
_pkcs11h_certificate,
|
|
|
|
mech,
|
2006-11-22 20:18:40 +00:00
|
|
|
(const unsigned char *)in.constData (),
|
2006-04-03 21:14:17 +00:00
|
|
|
in.size (),
|
|
|
|
NULL,
|
|
|
|
&my_size
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Decryption error");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
out->resize (my_size);
|
|
|
|
|
|
|
|
if (
|
2006-12-07 23:31:19 +00:00
|
|
|
(rv = pkcs11h_certificate_decryptAny (
|
2006-04-03 21:14:17 +00:00
|
|
|
_pkcs11h_certificate,
|
|
|
|
mech,
|
2006-11-22 20:18:40 +00:00
|
|
|
(const unsigned char *)in.constData (),
|
2006-04-03 21:14:17 +00:00
|
|
|
in.size (),
|
|
|
|
(unsigned char *)out->data (),
|
|
|
|
&my_size
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Decryption error");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
rv = out->resize (my_size);
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-12-07 23:31:19 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_releaseSession (
|
|
|
|
_pkcs11h_certificate
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot release session");
|
2006-12-07 23:31:19 +00:00
|
|
|
}
|
|
|
|
session_locked = false;
|
|
|
|
|
2007-04-12 14:12:02 +00:00
|
|
|
ret = true;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-12-07 23:31:19 +00:00
|
|
|
if (session_locked) {
|
|
|
|
pkcs11h_certificate_releaseSession (
|
|
|
|
_pkcs11h_certificate
|
|
|
|
);
|
|
|
|
session_locked = false;
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (s_keyStoreList != NULL) {
|
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Cannot decrypt: %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-04-12 14:12:02 +00:00
|
|
|
|
|
|
|
return ret;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
startSign (
|
|
|
|
SignatureAlgorithm alg,
|
|
|
|
SignatureFormat
|
|
|
|
) {
|
|
|
|
clearSign ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
_sign_data.alg = alg;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
switch (_sign_data.alg) {
|
2006-04-03 21:14:17 +00:00
|
|
|
case EMSA3_SHA1:
|
2007-04-11 08:34:28 +00:00
|
|
|
_sign_data.hash = new Hash ("sha1");
|
2005-07-28 12:41:07 +00:00
|
|
|
break;
|
2006-04-03 21:14:17 +00:00
|
|
|
case EMSA3_MD5:
|
2007-04-11 08:34:28 +00:00
|
|
|
_sign_data.hash = new Hash ("md5");
|
2006-04-03 21:14:17 +00:00
|
|
|
break;
|
|
|
|
case EMSA3_MD2:
|
2007-04-11 08:34:28 +00:00
|
|
|
_sign_data.hash = new Hash ("md2");
|
2006-04-03 21:14:17 +00:00
|
|
|
break;
|
|
|
|
case EMSA3_Raw:
|
|
|
|
break;
|
|
|
|
case SignatureUnknown:
|
|
|
|
case EMSA1_SHA1:
|
|
|
|
case EMSA3_RIPEMD160:
|
|
|
|
default:
|
2007-04-12 14:12:02 +00:00
|
|
|
QCA_logTextMessage (
|
|
|
|
QString().sprintf (
|
|
|
|
"PKCS#11: Invalid hash algorithm %d",
|
|
|
|
_sign_data.alg
|
|
|
|
),
|
|
|
|
Logger::Warning
|
|
|
|
);
|
2005-07-28 12:41:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
startVerify (
|
|
|
|
SignatureAlgorithm alg,
|
|
|
|
SignatureFormat sf
|
|
|
|
) {
|
|
|
|
_pubkey.startVerify (alg, sf);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
update (
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &in
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
2006-12-07 22:45:07 +00:00
|
|
|
if (_has_privateKeyRole) {
|
2007-04-05 16:28:32 +00:00
|
|
|
if (_sign_data.hash != NULL) {
|
|
|
|
_sign_data.hash->update (in);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-04-05 16:28:32 +00:00
|
|
|
_sign_data.raw.append (in);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_pubkey.update (in);
|
|
|
|
}
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray
|
2006-04-03 21:14:17 +00:00
|
|
|
endSign () {
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray result;
|
2006-12-07 23:31:19 +00:00
|
|
|
bool session_locked = false;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray final;
|
2007-04-11 08:34:28 +00:00
|
|
|
CK_RV rv;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-11 08:34:28 +00:00
|
|
|
// from some strange reason I got 2047... (for some) <---- BUG?!?!?!
|
|
|
|
int myrsa_size=(_pubkey.bitSize () + 7) / 8;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
if (_sign_data.hash != NULL) {
|
2007-04-11 08:34:28 +00:00
|
|
|
final = emsa3Encode (
|
|
|
|
_sign_data.hash->type (),
|
|
|
|
_sign_data.hash->final (),
|
|
|
|
myrsa_size
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-04-05 16:28:32 +00:00
|
|
|
final = _sign_data.raw;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-11 08:34:28 +00:00
|
|
|
if (final.size () == 0) {
|
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Cannot encode signature");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
ensureCertificate ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
size_t my_size;
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-12-07 23:31:19 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_lockSession (
|
|
|
|
_pkcs11h_certificate
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot lock session");
|
2006-12-07 23:31:19 +00:00
|
|
|
}
|
|
|
|
session_locked = true;
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_signAny (
|
|
|
|
_pkcs11h_certificate,
|
|
|
|
CKM_RSA_PKCS,
|
2007-04-11 08:34:28 +00:00
|
|
|
(const unsigned char *)final.constData (),
|
|
|
|
(size_t)final.size (),
|
2006-04-03 21:14:17 +00:00
|
|
|
NULL,
|
|
|
|
&my_size
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Signature failed");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
result.resize (my_size);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_signAny (
|
|
|
|
_pkcs11h_certificate,
|
|
|
|
CKM_RSA_PKCS,
|
2007-04-11 08:34:28 +00:00
|
|
|
(const unsigned char *)final.constData (),
|
|
|
|
(size_t)final.size (),
|
2006-04-03 21:14:17 +00:00
|
|
|
(unsigned char *)result.data (),
|
|
|
|
&my_size
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Signature failed");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
result.resize (my_size);
|
2006-12-07 23:31:19 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_releaseSession (
|
|
|
|
_pkcs11h_certificate
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot release session");
|
2006-12-07 23:31:19 +00:00
|
|
|
}
|
|
|
|
session_locked = false;
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-04-03 21:14:17 +00:00
|
|
|
result.clear ();
|
|
|
|
|
2006-12-07 23:31:19 +00:00
|
|
|
if (session_locked) {
|
|
|
|
pkcs11h_certificate_releaseSession (
|
|
|
|
_pkcs11h_certificate
|
|
|
|
);
|
|
|
|
session_locked = false;
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (s_keyStoreList != NULL) {
|
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Cannot sign: %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
clearSign ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return result;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
bool
|
|
|
|
validSignature (
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &sig
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
|
|
|
return _pubkey.validSignature (sig);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
createPrivate (
|
|
|
|
int bits,
|
|
|
|
int exp,
|
|
|
|
bool block
|
|
|
|
) {
|
|
|
|
Q_UNUSED(bits);
|
|
|
|
Q_UNUSED(exp);
|
|
|
|
Q_UNUSED(block);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
createPrivate (
|
2007-04-13 19:22:18 +00:00
|
|
|
const BigInteger &n,
|
|
|
|
const BigInteger &e,
|
|
|
|
const BigInteger &p,
|
|
|
|
const BigInteger &q,
|
|
|
|
const BigInteger &d
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
|
|
|
Q_UNUSED(n);
|
|
|
|
Q_UNUSED(e);
|
|
|
|
Q_UNUSED(p);
|
|
|
|
Q_UNUSED(q);
|
|
|
|
Q_UNUSED(d);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
createPublic (
|
2007-04-13 19:22:18 +00:00
|
|
|
const BigInteger &n,
|
|
|
|
const BigInteger &e
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
|
|
|
Q_UNUSED(n);
|
|
|
|
Q_UNUSED(e);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
BigInteger
|
2006-04-03 21:14:17 +00:00
|
|
|
n () const {
|
|
|
|
return _pubkey.n ();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
BigInteger
|
2006-04-03 21:14:17 +00:00
|
|
|
e () const {
|
|
|
|
return _pubkey.e ();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
BigInteger
|
2006-04-03 21:14:17 +00:00
|
|
|
p () const {
|
2007-04-13 19:22:18 +00:00
|
|
|
return BigInteger();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
BigInteger
|
2006-04-03 21:14:17 +00:00
|
|
|
q () const {
|
2007-04-13 19:22:18 +00:00
|
|
|
return BigInteger();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
BigInteger
|
2006-04-03 21:14:17 +00:00
|
|
|
d () const {
|
2007-04-13 19:22:18 +00:00
|
|
|
return BigInteger();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
|
|
|
PublicKey
|
2007-04-13 10:33:15 +00:00
|
|
|
publicKey () const {
|
2006-04-03 21:14:17 +00:00
|
|
|
return _pubkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ensureTokenAccess () {
|
2007-04-12 08:40:34 +00:00
|
|
|
if (
|
|
|
|
pkcs11h_token_ensureAccess (
|
|
|
|
_pkcs11h_certificate_id->token_id,
|
|
|
|
NULL,
|
|
|
|
0
|
|
|
|
) != CKR_OK
|
|
|
|
) {
|
2005-07-28 12:41:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-04-12 08:40:34 +00:00
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
|
|
|
void
|
|
|
|
clearSign () {
|
2007-04-05 16:28:32 +00:00
|
|
|
_sign_data.raw.clear ();
|
|
|
|
_sign_data.alg = SignatureUnknown;
|
|
|
|
delete _sign_data.hash;
|
|
|
|
_sign_data.hash = NULL;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ensureCertificate () {
|
|
|
|
CK_RV rv;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (_pkcs11h_certificate == NULL) {
|
|
|
|
if (
|
2006-04-06 14:22:48 +00:00
|
|
|
(rv = pkcs11h_certificate_create (
|
2006-04-03 21:14:17 +00:00
|
|
|
_pkcs11h_certificate_id,
|
2007-04-05 13:39:57 +00:00
|
|
|
&_serialized_entry,
|
2006-12-07 20:17:50 +00:00
|
|
|
PKCS11H_PROMPT_MASK_ALLOW_ALL,
|
2006-04-03 21:14:17 +00:00
|
|
|
PKCS11H_PIN_CACHE_INFINITE,
|
|
|
|
&_pkcs11h_certificate
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot create low-level certificate");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-05 16:28:32 +00:00
|
|
|
// pkcs11PKeyContext
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-05 16:28:32 +00:00
|
|
|
class pkcs11PKeyContext : public PKeyContext
|
2006-04-03 21:14:17 +00:00
|
|
|
{
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
|
|
|
PKeyBase *_k;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11PKeyContext (Provider *p) : PKeyContext (p) {
|
2006-04-03 21:14:17 +00:00
|
|
|
_k = NULL;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
~pkcs11PKeyContext () {
|
2006-04-03 21:14:17 +00:00
|
|
|
delete _k;
|
2007-04-13 21:34:00 +00:00
|
|
|
_k = NULL;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
Provider::Context *
|
|
|
|
clone () const {
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11PKeyContext *c = new pkcs11PKeyContext (*this);
|
2006-04-03 21:14:17 +00:00
|
|
|
c->_k = (PKeyBase *)_k->clone();
|
|
|
|
return c;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
|
|
|
virtual
|
|
|
|
QList<PKey::Type>
|
|
|
|
supportedTypes () const {
|
|
|
|
QList<PKey::Type> list;
|
|
|
|
list += PKey::RSA;
|
|
|
|
return list;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QList<PKey::Type>
|
|
|
|
supportedIOTypes () const {
|
|
|
|
QList<PKey::Type> list;
|
|
|
|
list += PKey::RSA;
|
|
|
|
return list;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QList<PBEAlgorithm>
|
|
|
|
supportedPBEAlgorithms () const {
|
|
|
|
QList<PBEAlgorithm> list;
|
|
|
|
return list;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
PKeyBase *
|
|
|
|
key () {
|
|
|
|
return _k;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
const PKeyBase *
|
|
|
|
key () const {
|
|
|
|
return _k;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
void
|
|
|
|
setKey (PKeyBase *key) {
|
|
|
|
delete _k;
|
|
|
|
_k = key;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
bool
|
|
|
|
importKey (
|
|
|
|
const PKeyBase *key
|
|
|
|
) {
|
|
|
|
Q_UNUSED(key);
|
|
|
|
return false;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
static
|
|
|
|
int
|
|
|
|
passphrase_cb (
|
|
|
|
char *buf,
|
|
|
|
int size,
|
|
|
|
int rwflag,
|
|
|
|
void *u
|
|
|
|
) {
|
|
|
|
Q_UNUSED(buf);
|
|
|
|
Q_UNUSED(size);
|
|
|
|
Q_UNUSED(rwflag);
|
|
|
|
Q_UNUSED(u);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray
|
2006-04-03 21:14:17 +00:00
|
|
|
publicToDER () const {
|
2007-04-13 10:33:15 +00:00
|
|
|
return static_cast<pkcs11RSAContext *>(_k)->publicKey ().toDER ();
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
publicToPEM () const {
|
2007-04-13 10:33:15 +00:00
|
|
|
return static_cast<pkcs11RSAContext *>(_k)->publicKey ().toPEM ();
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
ConvertResult
|
|
|
|
publicFromDER (
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &in
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
|
|
|
Q_UNUSED(in);
|
|
|
|
return ErrorDecode;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
ConvertResult
|
|
|
|
publicFromPEM (
|
|
|
|
const QString &s
|
|
|
|
) {
|
|
|
|
Q_UNUSED(s);
|
|
|
|
return ErrorDecode;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray
|
2006-04-03 21:14:17 +00:00
|
|
|
privateToDER(
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &passphrase,
|
2006-04-03 21:14:17 +00:00
|
|
|
PBEAlgorithm pbe
|
|
|
|
) const {
|
|
|
|
Q_UNUSED(passphrase);
|
|
|
|
Q_UNUSED(pbe);
|
2007-04-13 19:22:18 +00:00
|
|
|
return SecureArray ();
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
privateToPEM (
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &passphrase,
|
2006-04-03 21:14:17 +00:00
|
|
|
PBEAlgorithm pbe
|
|
|
|
) const {
|
|
|
|
Q_UNUSED(passphrase);
|
|
|
|
Q_UNUSED(pbe);
|
|
|
|
return QString ();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
ConvertResult
|
|
|
|
privateFromDER (
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &in,
|
|
|
|
const SecureArray &passphrase
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
|
|
|
Q_UNUSED(in);
|
|
|
|
Q_UNUSED(passphrase);
|
|
|
|
return ErrorDecode;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
ConvertResult
|
|
|
|
privateFromPEM (
|
|
|
|
const QString &s,
|
2007-04-13 19:22:18 +00:00
|
|
|
const SecureArray &passphrase
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
|
|
|
Q_UNUSED(s);
|
|
|
|
Q_UNUSED(passphrase);
|
|
|
|
return ErrorDecode;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
// pkcs11KeyStoreEntryContext
|
2005-07-28 12:41:07 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
class pkcs11KeyStoreEntryContext : public KeyStoreEntryContext
|
2005-07-28 12:41:07 +00:00
|
|
|
{
|
2006-04-03 21:14:17 +00:00
|
|
|
private:
|
|
|
|
KeyStoreEntry::Type _item_type;
|
|
|
|
KeyBundle _key;
|
|
|
|
Certificate _cert;
|
|
|
|
QString _storeId;
|
|
|
|
QString _id;
|
2007-04-13 10:33:15 +00:00
|
|
|
QString _serialized;
|
2006-04-03 21:14:17 +00:00
|
|
|
QString _storeName;
|
|
|
|
QString _name;
|
|
|
|
|
2005-07-28 12:41:07 +00:00
|
|
|
public:
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreEntryContext (
|
2006-04-03 21:14:17 +00:00
|
|
|
const Certificate &cert,
|
|
|
|
const QString &storeId,
|
2007-04-13 10:33:15 +00:00
|
|
|
const QString &serialized,
|
2006-04-03 21:14:17 +00:00
|
|
|
const QString &storeName,
|
|
|
|
const QString &name,
|
|
|
|
Provider *p
|
|
|
|
) : KeyStoreEntryContext(p) {
|
|
|
|
_item_type = KeyStoreEntry::TypeCertificate;
|
|
|
|
_cert = cert;
|
|
|
|
_storeId = storeId;
|
2007-04-13 10:33:15 +00:00
|
|
|
_id = certificateHash (_cert);
|
|
|
|
_serialized = serialized;
|
2006-04-03 21:14:17 +00:00
|
|
|
_storeName = storeName;
|
|
|
|
_name = name;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreEntryContext (
|
2006-04-03 21:14:17 +00:00
|
|
|
const KeyBundle &key,
|
|
|
|
const QString &storeId,
|
2007-04-13 10:33:15 +00:00
|
|
|
const QString &serialized,
|
2006-04-03 21:14:17 +00:00
|
|
|
const QString &storeName,
|
|
|
|
const QString &name,
|
|
|
|
Provider *p
|
|
|
|
) : KeyStoreEntryContext(p) {
|
|
|
|
_item_type = KeyStoreEntry::TypeKeyBundle;
|
|
|
|
_key = key;
|
|
|
|
_storeId = storeId,
|
2007-04-13 10:33:15 +00:00
|
|
|
_id = certificateHash (key.certificateChain ().primary ());
|
|
|
|
_serialized = serialized;
|
2006-04-03 21:14:17 +00:00
|
|
|
_storeName = storeName;
|
|
|
|
_name = name;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreEntryContext (
|
|
|
|
const pkcs11KeyStoreEntryContext &from
|
2006-04-03 21:14:17 +00:00
|
|
|
) : KeyStoreEntryContext(from) {
|
|
|
|
_item_type = from._item_type;
|
|
|
|
_key = from._key;
|
|
|
|
_storeId = from._storeId;
|
|
|
|
_id = from._id;
|
2007-04-13 10:33:15 +00:00
|
|
|
_serialized = from._serialized;
|
2006-04-03 21:14:17 +00:00
|
|
|
_storeName = from._storeName;
|
|
|
|
_name = from._name;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
Provider::Context *
|
|
|
|
clone () const {
|
2007-04-13 10:33:15 +00:00
|
|
|
return new pkcs11KeyStoreEntryContext (*this);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
public:
|
|
|
|
virtual
|
|
|
|
KeyStoreEntry::Type
|
|
|
|
type () const {
|
|
|
|
return _item_type;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
name () const {
|
|
|
|
return _name;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
id () const {
|
|
|
|
return _id;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
KeyBundle
|
|
|
|
keyBundle () const {
|
|
|
|
return _key;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
Certificate
|
|
|
|
certificate () const {
|
|
|
|
return _cert;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
storeId () const {
|
|
|
|
return _storeId;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
storeName () const {
|
|
|
|
return _storeName;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
virtual
|
|
|
|
bool
|
|
|
|
ensureAccess () {
|
2007-04-13 10:33:15 +00:00
|
|
|
return static_cast<pkcs11RSAContext *>(static_cast<PKeyContext *>(_key.privateKey ().context ())->key ())->ensureTokenAccess ();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
QString
|
|
|
|
serialize () const {
|
|
|
|
return _serialized;
|
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
};
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// pkcs11QCACrypto
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
class pkcs11QCACrypto {
|
|
|
|
|
2007-04-07 10:59:09 +00:00
|
|
|
private:
|
|
|
|
static
|
|
|
|
int
|
|
|
|
_pkcs11h_crypto_qca_initialize (
|
|
|
|
void * const global_data
|
|
|
|
) {
|
|
|
|
Q_UNUSED(global_data);
|
|
|
|
|
2007-04-12 14:12:02 +00:00
|
|
|
return TRUE; //krazy:exclude=captruefalse
|
2007-04-07 10:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
_pkcs11h_crypto_qca_uninitialize (
|
|
|
|
void * const global_data
|
|
|
|
) {
|
|
|
|
Q_UNUSED(global_data);
|
|
|
|
|
2007-04-12 14:12:02 +00:00
|
|
|
return TRUE; //krazy:exclude=captruefalse
|
2007-04-07 10:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
_pkcs11h_crypto_qca_certificate_get_expiration (
|
|
|
|
void * const global_data,
|
|
|
|
const unsigned char * const blob,
|
|
|
|
const size_t blob_size,
|
|
|
|
time_t * const expiration
|
|
|
|
) {
|
|
|
|
Q_UNUSED(global_data);
|
|
|
|
|
|
|
|
Certificate cert = Certificate::fromDER (
|
|
|
|
QByteArray (
|
|
|
|
(char *)blob,
|
|
|
|
blob_size
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
*expiration = cert.notValidAfter ().toTime_t ();
|
|
|
|
|
2007-04-12 14:12:02 +00:00
|
|
|
return TRUE; //krazy:exclude=captruefalse
|
2007-04-07 10:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
_pkcs11h_crypto_qca_certificate_get_dn (
|
|
|
|
void * const global_data,
|
|
|
|
const unsigned char * const blob,
|
|
|
|
const size_t blob_size,
|
|
|
|
char * const dn,
|
|
|
|
const size_t dn_max
|
|
|
|
) {
|
|
|
|
Q_UNUSED(global_data);
|
|
|
|
|
|
|
|
Certificate cert = Certificate::fromDER (
|
|
|
|
QByteArray (
|
|
|
|
(char *)blob,
|
|
|
|
blob_size
|
|
|
|
)
|
|
|
|
);
|
2007-04-11 20:07:46 +00:00
|
|
|
QString qdn = cert.subjectInfoOrdered ().toString ();
|
2007-04-07 10:59:09 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if ((size_t)qdn.length () > dn_max-1) {
|
2007-04-12 14:12:02 +00:00
|
|
|
return FALSE; //krazy:exclude=captruefalse
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-04-08 23:44:38 +00:00
|
|
|
strcpy (dn, myPrintable (qdn));
|
2007-04-12 14:12:02 +00:00
|
|
|
return TRUE; //krazy:exclude=captruefalse
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
_pkcs11h_crypto_qca_certificate_is_issuer (
|
|
|
|
void * const global_data,
|
|
|
|
const unsigned char * const signer_blob,
|
|
|
|
const size_t signer_blob_size,
|
|
|
|
const unsigned char * const cert_blob,
|
|
|
|
const size_t cert_blob_size
|
|
|
|
) {
|
|
|
|
Q_UNUSED(global_data);
|
|
|
|
|
|
|
|
Certificate signer = Certificate::fromDER (
|
|
|
|
QByteArray (
|
|
|
|
(char *)signer_blob,
|
|
|
|
signer_blob_size
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
Certificate cert = Certificate::fromDER (
|
|
|
|
QByteArray (
|
|
|
|
(char *)cert_blob,
|
|
|
|
cert_blob_size
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return signer.isIssuerOf (cert);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static pkcs11h_engine_crypto_t crypto;
|
|
|
|
};
|
|
|
|
|
|
|
|
pkcs11h_engine_crypto_t pkcs11QCACrypto::crypto = {
|
|
|
|
NULL,
|
|
|
|
_pkcs11h_crypto_qca_initialize,
|
|
|
|
_pkcs11h_crypto_qca_uninitialize,
|
|
|
|
_pkcs11h_crypto_qca_certificate_get_expiration,
|
|
|
|
_pkcs11h_crypto_qca_certificate_get_dn,
|
|
|
|
_pkcs11h_crypto_qca_certificate_is_issuer
|
|
|
|
};
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
// pkcs11KeyStoreListContext
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::pkcs11KeyStoreListContext (Provider *p) : KeyStoreListContext(p) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::pkcs11KeyStoreListContext - entry Provider=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)p
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_last_id = 0;
|
|
|
|
_initialized = false;
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::pkcs11KeyStoreListContext - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::~pkcs11KeyStoreListContext () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::~pkcs11KeyStoreListContext - entry",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
s_keyStoreList = NULL;
|
|
|
|
clearStores ();
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::~pkcs11KeyStoreListContext - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-11 08:34:28 +00:00
|
|
|
Provider::Context *
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::clone () const {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::clone - entry/return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::start () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::start - entry",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QMetaObject::invokeMethod(this, "doReady", Qt::QueuedConnection);
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::start - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::setUpdatesEnabled (bool enabled) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::setUpdatesEnabled - entry enabled=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
enabled ? 1 : 0
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
|
|
|
pkcs11Provider *p = static_cast<pkcs11Provider *>(provider ());
|
|
|
|
if (enabled) {
|
|
|
|
p->startSlotEvents ();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
else {
|
|
|
|
p->stopSlotEvents ();
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-04-03 21:14:17 +00:00
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Start event failed %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::setUpdatesEnabled - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
KeyStoreEntryContext *
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::entry (
|
2006-04-03 21:14:17 +00:00
|
|
|
int id,
|
|
|
|
const QString &entryId
|
2006-11-22 20:18:40 +00:00
|
|
|
) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::entry - entry/return id=%d entryId='%s'",
|
2007-04-05 16:28:32 +00:00
|
|
|
id,
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (entryId)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
Q_UNUSED(id);
|
|
|
|
Q_UNUSED(entryId);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
KeyStoreEntryContext *
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::entryPassive (
|
|
|
|
const QString &serialized
|
2006-11-22 20:18:40 +00:00
|
|
|
) {
|
2007-04-04 02:30:31 +00:00
|
|
|
KeyStoreEntryContext *entry = NULL;
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11h_certificate_id_t certificate_id = NULL;
|
2007-04-04 02:30:31 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::entryPassive - entry serialized='%s'",
|
|
|
|
myPrintable (serialized)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
|
|
|
QList<Certificate> listIssuers;
|
2006-12-07 22:45:07 +00:00
|
|
|
bool has_private;
|
2007-04-13 10:33:15 +00:00
|
|
|
deserializeCertificateId (serialized, &certificate_id, &has_private, &listIssuers);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2007-04-13 14:50:48 +00:00
|
|
|
entry = keyStoreEntryByCertificateId (certificate_id, has_private, listIssuers, QString ());
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-04-03 21:14:17 +00:00
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Add key store entry %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-04-04 02:30:31 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
if (certificate_id != NULL) {
|
|
|
|
pkcs11h_certificate_freeCertificateId (certificate_id);
|
|
|
|
certificate_id = NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::entryPassive - return entry=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)entry
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2007-04-04 02:30:31 +00:00
|
|
|
return entry;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
KeyStore::Type
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::type (int id) const {
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
Q_UNUSED(id);
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::type - entry/return id=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return KeyStore::SmartCard;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::storeId (int id) const {
|
2006-04-03 21:14:17 +00:00
|
|
|
QString ret;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::storeId - entry id=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (_storesById.contains (id)) {
|
|
|
|
if (_storesById[id]->token_id != NULL) {
|
|
|
|
ret = tokenId2storeId (_storesById[id]->token_id);
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::storeId - return ret=%s",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (ret)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::name (int id) const {
|
2006-04-03 21:14:17 +00:00
|
|
|
QString ret;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::name - entry id=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (_storesById.contains (id)) {
|
|
|
|
if (_storesById[id]->token_id != NULL) {
|
|
|
|
ret = _storesById[id]->token_id->label;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::name - return ret=%s",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (ret)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<KeyStoreEntry::Type>
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::entryTypes (int id) const {
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
Q_UNUSED(id);
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::entryTypes - entry/return id=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QList<KeyStoreEntry::Type> list;
|
|
|
|
list += KeyStoreEntry::TypeKeyBundle;
|
|
|
|
list += KeyStoreEntry::TypeCertificate;
|
|
|
|
return list;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QList<int>
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::keyStores () {
|
2006-04-03 21:14:17 +00:00
|
|
|
pkcs11h_token_id_list_t tokens = NULL;
|
|
|
|
QList<int> out;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::keyStores - entry",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
|
|
|
CK_RV rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get available tokens
|
|
|
|
*/
|
|
|
|
if (
|
2006-12-07 20:17:50 +00:00
|
|
|
(rv = pkcs11h_token_enumTokenIds (
|
2006-04-03 21:14:17 +00:00
|
|
|
PKCS11H_ENUM_METHOD_CACHE,
|
|
|
|
&tokens
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Enumerating tokens");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
/*
|
|
|
|
* Register all tokens, unmark
|
|
|
|
* them from remove list
|
|
|
|
*/
|
|
|
|
QList<int> to_remove = _storesById.keys ();
|
|
|
|
for (
|
|
|
|
pkcs11h_token_id_list_t entry = tokens;
|
|
|
|
entry != NULL;
|
|
|
|
entry = entry->next
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11KeyStoreItem *item = registerTokenId (entry->token_id);
|
2006-04-03 21:14:17 +00:00
|
|
|
out += item->id;
|
|
|
|
to_remove.removeAll (item->id);
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
/*
|
|
|
|
* Remove all items
|
|
|
|
* that were not discovered
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
QMutexLocker l(&_mutexStores);
|
|
|
|
|
2007-04-14 00:20:27 +00:00
|
|
|
foreach (int i, to_remove) {
|
|
|
|
pkcs11KeyStoreItem *item = _storesById[i];
|
2007-04-13 21:34:00 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_storesById.remove (item->id);
|
|
|
|
_stores.removeAll (item);
|
2007-04-13 21:34:00 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
delete item;
|
2007-04-13 21:34:00 +00:00
|
|
|
item = NULL;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-04-03 21:14:17 +00:00
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Cannot get key stores: %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (tokens != NULL) {
|
2006-12-07 20:17:50 +00:00
|
|
|
pkcs11h_token_freeTokenIdList (tokens);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::keyStores - return out.size()=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
out.size ()
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<KeyStoreEntryContext*>
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::entryList (int id) {
|
2006-04-03 21:14:17 +00:00
|
|
|
pkcs11h_certificate_id_list_t certs = NULL;
|
|
|
|
QList<KeyStoreEntryContext*> out;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::entryList - entry id=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
|
|
|
CK_RV rv;
|
|
|
|
|
|
|
|
if (_storesById.contains (id)) {
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11KeyStoreItem *entry = _storesById[id];
|
2006-04-03 21:14:17 +00:00
|
|
|
|
|
|
|
if (entry->token_id != NULL) {
|
|
|
|
pkcs11h_certificate_id_list_t issuers = NULL;
|
|
|
|
pkcs11h_certificate_id_list_t current = NULL;
|
2007-04-13 14:50:48 +00:00
|
|
|
QList<Certificate> listCerts;
|
2006-04-03 21:14:17 +00:00
|
|
|
QList<Certificate> listIssuers;
|
2007-04-13 14:50:48 +00:00
|
|
|
QList<pkcs11h_certificate_id_list_t> listIds;
|
|
|
|
int i;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
|
|
|
if (
|
2006-12-07 20:17:50 +00:00
|
|
|
(rv = pkcs11h_certificate_enumTokenCertificateIds (
|
2006-04-03 21:14:17 +00:00
|
|
|
entry->token_id,
|
|
|
|
PKCS11H_ENUM_METHOD_CACHE,
|
2006-12-07 20:17:50 +00:00
|
|
|
NULL,
|
|
|
|
PKCS11H_PROMPT_MASK_ALLOW_ALL,
|
2006-04-03 21:14:17 +00:00
|
|
|
&issuers,
|
|
|
|
&certs
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Enumerate certificates");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 14:50:48 +00:00
|
|
|
for (
|
|
|
|
current=certs;
|
|
|
|
current!=NULL;
|
|
|
|
current=current->next
|
|
|
|
) {
|
|
|
|
listCerts += Certificate::fromDER (
|
|
|
|
QByteArray (
|
|
|
|
(char *)current->certificate_id->certificate_blob,
|
|
|
|
current->certificate_id->certificate_blob_size
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (
|
|
|
|
current=issuers;
|
|
|
|
current!=NULL;
|
|
|
|
current=current->next
|
|
|
|
) {
|
2006-04-03 21:14:17 +00:00
|
|
|
listIssuers += Certificate::fromDER (
|
|
|
|
QByteArray (
|
|
|
|
(char *)current->certificate_id->certificate_blob,
|
|
|
|
current->certificate_id->certificate_blob_size
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 14:50:48 +00:00
|
|
|
QStringList names = makeFriendlyNames (listIssuers + listCerts);
|
|
|
|
QMap<QString, QString> friendlyNames;
|
|
|
|
|
|
|
|
for (i=0;i<names.size ();i++) {
|
|
|
|
friendlyNames.insert (certificateHash (listCerts[i]), names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (
|
|
|
|
i=0, current=issuers;
|
|
|
|
current!=NULL;
|
|
|
|
i++, current=current->next
|
|
|
|
) {
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
2007-04-13 10:33:15 +00:00
|
|
|
out += keyStoreEntryByCertificateId (
|
2006-04-03 21:14:17 +00:00
|
|
|
current->certificate_id,
|
|
|
|
false,
|
2007-04-13 14:50:48 +00:00
|
|
|
listIssuers,
|
|
|
|
friendlyNames[certificateHash (listIssuers[i])]
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-04-03 21:14:17 +00:00
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Add key store entry %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 14:50:48 +00:00
|
|
|
for (
|
|
|
|
i=0, current=certs;
|
|
|
|
current!=NULL;
|
|
|
|
i++, current=current->next
|
|
|
|
) {
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
2007-04-13 10:33:15 +00:00
|
|
|
out += keyStoreEntryByCertificateId (
|
2006-04-03 21:14:17 +00:00
|
|
|
current->certificate_id,
|
|
|
|
true,
|
2007-04-13 14:50:48 +00:00
|
|
|
listIssuers,
|
|
|
|
friendlyNames[certificateHash (listCerts[i])]
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-04-03 21:14:17 +00:00
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Add key store entry %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2006-04-03 21:14:17 +00:00
|
|
|
s_keyStoreList->emit_diagnosticText (
|
2006-04-04 10:54:58 +00:00
|
|
|
QString ().sprintf (
|
2006-12-09 12:37:20 +00:00
|
|
|
"PKCS#11: Enumerating store failed %lu-'%s'.\n",
|
2007-04-13 10:33:15 +00:00
|
|
|
e.rv (),
|
|
|
|
myPrintable (e.message ())
|
2006-04-03 21:14:17 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (certs != NULL) {
|
2006-12-07 20:17:50 +00:00
|
|
|
pkcs11h_certificate_freeCertificateIdList (certs);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::entryList - return out.size()=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
out.size ()
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return out;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-04 02:30:31 +00:00
|
|
|
bool
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::tokenPrompt (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2007-04-04 02:30:31 +00:00
|
|
|
const pkcs11h_token_id_t token_id
|
|
|
|
) {
|
2007-04-13 10:33:15 +00:00
|
|
|
KeyStoreEntry entry;
|
|
|
|
KeyStoreEntryContext *context = NULL;
|
2007-04-07 08:23:56 +00:00
|
|
|
QString storeId;
|
2007-04-05 22:05:48 +00:00
|
|
|
bool ret = false;
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::tokenPrompt - entry user_data=%p, token_id=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
user_data,
|
|
|
|
(void *)token_id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2007-04-05 22:05:48 +00:00
|
|
|
if (user_data != NULL) {
|
|
|
|
QString *serialized = (QString *)user_data;
|
2007-04-13 10:33:15 +00:00
|
|
|
context = entryPassive (*serialized);
|
|
|
|
storeId = context->storeId ();
|
2007-04-13 19:25:30 +00:00
|
|
|
entry.change (context);
|
2007-04-07 08:23:56 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
registerTokenId (token_id);
|
|
|
|
storeId = tokenId2storeId (token_id);
|
|
|
|
}
|
2007-04-05 22:05:48 +00:00
|
|
|
|
2007-04-07 08:23:56 +00:00
|
|
|
TokenAsker asker;
|
|
|
|
asker.ask (
|
|
|
|
storeId,
|
2007-04-13 10:33:15 +00:00
|
|
|
entry,
|
|
|
|
context
|
2007-04-07 08:23:56 +00:00
|
|
|
);
|
|
|
|
asker.waitForResponse ();
|
|
|
|
if (asker.accepted ()) {
|
|
|
|
ret = true;
|
2007-04-05 22:05:48 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::tokenPrompt - return ret=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
ret ? 1 : 0
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
|
|
|
return ret;
|
2007-04-04 02:30:31 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
bool
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::pinPrompt (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token_id,
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray &pin
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
2007-04-13 10:33:15 +00:00
|
|
|
KeyStoreEntry entry;
|
|
|
|
KeyStoreEntryContext *context = NULL;
|
2007-04-05 21:18:26 +00:00
|
|
|
QString storeId;
|
2007-04-05 16:28:32 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::pinPrompt - entry user_data=%p, token_id=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
user_data,
|
|
|
|
(void *)token_id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2007-04-13 19:22:18 +00:00
|
|
|
pin = SecureArray();
|
2007-04-05 21:18:26 +00:00
|
|
|
|
|
|
|
if (user_data != NULL) {
|
|
|
|
QString *serialized = (QString *)user_data;
|
2007-04-13 10:33:15 +00:00
|
|
|
context = entryPassive (*serialized);
|
|
|
|
storeId = context->storeId ();
|
2007-04-13 19:25:30 +00:00
|
|
|
entry.change (context);
|
2007-04-05 21:18:26 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
registerTokenId (token_id);
|
|
|
|
storeId = tokenId2storeId (token_id);
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-07 11:13:05 +00:00
|
|
|
PasswordAsker asker;
|
|
|
|
asker.ask (
|
|
|
|
Event::StylePIN,
|
2007-04-05 21:18:26 +00:00
|
|
|
storeId,
|
2007-04-13 10:33:15 +00:00
|
|
|
entry,
|
|
|
|
context
|
2006-04-07 11:13:05 +00:00
|
|
|
);
|
|
|
|
asker.waitForResponse ();
|
|
|
|
if (asker.accepted ()) {
|
2007-04-05 16:28:32 +00:00
|
|
|
ret = true;
|
2007-04-05 21:18:26 +00:00
|
|
|
pin = asker.password ();
|
2006-04-07 11:13:05 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::pinPrompt - return ret=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
ret ? 1 : 0
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
|
|
|
return ret;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::emit_diagnosticText (
|
2006-04-03 21:14:17 +00:00
|
|
|
const QString &t
|
|
|
|
) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::emit_diagnosticText - entry t='%s'",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (t)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2007-04-12 08:40:34 +00:00
|
|
|
QCA_logTextMessage (t, Logger::Warning);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
emit diagnosticText (t);
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::emit_diagnosticText - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::doReady () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::doReady - entry",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
emit busyEnd ();
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::doReady - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::doUpdated () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::doUpdated - entry",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
emit updated ();
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::doUpdated - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::pkcs11KeyStoreItem *
|
|
|
|
pkcs11KeyStoreListContext::registerTokenId (
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token_id
|
|
|
|
) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::registerTokenId - entry token_id=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)token_id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QMutexLocker l(&_mutexStores);
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_stores_t::iterator i=_stores.begin ();
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
while (
|
|
|
|
i != _stores.end () &&
|
2006-12-07 20:17:50 +00:00
|
|
|
!pkcs11h_token_sameTokenId (
|
2006-04-03 21:14:17 +00:00
|
|
|
token_id,
|
|
|
|
(*i)->token_id
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
i++;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11KeyStoreItem *entry = NULL;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (i == _stores.end ()) {
|
|
|
|
/*
|
|
|
|
* Deal with last_id overlap
|
|
|
|
*/
|
|
|
|
while (_storesById.find (++_last_id) != _storesById.end ());
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
entry = new pkcs11KeyStoreItem;
|
2006-04-03 21:14:17 +00:00
|
|
|
entry->id = _last_id;
|
2006-12-07 20:17:50 +00:00
|
|
|
pkcs11h_token_duplicateTokenId (&entry->token_id, token_id);
|
2006-04-03 21:14:17 +00:00
|
|
|
|
|
|
|
_stores += entry;
|
|
|
|
_storesById.insert (entry->id, entry);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
entry = (*i);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::registerTokenId - return entry=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)token_id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return entry;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::clearStores () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::clearStores - entry",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QMutexLocker l(&_mutexStores);
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_storesById.clear ();
|
2007-04-14 00:20:27 +00:00
|
|
|
foreach (pkcs11KeyStoreItem *i, _stores) {
|
|
|
|
delete i;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_stores.clear ();
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::clearStores - return",
|
2007-04-05 16:28:32 +00:00
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreEntryContext *
|
|
|
|
pkcs11KeyStoreListContext::keyStoreEntryByCertificateId (
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_certificate_id_t certificate_id,
|
2006-12-07 22:45:07 +00:00
|
|
|
bool has_private,
|
2007-04-13 14:50:48 +00:00
|
|
|
const QList<Certificate> &listIssuers,
|
|
|
|
const QString &_description
|
2006-04-03 21:14:17 +00:00
|
|
|
) const {
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreEntryContext *entry = NULL;
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::keyStoreEntryByCertificateId - entry certificate_id=%p, has_private=%d, listIssuers.size()=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)certificate_id,
|
|
|
|
has_private ? 1 : 0,
|
|
|
|
listIssuers.size ()
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
if (certificate_id == NULL) {
|
|
|
|
throw pkcs11Exception (CKR_ARGUMENTS_BAD, "Missing certificate object");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (certificate_id->certificate_blob_size == 0) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (CKR_ARGUMENTS_BAD, "Missing certificate");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Certificate cert = Certificate::fromDER (
|
|
|
|
QByteArray (
|
|
|
|
(char *)certificate_id->certificate_blob,
|
|
|
|
certificate_id->certificate_blob_size
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (cert.isNull ()) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (CKR_ARGUMENTS_BAD, "Invalid certificate");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CertificateChain chain = CertificateChain (cert).complete (listIssuers);
|
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
QString serialized = serializeCertificateId (
|
2006-04-03 21:14:17 +00:00
|
|
|
certificate_id,
|
|
|
|
chain,
|
2006-12-07 22:45:07 +00:00
|
|
|
has_private
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
|
|
|
|
2007-04-13 14:50:48 +00:00
|
|
|
QString description = _description;
|
|
|
|
if (description.isEmpty ()) {
|
|
|
|
description = cert.subjectInfoOrdered ().toString () + " by " + cert.issuerInfo ().value (CommonName, "Unknown");
|
|
|
|
}
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if (has_private) {
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11RSAContext *rsakey = new pkcs11RSAContext (
|
2006-04-03 21:14:17 +00:00
|
|
|
provider(),
|
|
|
|
certificate_id,
|
|
|
|
cert.subjectPublicKey ().toRSA ()
|
|
|
|
);
|
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11PKeyContext *pkc = new pkcs11PKeyContext (provider ());
|
2006-04-03 21:14:17 +00:00
|
|
|
pkc->setKey (rsakey);
|
|
|
|
PrivateKey privkey;
|
|
|
|
privkey.change (pkc);
|
|
|
|
KeyBundle key;
|
|
|
|
key.setCertificateChainAndKey (
|
|
|
|
chain,
|
|
|
|
privkey
|
|
|
|
);
|
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
entry = new pkcs11KeyStoreEntryContext (
|
2006-04-03 21:14:17 +00:00
|
|
|
key,
|
|
|
|
tokenId2storeId (certificate_id->token_id),
|
2007-04-13 10:33:15 +00:00
|
|
|
serialized,
|
2006-04-03 21:14:17 +00:00
|
|
|
certificate_id->token_id->label,
|
2006-12-07 22:45:07 +00:00
|
|
|
description,
|
2006-04-03 21:14:17 +00:00
|
|
|
provider ()
|
|
|
|
);
|
2007-04-05 13:39:57 +00:00
|
|
|
|
2007-04-13 10:33:15 +00:00
|
|
|
rsakey->setSerializedEntry (serialized);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-04-13 10:33:15 +00:00
|
|
|
entry = new pkcs11KeyStoreEntryContext (
|
2006-04-03 21:14:17 +00:00
|
|
|
cert,
|
|
|
|
tokenId2storeId (certificate_id->token_id),
|
2007-04-13 10:33:15 +00:00
|
|
|
serialized,
|
2006-04-03 21:14:17 +00:00
|
|
|
certificate_id->token_id->label,
|
2006-12-07 22:45:07 +00:00
|
|
|
description,
|
2006-04-03 21:14:17 +00:00
|
|
|
provider()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::keyStoreEntryByCertificateId - return entry=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)entry
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return entry;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::tokenId2storeId (
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token_id
|
|
|
|
) const {
|
2007-04-05 16:28:32 +00:00
|
|
|
QString storeId;
|
2006-12-07 22:45:07 +00:00
|
|
|
size_t len;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::tokenId2storeId - entry token_id=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)token_id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if (
|
|
|
|
pkcs11h_token_serializeTokenId (
|
|
|
|
NULL,
|
|
|
|
&len,
|
|
|
|
token_id
|
2007-04-13 13:59:51 +00:00
|
|
|
) != CKR_OK
|
|
|
|
) {
|
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Cannot serialize token id");
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray buf;
|
|
|
|
buf.resize ((int)len);
|
|
|
|
|
|
|
|
if (
|
2006-12-07 22:45:07 +00:00
|
|
|
pkcs11h_token_serializeTokenId (
|
2007-04-13 13:59:51 +00:00
|
|
|
buf.data (),
|
2006-12-07 22:45:07 +00:00
|
|
|
&len,
|
|
|
|
token_id
|
2007-04-13 13:59:51 +00:00
|
|
|
) != CKR_OK
|
2006-12-07 22:45:07 +00:00
|
|
|
) {
|
2007-04-13 13:59:51 +00:00
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Cannot serialize token id");
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 13:59:51 +00:00
|
|
|
buf.resize ((int)len);
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 13:59:51 +00:00
|
|
|
storeId = "qca-pkcs11/" + escapeString (QString::fromUtf8 (buf));
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::tokenId2storeId - return storeId='%s'",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (storeId)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
|
|
|
return storeId;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::serializeCertificateId (
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_certificate_id_t certificate_id,
|
|
|
|
const CertificateChain &chain,
|
2006-12-07 22:45:07 +00:00
|
|
|
const bool has_private
|
2006-04-03 21:14:17 +00:00
|
|
|
) const {
|
2006-12-07 22:45:07 +00:00
|
|
|
QString serialized;
|
|
|
|
size_t len;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::serializeCertificateId - entry certificate_id=%p, xx, has_private=%d",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)certificate_id,
|
|
|
|
has_private ? 1 : 0
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if (
|
|
|
|
pkcs11h_certificate_serializeCertificateId (
|
|
|
|
NULL,
|
|
|
|
&len,
|
|
|
|
certificate_id
|
2007-04-13 13:59:51 +00:00
|
|
|
) != CKR_OK
|
|
|
|
) {
|
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Cannot serialize certificate id");
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray buf;
|
|
|
|
buf.resize ((int)len);
|
|
|
|
|
|
|
|
if (
|
2006-12-07 22:45:07 +00:00
|
|
|
pkcs11h_certificate_serializeCertificateId (
|
2007-04-13 13:59:51 +00:00
|
|
|
buf.data (),
|
2006-12-07 22:45:07 +00:00
|
|
|
&len,
|
|
|
|
certificate_id
|
2007-04-13 13:59:51 +00:00
|
|
|
) != CKR_OK
|
2006-12-07 22:45:07 +00:00
|
|
|
) {
|
2007-04-13 13:59:51 +00:00
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Cannot serialize certificate id");
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 13:59:51 +00:00
|
|
|
buf.resize ((int)len);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
serialized = QString ().sprintf (
|
2007-04-13 20:33:23 +00:00
|
|
|
"qca-pkcs11/0/%s/%d/",
|
2007-04-13 13:59:51 +00:00
|
|
|
myPrintable(escapeString (QString::fromUtf8 (buf))),
|
2006-12-07 22:45:07 +00:00
|
|
|
has_private ? 1 : 0
|
2006-04-03 21:14:17 +00:00
|
|
|
);
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2007-04-13 13:59:51 +00:00
|
|
|
QStringList list;
|
2007-04-14 00:20:27 +00:00
|
|
|
foreach (Certificate i, chain) {
|
|
|
|
list += escapeString (Base64 ().arrayToString (i.toDER ()));
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 13:59:51 +00:00
|
|
|
serialized.append (list.join ("/"));
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::serializeCertificateId - return serialized='%s'",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (serialized)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
return serialized;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::deserializeCertificateId (
|
2006-04-03 21:14:17 +00:00
|
|
|
const QString &from,
|
|
|
|
pkcs11h_certificate_id_t * const p_certificate_id,
|
2007-04-05 16:28:32 +00:00
|
|
|
bool * const p_has_private,
|
|
|
|
QList<Certificate> *p_listIssuers
|
2006-04-03 21:14:17 +00:00
|
|
|
) const {
|
2006-12-07 22:45:07 +00:00
|
|
|
pkcs11h_certificate_id_t certificate_id = NULL;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::deserializeCertificateId - entry from='%s', p_certificate_id=%p, p_has_private=%p, p_listIssuers=%p",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (from),
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)p_certificate_id,
|
|
|
|
(void *)p_has_private,
|
|
|
|
(void *)p_listIssuers
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
try {
|
|
|
|
int n = 0;
|
|
|
|
CK_RV rv;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
*p_certificate_id = NULL;
|
2007-04-05 16:28:32 +00:00
|
|
|
*p_has_private = false;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
QStringList list = from.split ("/");
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-14 10:19:57 +00:00
|
|
|
if (list.size () < 5) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Invalid serialization");
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if (list[n++] != "qca-pkcs11") {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Invalid serialization");
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-13 20:33:23 +00:00
|
|
|
if (list[n++].toInt () != 0) {
|
|
|
|
throw pkcs11Exception (CKR_FUNCTION_FAILED, "Invalid serialization version");
|
|
|
|
}
|
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_deserializeCertificateId (
|
|
|
|
&certificate_id,
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (unescapeString (list[n++]))
|
2006-12-07 22:45:07 +00:00
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Invalid serialization");
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
*p_has_private = list[n++].toInt () != 0;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray arrayCertificate = Base64 ().stringToArray (unescapeString (list[n++]));
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_certificate_setCertificateIdCertificateBlob (
|
|
|
|
certificate_id,
|
|
|
|
(unsigned char *)arrayCertificate.data (),
|
|
|
|
(size_t)arrayCertificate.size ()
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Invalid serialization");
|
2006-12-07 22:45:07 +00:00
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
while (n < list.size ()) {
|
2007-04-05 16:28:32 +00:00
|
|
|
*p_listIssuers += Certificate::fromDER (
|
2006-12-07 22:45:07 +00:00
|
|
|
Base64 ().stringToArray (unescapeString (list[n++]))
|
|
|
|
);
|
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
*p_certificate_id = certificate_id;
|
|
|
|
certificate_id = NULL;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2006-12-07 22:45:07 +00:00
|
|
|
catch (...) {
|
|
|
|
if (certificate_id != NULL) {
|
|
|
|
pkcs11h_certificate_freeCertificateId (certificate_id);
|
|
|
|
certificate_id = NULL;
|
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
2007-04-13 10:33:15 +00:00
|
|
|
"pkcs11KeyStoreListContext::deserializeCertificateId - return *p_certificate_id=%p",
|
2007-04-05 16:28:32 +00:00
|
|
|
(void *)*p_certificate_id
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::escapeString (
|
2006-04-03 21:14:17 +00:00
|
|
|
const QString &from
|
|
|
|
) const {
|
|
|
|
QString to;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-14 00:20:27 +00:00
|
|
|
foreach (QChar c, from) {
|
2006-04-03 21:14:17 +00:00
|
|
|
if (c == '/' || c == '\\') {
|
2007-04-13 13:59:51 +00:00
|
|
|
to += QString ().sprintf ("\\x%04x", c.unicode ());
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
to += c;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return to;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
2007-04-13 10:33:15 +00:00
|
|
|
pkcs11KeyStoreListContext::unescapeString (
|
2006-04-03 21:14:17 +00:00
|
|
|
const QString &from
|
|
|
|
) const {
|
|
|
|
QString to;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
for (int i=0;i<from.size ();i++) {
|
|
|
|
QChar c = from[i];
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (c == '\\') {
|
2007-04-13 13:59:51 +00:00
|
|
|
to += QChar ((ushort)from.mid (i+2, 4).toInt (0, 16));
|
|
|
|
i+=5;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
to += c;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return to;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using namespace pkcs11QCAPlugin;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-12-09 12:37:20 +00:00
|
|
|
const int pkcs11Provider::_CONFIG_MAX_PROVIDERS = 10;
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// pkcs11Provider
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
pkcs11Provider::pkcs11Provider () {
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::pkcs11Provider - entry",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_fLowLevelInitialized = false;
|
|
|
|
_fSlotEventsActive = false;
|
|
|
|
_fSlotEventsLowLevelActive = false;
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::pkcs11Provider - return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
pkcs11Provider::~pkcs11Provider () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::~pkcs11Provider - entry",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
delete s_keyStoreList;
|
|
|
|
s_keyStoreList = NULL;
|
2007-04-13 21:34:00 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
pkcs11h_terminate ();
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::~pkcs11Provider - return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-11-13 05:44:45 +00:00
|
|
|
int pkcs11Provider::version() const
|
|
|
|
{
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::version - entry/return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-11-13 05:44:45 +00:00
|
|
|
return QCA_VERSION;
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void pkcs11Provider::init () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::init - entry",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
try {
|
|
|
|
CK_RV rv;
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-12-07 22:45:07 +00:00
|
|
|
if ((rv = pkcs11h_engine_setCrypto (&pkcs11QCACrypto::crypto)) != CKR_OK) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot set crypto");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if ((rv = pkcs11h_initialize ()) != CKR_OK) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot initialize");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
(rv = pkcs11h_setLogHook (
|
|
|
|
_logHook,
|
|
|
|
this
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot set hook");
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-12-09 12:37:20 +00:00
|
|
|
pkcs11h_setLogLevel (PKCS11H_LOG_QUITE);
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_setTokenPromptHook (
|
|
|
|
_tokenPromptHook,
|
|
|
|
this
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot set hook");
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (
|
|
|
|
(rv = pkcs11h_setPINPromptHook (
|
|
|
|
_pinPromptHook,
|
|
|
|
this
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot set hook");
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2006-12-09 12:37:20 +00:00
|
|
|
|
|
|
|
_fLowLevelInitialized = true;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
catch (const pkcs11Exception &e) {
|
2007-04-13 10:33:15 +00:00
|
|
|
QCA_logTextMessage (e.message (), Logger::Error);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
catch (...) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage ("PKCS#11: Unknown error during provider initialization", Logger::Error);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::init - return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QString
|
|
|
|
pkcs11Provider::name () const {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::name - entry/return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
return "qca-pkcs11";
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QStringList
|
|
|
|
pkcs11Provider::features() const {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::features - entry/return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
QStringList list;
|
|
|
|
list += "smartcard"; // indicator, not algorithm
|
|
|
|
list += "pkey";
|
|
|
|
list += "keystorelist";
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2007-04-11 08:34:28 +00:00
|
|
|
Provider::Context *
|
2007-04-05 16:28:32 +00:00
|
|
|
pkcs11Provider::createContext (const QString &type) {
|
2007-04-07 01:27:23 +00:00
|
|
|
|
2007-04-11 08:34:28 +00:00
|
|
|
Provider::Context *context = NULL;
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
|
|
|
"pkcs11Provider::createContext - entry type='%s'",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (type)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (_fLowLevelInitialized) {
|
2007-04-05 16:28:32 +00:00
|
|
|
if (type == "keystorelist") {
|
2006-04-03 21:14:17 +00:00
|
|
|
if (s_keyStoreList == NULL) {
|
2007-04-13 10:33:15 +00:00
|
|
|
s_keyStoreList = new pkcs11KeyStoreListContext (this);
|
2007-04-05 16:28:32 +00:00
|
|
|
context = s_keyStoreList;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
QString ().sprintf (
|
|
|
|
"pkcs11Provider::createContext - return context=%p",
|
|
|
|
(void *)context
|
|
|
|
),
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
|
|
|
return context;
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
pkcs11Provider::startSlotEvents () {
|
|
|
|
CK_RV rv;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::startSlotEvents - entry",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
if (_fLowLevelInitialized) {
|
|
|
|
if (!_fSlotEventsLowLevelActive) {
|
|
|
|
if (
|
|
|
|
(rv = pkcs11h_setSlotEventHook (
|
|
|
|
_slotEventHook,
|
|
|
|
this
|
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
throw pkcs11Exception (rv, "Cannot start slot events");
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_fSlotEventsLowLevelActive = true;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_fSlotEventsActive = true;
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::startSlotEvents - return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
pkcs11Provider::stopSlotEvents () {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::stopSlotEvents - entry/return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
_fSlotEventsActive = false;
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-12-09 12:37:20 +00:00
|
|
|
QVariantMap
|
|
|
|
pkcs11Provider::defaultConfig () const {
|
|
|
|
QVariantMap mytemplate;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::defaultConfig - entry/return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-12-09 12:37:20 +00:00
|
|
|
mytemplate["formtype"] = "http://affinix.com/qca/forms/qca-pkcs11#1.0";
|
|
|
|
mytemplate["allow_protected_authentication"] = true;
|
|
|
|
mytemplate["pin_cache"] = PKCS11H_PIN_CACHE_INFINITE;
|
|
|
|
mytemplate["log_level"] = PKCS11H_LOG_QUITE;
|
|
|
|
for (int i=0;i<_CONFIG_MAX_PROVIDERS;i++) {
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_enabled", i)] = false;
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_name", i)] = "";
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_library", i)] = "";
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_allow_protected_authentication", i)] = true;
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_cert_private", i)] = false;
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_private_mask", i)] = PKCS11H_PRIVATEMODE_MASK_AUTO;
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_slotevent_method", i)] = "auto";
|
|
|
|
mytemplate[QString ().sprintf ("provider_%02d_slotevent_timeout", i)] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mytemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pkcs11Provider::configChanged (const QVariantMap &config) {
|
|
|
|
CK_RV rv = CKR_OK;
|
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::configChanged - entry",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
|
|
|
|
2006-12-09 12:37:20 +00:00
|
|
|
if (!_fLowLevelInitialized) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage ("PKCS#11: Not initialized", Logger::Error);
|
2006-12-09 12:37:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-20 10:25:18 +00:00
|
|
|
pkcs11h_setLogLevel (config["log_level"].toInt ());
|
2006-12-09 12:37:20 +00:00
|
|
|
pkcs11h_setProtectedAuthentication (
|
2007-04-03 10:04:57 +00:00
|
|
|
config["allow_protected_authentication"].toBool () != false ? TRUE : FALSE //krazy:exclude=captruefalse
|
2006-12-09 12:37:20 +00:00
|
|
|
);
|
|
|
|
pkcs11h_setPINCachePeriod (config["pin_cache"].toInt ());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove current providers
|
|
|
|
*/
|
2007-04-14 00:20:27 +00:00
|
|
|
foreach (QString i, _providers) {
|
|
|
|
pkcs11h_removeProvider (myPrintable (i));
|
2006-12-09 12:37:20 +00:00
|
|
|
}
|
|
|
|
_providers.clear ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add new providers
|
|
|
|
*/
|
|
|
|
for (int i=0;i<_CONFIG_MAX_PROVIDERS;i++) {
|
|
|
|
bool enabled = config[QString ().sprintf ("provider_%02d_enabled", i)].toBool ();
|
|
|
|
QString provider = config[QString ().sprintf ("provider_%02d_library", i)].toString ();
|
|
|
|
QString name = config[QString ().sprintf ("provider_%02d_name", i)].toString ();
|
|
|
|
QString qslotevent = config[QString ().sprintf ("provider_%02d_slotevent_method", i)].toString ();
|
|
|
|
unsigned slotevent = PKCS11H_SLOTEVENT_METHOD_AUTO;
|
|
|
|
if (qslotevent == "trigger") {
|
|
|
|
slotevent = PKCS11H_SLOTEVENT_METHOD_TRIGGER;
|
|
|
|
}
|
|
|
|
else if (qslotevent == "poll") {
|
|
|
|
slotevent = PKCS11H_SLOTEVENT_METHOD_POLL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name.isEmpty ()) {
|
|
|
|
name = provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled && !provider.isEmpty()) {
|
|
|
|
if (
|
|
|
|
(rv = pkcs11h_addProvider (
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (name),
|
|
|
|
myPrintable (provider),
|
2006-12-09 12:37:20 +00:00
|
|
|
config[
|
|
|
|
QString ().sprintf ("provider_%02d_allow_protected_authentication", i)
|
2007-04-03 10:04:57 +00:00
|
|
|
].toBool () != false ? TRUE : FALSE, //krazy:exclude=captruefalse
|
2006-12-09 12:37:20 +00:00
|
|
|
(unsigned)config[
|
|
|
|
QString ().sprintf ("provider_%02d_private_mask", i)
|
|
|
|
].toInt (),
|
|
|
|
slotevent,
|
|
|
|
(unsigned)config[
|
|
|
|
QString ().sprintf ("provider_%02d_slotevent_timeout", i)
|
|
|
|
].toInt (),
|
|
|
|
config[
|
|
|
|
QString ().sprintf ("provider_%02d_cert_private", i)
|
2007-04-03 10:04:57 +00:00
|
|
|
].toBool () != false ? TRUE : FALSE //krazy:exclude=captruefalse
|
2006-12-09 12:37:20 +00:00
|
|
|
)) != CKR_OK
|
|
|
|
) {
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2006-12-09 12:37:20 +00:00
|
|
|
QString ().sprintf (
|
|
|
|
"PKCS#11: Cannot log provider '%s'-'%s' %lu-'%s'.\n",
|
2007-04-08 23:44:38 +00:00
|
|
|
myPrintable (name),
|
|
|
|
myPrintable (provider),
|
2006-12-09 12:37:20 +00:00
|
|
|
rv,
|
|
|
|
pkcs11h_getMessage (rv)
|
2007-04-05 16:28:32 +00:00
|
|
|
),
|
|
|
|
Logger::Error
|
2006-12-09 12:37:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_providers += provider;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (
|
2007-04-05 16:28:32 +00:00
|
|
|
"pkcs11Provider::configChanged - return",
|
|
|
|
Logger::Debug
|
|
|
|
);
|
2006-12-09 12:37:20 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
pkcs11Provider::_logHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const unsigned flags,
|
2006-12-07 22:45:07 +00:00
|
|
|
const char * const format,
|
2006-04-03 21:14:17 +00:00
|
|
|
va_list args
|
|
|
|
) {
|
2006-12-07 20:17:50 +00:00
|
|
|
pkcs11Provider *me = (pkcs11Provider *)global_data;
|
2006-12-07 22:45:07 +00:00
|
|
|
me->logHook (flags, format, args);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
pkcs11Provider::_slotEventHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
2006-12-07 20:17:50 +00:00
|
|
|
pkcs11Provider *me = (pkcs11Provider *)global_data;
|
2006-04-03 21:14:17 +00:00
|
|
|
me->slotEventHook ();
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
PKCS11H_BOOL
|
|
|
|
pkcs11Provider::_tokenPromptHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data,
|
|
|
|
void * const user_data,
|
|
|
|
const pkcs11h_token_id_t token,
|
|
|
|
const unsigned retry
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
2006-12-07 20:17:50 +00:00
|
|
|
Q_UNUSED(retry);
|
|
|
|
|
|
|
|
pkcs11Provider *me = (pkcs11Provider *)global_data;
|
2007-04-05 13:39:57 +00:00
|
|
|
return me->tokenPromptHook (user_data, token);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
PKCS11H_BOOL
|
|
|
|
pkcs11Provider::_pinPromptHook (
|
2006-12-07 20:17:50 +00:00
|
|
|
void * const global_data,
|
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token,
|
2006-12-07 20:17:50 +00:00
|
|
|
const unsigned retry,
|
2006-12-07 22:45:07 +00:00
|
|
|
char * const pin,
|
|
|
|
const size_t pin_max
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
2006-12-07 20:17:50 +00:00
|
|
|
Q_UNUSED(retry);
|
|
|
|
|
|
|
|
pkcs11Provider *me = (pkcs11Provider *)global_data;
|
2007-04-05 13:39:57 +00:00
|
|
|
return me->pinPromptHook (user_data, token, pin, pin_max);
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
pkcs11Provider::logHook (
|
|
|
|
const unsigned flags,
|
2006-12-07 22:45:07 +00:00
|
|
|
const char * const format,
|
2006-04-03 21:14:17 +00:00
|
|
|
va_list args
|
|
|
|
) {
|
2007-01-20 10:25:18 +00:00
|
|
|
Logger::Severity severity;
|
|
|
|
|
|
|
|
switch (flags) {
|
|
|
|
case PKCS11H_LOG_DEBUG2:
|
|
|
|
case PKCS11H_LOG_DEBUG1:
|
|
|
|
severity = Logger::Debug;
|
|
|
|
break;
|
|
|
|
case PKCS11H_LOG_INFO:
|
|
|
|
severity = Logger::Information;
|
|
|
|
break;
|
|
|
|
case PKCS11H_LOG_WARN:
|
|
|
|
severity = Logger::Warning;
|
|
|
|
break;
|
|
|
|
case PKCS11H_LOG_ERROR:
|
|
|
|
severity = Logger::Error;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
severity = Logger::Debug;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-04 02:30:31 +00:00
|
|
|
|
|
|
|
//@BEGIN-WORKAROUND
|
|
|
|
// Qt vsprintf cannot can NULL for %s as vsprintf does.
|
2007-04-08 12:29:44 +00:00
|
|
|
// QCA_logTextMessage (QString ().vsprintf (format, args), severity);
|
2007-04-13 13:59:51 +00:00
|
|
|
char buffer[2048];
|
2007-04-04 02:30:31 +00:00
|
|
|
vsnprintf (buffer, sizeof (buffer)-1, format, args);
|
|
|
|
buffer[sizeof (buffer)-1] = '\x0';
|
2007-04-08 12:29:44 +00:00
|
|
|
QCA_logTextMessage (buffer, severity);
|
2007-04-04 02:30:31 +00:00
|
|
|
//@END-WORKAROUND
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
void
|
|
|
|
pkcs11Provider::slotEventHook () {
|
|
|
|
/*
|
2007-01-01 08:59:19 +00:00
|
|
|
* This is called from a separate
|
2006-04-03 21:14:17 +00:00
|
|
|
* thread.
|
|
|
|
*/
|
|
|
|
if (s_keyStoreList != NULL && _fSlotEventsActive) {
|
2007-04-07 15:34:35 +00:00
|
|
|
QMetaObject::invokeMethod(s_keyStoreList, "doUpdated", Qt::QueuedConnection);
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2006-04-03 21:14:17 +00:00
|
|
|
PKCS11H_BOOL
|
2007-04-04 02:30:31 +00:00
|
|
|
pkcs11Provider::tokenPromptHook (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token
|
|
|
|
) {
|
2007-04-04 02:30:31 +00:00
|
|
|
if (s_keyStoreList != NULL) {
|
2007-04-05 13:39:57 +00:00
|
|
|
return s_keyStoreList->tokenPrompt (user_data, token) ? TRUE : FALSE; //krazy:exclude=captruefalse
|
2007-04-04 02:30:31 +00:00
|
|
|
}
|
2007-01-20 10:25:18 +00:00
|
|
|
|
2007-04-03 10:04:57 +00:00
|
|
|
return FALSE; //krazy:exclude=captruefalse
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PKCS11H_BOOL
|
|
|
|
pkcs11Provider::pinPromptHook (
|
2007-04-05 13:39:57 +00:00
|
|
|
void * const user_data,
|
2006-04-03 21:14:17 +00:00
|
|
|
const pkcs11h_token_id_t token,
|
2006-12-07 22:45:07 +00:00
|
|
|
char * const pin,
|
|
|
|
const size_t pin_max
|
2006-04-03 21:14:17 +00:00
|
|
|
) {
|
2007-04-05 16:28:32 +00:00
|
|
|
PKCS11H_BOOL ret = FALSE; //krazy:exclude=captruefalse
|
2007-01-01 08:59:19 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
if (s_keyStoreList != NULL) {
|
2007-04-13 19:22:18 +00:00
|
|
|
SecureArray qpin;
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2007-04-05 16:28:32 +00:00
|
|
|
if (s_keyStoreList->pinPrompt (user_data, token, qpin)) {
|
2006-12-07 22:45:07 +00:00
|
|
|
if ((size_t)qpin.size () < pin_max-1) {
|
|
|
|
memmove (pin, qpin.constData (), qpin.size ());
|
|
|
|
pin[qpin.size ()] = '\0';
|
2007-04-05 16:28:32 +00:00
|
|
|
ret = TRUE; //krazy:exclude=captruefalse
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
}
|
2007-04-05 16:28:32 +00:00
|
|
|
|
|
|
|
return ret; //krazy:exclude=captruefalse
|
2006-04-03 21:14:17 +00:00
|
|
|
}
|
2005-07-28 12:41:07 +00:00
|
|
|
|
2007-04-13 00:42:19 +00:00
|
|
|
class pkcs11Plugin : public QObject, public QCAPlugin
|
2005-07-28 12:41:07 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2006-02-25 00:40:51 +00:00
|
|
|
Q_INTERFACES(QCAPlugin)
|
2006-04-03 21:14:17 +00:00
|
|
|
|
2005-07-28 12:41:07 +00:00
|
|
|
public:
|
2007-04-11 08:34:28 +00:00
|
|
|
virtual Provider *createProvider() { return new pkcs11Provider; }
|
2005-07-28 12:41:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#include "qca-pkcs11.moc"
|
|
|
|
|
2007-03-31 17:01:56 +00:00
|
|
|
Q_EXPORT_PLUGIN2(qca_pkcs11, pkcs11Plugin)
|