works for certimporter on win

master
Marc Wäckerlin 15 years ago
parent 6f1bd2ae87
commit 8de25e302d
  1. 38
      src/cryptoki.cxx
  2. 127
      src/cryptoki.hxx
  3. 3
      src/makefile.am

@ -11,35 +11,47 @@
#include <memory> #include <memory>
#ifndef WIN32 #ifndef WIN32
#include <dlfcn.h> #include <dlfcn.h>
#define CK_PTR *
typedef CK_FUNCTION_LIST CK_PTR CK_FUNCTION_LIST_PTR;
typedef CK_FUNCTION_LIST_PTR CK_PTR CK_FUNCTION_LIST_PTR_PTR;
typedef CK_RV (*CK_C_GetFunctionList)
(CK_FUNCTION_LIST_PTR_PTR ppFunctionList);
#else #else
#include <windows.h> #include <windows.h>
#undef ERROR #undef ERROR
#endif #endif
// no logging
#define CRYPTOKI_LOG(X)
namespace cryptoki { namespace cryptoki {
bool Init::functionList(const std::string& library) { bool Init::functionList(const std::string& library) {
CRYPTOKI_LOG("try to load: "<<library);
#ifndef WIN32 #ifndef WIN32
void* lib(dlopen(library.c_str(), RTLD_NOW)); void* lib(dlopen(library.c_str(), RTLD_NOW));
#else #else
HMODULE lib(LoadLibrary(library.c_str())); HINSTANCE lib(LoadLibrary(library.c_str()));
#endif #endif
if (!lib) throw exception("open of library failed: "+library); if (!lib) throw exception("open of library failed: "+library);
CRYPTOKI_LOG("loaded: "<<library);
#ifndef WIN32 #ifndef WIN32
CK_RV(*fn)(CK_FUNCTION_LIST**) CK_C_GetFunctionList fn
((CK_RV(*)(CK_FUNCTION_LIST**))dlsym(lib, "C_GetFunctionList")); ((CK_C_GetFunctionList)dlsym(lib, "C_GetFunctionList"));
#else #else
CK_RV(*fn)(CK_FUNCTION_LIST**) CK_C_GetFunctionList fn
((CK_RV(*)(CK_FUNCTION_LIST**))GetProcAddress(lib, "C_GetFunctionList")); ((CK_C_GetFunctionList)GetProcAddress(lib, "C_GetFunctionList"));
#endif #endif
if (!fn) if (!fn)
throw exception("required library symbol C_GetFunctionList not found in " throw exception("required library symbol C_GetFunctionList not found in "
+library); +library);
CRYPTOKI_LOG("Got C_GetFunctionList, now call it");
//! calls @c C_GetFunctionList //! calls @c C_GetFunctionList
return check(fn(&_fn), CRYPTOKI_FN_LOG("C_GetFunctionList")); return check(fn(&_fn), CRYPTOKI_FN_LOG("C_GetFunctionList"));
} }
bool Init::check(CK_RV result, const std::string& context) { bool Init::check(CK_RV result, const std::string& context) {
CRYPTOKI_LOG("log");
_res = result; _res = result;
if (_exc && !*this) if (_exc && !*this)
if (context.size()) if (context.size())
@ -50,6 +62,7 @@ namespace cryptoki {
} }
std::string Init::error(CK_RV res) { std::string Init::error(CK_RV res) {
CRYPTOKI_LOG("log");
switch (res) { switch (res) {
case CKR_OK: return "CKR_OK"; case CKR_OK: return "CKR_OK";
case CKR_CANCEL: return "CKR_CANCEL"; case CKR_CANCEL: return "CKR_CANCEL";
@ -158,18 +171,23 @@ namespace cryptoki {
Init::Init(const std::string& library, bool exc): Init::Init(const std::string& library, bool exc):
_exc(exc), _res(CKR_OK), _fn(0) { _exc(exc), _res(CKR_OK), _fn(0) {
CRYPTOKI_LOG("library: "<<library);
//! calls @c functionList //! calls @c functionList
if (!functionList(library)) return; if (!functionList(library)) return;
CRYPTOKI_LOG("now initialize "<<library);
assert(_fn);
//! calls @c C_Initialize //! calls @c C_Initialize
check(_fn->C_Initialize(0), //! @todo add optional argument check(_fn->C_Initialize(0), //! @todo add optional argument
CRYPTOKI_FN_LOG("C_Initialize")); CRYPTOKI_FN_LOG("C_Initialize"));
} }
Init::operator bool() { Init::operator bool() {
CRYPTOKI_LOG("log "<<(_res==CKR_OK?"success":"failed"));
return _res==CKR_OK; return _res==CKR_OK;
} }
std::string Init::error() { std::string Init::error() {
CRYPTOKI_LOG("log");
return error(_res); return error(_res);
} }
@ -183,6 +201,7 @@ namespace cryptoki {
@endcode */ @endcode */
SlotList Init::slotList(bool tokenPresent) { SlotList Init::slotList(bool tokenPresent) {
CRYPTOKI_LOG("log");
SlotList res; SlotList res;
CK_ULONG count(0); CK_ULONG count(0);
//! calls @c C_GetSlotList //! calls @c C_GetSlotList
@ -210,6 +229,7 @@ namespace cryptoki {
//============================================================================ //============================================================================
ObjectList Session::find(const AttributeList& attrs) { ObjectList Session::find(const AttributeList& attrs) {
CRYPTOKI_LOG("log");
ObjectList res; ObjectList res;
CK_ATTRIBUTE* a(0); CK_ATTRIBUTE* a(0);
try { try {
@ -243,6 +263,7 @@ namespace cryptoki {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
ObjectList Session::find(const Attribute& a) { ObjectList Session::find(const Attribute& a) {
CRYPTOKI_LOG("log");
AttributeList al; AttributeList al;
al.push_back(a); al.push_back(a);
return find(al); return find(al);
@ -250,6 +271,7 @@ namespace cryptoki {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
ObjectList Session::find(const Attribute& a1, const Attribute& a2) { ObjectList Session::find(const Attribute& a1, const Attribute& a2) {
CRYPTOKI_LOG("log");
AttributeList al; AttributeList al;
al.push_back(a1); al.push_back(a1);
al.push_back(a2); al.push_back(a2);
@ -258,6 +280,7 @@ namespace cryptoki {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
Object Session::create(const std::string& label, const openssl::X509& cert) { Object Session::create(const std::string& label, const openssl::X509& cert) {
CRYPTOKI_LOG("log");
AttributeList attrs; AttributeList attrs;
attrs.push_back(Attribute(CKA_CLASS) attrs.push_back(Attribute(CKA_CLASS)
.from<CK_OBJECT_CLASS>(CKO_CERTIFICATE)); .from<CK_OBJECT_CLASS>(CKO_CERTIFICATE));
@ -274,9 +297,11 @@ namespace cryptoki {
attrs.push_back(Attribute(CKA_VALUE, cert.valueDER())); attrs.push_back(Attribute(CKA_VALUE, cert.valueDER()));
return create(attrs); return create(attrs);
} }
Object Session::create(const std::string& label, Object Session::create(const std::string& label,
const openssl::PrivateKey& key, const openssl::PrivateKey& key,
const openssl::X509& cert) { const openssl::X509& cert) {
CRYPTOKI_LOG("log");
int usage(cert.keyUsageFlags()); int usage(cert.keyUsageFlags());
AttributeList attrs; AttributeList attrs;
attrs.push_back(Attribute(CKA_CLASS) attrs.push_back(Attribute(CKA_CLASS)
@ -314,14 +339,17 @@ namespace cryptoki {
attrs.push_back(Attribute(CKA_COEFFICIENT, key.coefficient())); attrs.push_back(Attribute(CKA_COEFFICIENT, key.coefficient()));
return create(attrs); return create(attrs);
} }
Object Session::create(const std::string& label, Object Session::create(const std::string& label,
const openssl::PKCS12& p12) { const openssl::PKCS12& p12) {
CRYPTOKI_LOG("log");
AttributeList attrs; AttributeList attrs;
return create(attrs); return create(attrs);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
Object Session::create(const AttributeList& attrs) { Object Session::create(const AttributeList& attrs) {
CRYPTOKI_LOG("log");
CK_ATTRIBUTE* a(0); CK_ATTRIBUTE* a(0);
try { try {
if (attrs.size()) { if (attrs.size()) {

@ -9,7 +9,11 @@
// interface // interface
#include <openssl.hxx> #include <openssl.hxx>
#include <pkcs11/apiclient.h> #ifndef WIN32
#include <opensc/pkcs11.h>
#else
#include <cryptoki.h>
#endif
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
@ -57,14 +61,14 @@
#if __GNUC__ >= 2 #if __GNUC__ >= 2
//! Cryptoki Logging //! Cryptoki Logging
/*! If you want to change cryptoki logging mechanism, just /*! If you want to change cryptoki logging mechanism, just
redefine your own CRYPTOKY_LOG macro before <code>#include redefine your own CRYPTOKI_LOG macro before <code>#include
&lt;cryptoki.hxx&gt;</code>. Define it empty for no logging at &lt;cryptoki.hxx&gt;</code>. Define it empty for no logging at
all. By default logs to <code>std::clog</code>. */ all. By default logs to <code>std::clog</code>. */
#define CRYPTOKI_LOG(X) std::clog<<X<<" @ "<<__PRETTY_FUNCTION__<<std::endl #define CRYPTOKI_LOG(X) std::clog<<X<<" @ "<<__PRETTY_FUNCTION__<<std::endl
#else #else
//! Cryptoki Logging //! Cryptoki Logging
/*! If you want to change cryptoki logging mechanism, just /*! If you want to change cryptoki logging mechanism, just
redefine your own CRYPTOKY_LOG macro before <code>#include redefine your own CRYPTOKI_LOG macro before <code>#include
&lt;cryptoki.hxx&gt;</code>. Define it empty for no logging at &lt;cryptoki.hxx&gt;</code>. Define it empty for no logging at
all. By default logs to <code>std::clog</code>. */ all. By default logs to <code>std::clog</code>. */
#define CRYPTOKI_LOG(X) std::clog<<X<<" @ "<<__FILE__<<__LINE__<<std::endl #define CRYPTOKI_LOG(X) std::clog<<X<<" @ "<<__FILE__<<__LINE__<<std::endl
@ -331,7 +335,7 @@ namespace cryptoki {
case CKA_SUBPRIME: return "SUBPRIME"; case CKA_SUBPRIME: return "SUBPRIME";
case CKA_BASE: return "BASE"; case CKA_BASE: return "BASE";
case CKA_PRIME_BITS: return "PRIME_BITS"; case CKA_PRIME_BITS: return "PRIME_BITS";
case CKA_SUBPRIME_BITS: return "SUBPRIME_BITS"; //case CKA_SUBPRIME_BITS: return "SUBPRIME_BITS";
case CKA_VALUE_BITS: return "VALUE_BITS"; case CKA_VALUE_BITS: return "VALUE_BITS";
case CKA_VALUE_LEN: return "VALUE_LEN"; case CKA_VALUE_LEN: return "VALUE_LEN";
case CKA_EXTRACTABLE: return "EXTRACTABLE"; case CKA_EXTRACTABLE: return "EXTRACTABLE";
@ -349,7 +353,7 @@ namespace cryptoki {
case CKA_RESET_ON_INIT: return "RESET_ON_INIT"; case CKA_RESET_ON_INIT: return "RESET_ON_INIT";
case CKA_HAS_RESET: return "HAS_RESET"; case CKA_HAS_RESET: return "HAS_RESET";
case CKA_VENDOR_DEFINED: return "VENDOR_DEFINED"; case CKA_VENDOR_DEFINED: return "VENDOR_DEFINED";
case CKA_IBM_OPAQUE: return "IBM_OPAQUE"; //case CKA_IBM_OPAQUE: return "IBM_OPAQUE";
default: return "unknown"; default: return "unknown";
} }
} }
@ -494,7 +498,7 @@ namespace cryptoki {
case CKM_X9_42_DH_DERIVE: name="X9_42_DH_DERIVE"; break; case CKM_X9_42_DH_DERIVE: name="X9_42_DH_DERIVE"; break;
case CKM_X9_42_DH_HYBRID_DERIVE: name="X9_42_DH_HYBRID_DERIVE"; break; case CKM_X9_42_DH_HYBRID_DERIVE: name="X9_42_DH_HYBRID_DERIVE"; break;
case CKM_X9_42_MQV_DERIVE: name="X9_42_MQV_DERIVE"; break; case CKM_X9_42_MQV_DERIVE: name="X9_42_MQV_DERIVE"; break;
case CKM_SHA256_RSA_PKCS: name="SHA256_RSA_PKCS"; break; //case CKM_SHA256_RSA_PKCS: name="SHA256_RSA_PKCS"; break;
case CKM_RC2_KEY_GEN: name="RC2_KEY_GEN"; break; case CKM_RC2_KEY_GEN: name="RC2_KEY_GEN"; break;
case CKM_RC2_ECB: name="RC2_ECB"; break; case CKM_RC2_ECB: name="RC2_ECB"; break;
case CKM_RC2_CBC: name="RC2_CBC"; break; case CKM_RC2_CBC: name="RC2_CBC"; break;
@ -537,15 +541,15 @@ namespace cryptoki {
case CKM_RIPEMD160: name="RIPEMD160"; break; case CKM_RIPEMD160: name="RIPEMD160"; break;
case CKM_RIPEMD160_HMAC: name="RIPEMD160_HMAC"; break; case CKM_RIPEMD160_HMAC: name="RIPEMD160_HMAC"; break;
case CKM_RIPEMD160_HMAC_GENERAL: name="RIPEMD160_HMAC_GENERAL"; break; case CKM_RIPEMD160_HMAC_GENERAL: name="RIPEMD160_HMAC_GENERAL"; break;
case CKM_SHA256: name="SHA256"; break; //case CKM_SHA256: name="SHA256"; break;
case CKM_SHA256_HMAC: name="SHA256_HMAC"; break; //case CKM_SHA256_HMAC: name="SHA256_HMAC"; break;
case CKM_SHA256_HMAC_GENERAL: name="SHA256_HMAC_GENERAL"; break; //case CKM_SHA256_HMAC_GENERAL: name="SHA256_HMAC_GENERAL"; break;
case CKM_SHA384: name="SHA384"; break; //case CKM_SHA384: name="SHA384"; break;
case CKM_SHA384_HMAC: name="SHA384_HMAC"; break; //case CKM_SHA384_HMAC: name="SHA384_HMAC"; break;
case CKM_SHA384_HMAC_GENERAL: name="SHA384_HMAC_GENERAL"; break; //case CKM_SHA384_HMAC_GENERAL: name="SHA384_HMAC_GENERAL"; break;
case CKM_SHA512: name="SHA512"; break; //case CKM_SHA512: name="SHA512"; break;
case CKM_SHA512_HMAC: name="SHA512_HMAC"; break; //case CKM_SHA512_HMAC: name="SHA512_HMAC"; break;
case CKM_SHA512_HMAC_GENERAL: name="SHA512_HMAC_GENERAL"; break; //case CKM_SHA512_HMAC_GENERAL: name="SHA512_HMAC_GENERAL"; break;
case CKM_CAST_KEY_GEN: name="CAST_KEY_GEN"; break; case CKM_CAST_KEY_GEN: name="CAST_KEY_GEN"; break;
case CKM_CAST_ECB: name="CAST_ECB"; break; case CKM_CAST_ECB: name="CAST_ECB"; break;
case CKM_CAST_CBC: name="CAST_CBC"; break; case CKM_CAST_CBC: name="CAST_CBC"; break;
@ -606,7 +610,7 @@ namespace cryptoki {
case CKM_MD5_KEY_DERIVATION: name="MD5_KEY_DERIVATION"; break; case CKM_MD5_KEY_DERIVATION: name="MD5_KEY_DERIVATION"; break;
case CKM_MD2_KEY_DERIVATION: name="MD2_KEY_DERIVATION"; break; case CKM_MD2_KEY_DERIVATION: name="MD2_KEY_DERIVATION"; break;
case CKM_SHA1_KEY_DERIVATION: name="SHA1_KEY_DERIVATION"; break; case CKM_SHA1_KEY_DERIVATION: name="SHA1_KEY_DERIVATION"; break;
case CKM_SHA256_KEY_DERIVATION: name="SHA256_KEY_DERIVATION"; break; //case CKM_SHA256_KEY_DERIVATION: name="SHA256_KEY_DERIVATION"; break;
case CKM_PBE_MD2_DES_CBC: name="PBE_MD2_DES_CBC"; break; case CKM_PBE_MD2_DES_CBC: name="PBE_MD2_DES_CBC"; break;
case CKM_PBE_MD5_DES_CBC: name="PBE_MD5_DES_CBC"; break; case CKM_PBE_MD5_DES_CBC: name="PBE_MD5_DES_CBC"; break;
case CKM_PBE_MD5_CAST_CBC: name="PBE_MD5_CAST_CBC"; break; case CKM_PBE_MD5_CAST_CBC: name="PBE_MD5_CAST_CBC"; break;
@ -759,6 +763,7 @@ namespace cryptoki {
Init(const std::string& library="onepin-opensc-pkcs11.so", bool exc=true); Init(const std::string& library="onepin-opensc-pkcs11.so", bool exc=true);
~Init() { ~Init() {
CRYPTOKI_LOG("log");
try { try {
//! calls @c C_Finalize //! calls @c C_Finalize
check(_fn->C_Finalize(0), CRYPTOKI_FN_LOG("C_Finalize")); check(_fn->C_Finalize(0), CRYPTOKI_FN_LOG("C_Finalize"));
@ -784,6 +789,7 @@ namespace cryptoki {
//@} //@}
Info info() { Info info() {
CRYPTOKI_LOG("log");
Info inf; Info inf;
CK_INFO cInf; CK_INFO cInf;
//! calls @c C_GetInfo //! calls @c C_GetInfo
@ -818,9 +824,11 @@ namespace cryptoki {
Slot(Init& init, CK_SLOT_ID slot): Slot(Init& init, CK_SLOT_ID slot):
_init(&init), _slot(slot), _res(CKR_OK) { _init(&init), _slot(slot), _res(CKR_OK) {
CRYPTOKI_LOG("log");
} }
bool check(CK_RV result, const std::string& context="") { bool check(CK_RV result, const std::string& context="") {
CRYPTOKI_LOG("log");
_res = result; _res = result;
if (_init->_exc && !*this) if (_init->_exc && !*this)
if (!context.empty()) if (!context.empty())
@ -834,9 +842,11 @@ namespace cryptoki {
//! Don't use without assignment! For standard containers only! //! Don't use without assignment! For standard containers only!
Slot(): _init(0) { Slot(): _init(0) {
CRYPTOKI_LOG("log");
} }
Slot& operator=(const Slot& o) { Slot& operator=(const Slot& o) {
CRYPTOKI_LOG("log");
_init = o._init; _init = o._init;
_slot = o._slot; _slot = o._slot;
_res = o._res; _res = o._res;
@ -853,17 +863,20 @@ namespace cryptoki {
/*! @return @c true if last cryptoki on this object call was successful */ /*! @return @c true if last cryptoki on this object call was successful */
operator bool() { operator bool() {
CRYPTOKI_LOG("log");
return _res==CKR_OK; return _res==CKR_OK;
} }
/*! @return error text of last cryptoki call */ /*! @return error text of last cryptoki call */
std::string error() { std::string error() {
CRYPTOKI_LOG("log");
return _init->error(_res); return _init->error(_res);
} }
//@} //@}
MechanismInfo mechanisminfo(CK_MECHANISM_TYPE mechanism) { MechanismInfo mechanisminfo(CK_MECHANISM_TYPE mechanism) {
CRYPTOKI_LOG("log");
MechanismInfo info(mechanism); MechanismInfo info(mechanism);
CK_MECHANISM_INFO cInfo; CK_MECHANISM_INFO cInfo;
//! calls @c C_GetMechanismInfo //! calls @c C_GetMechanismInfo
@ -876,6 +889,7 @@ namespace cryptoki {
} }
MechanismList mechanismlist() { MechanismList mechanismlist() {
CRYPTOKI_LOG("log");
MechanismList res; MechanismList res;
CK_ULONG count(0); CK_ULONG count(0);
//! calls @c C_GetMechanismList //! calls @c C_GetMechanismList
@ -900,6 +914,7 @@ namespace cryptoki {
} }
SlotInfo slotinfo() { SlotInfo slotinfo() {
CRYPTOKI_LOG("log");
SlotInfo info; SlotInfo info;
CK_SLOT_INFO cInfo; CK_SLOT_INFO cInfo;
//! calls @c C_GetSlotInfo //! calls @c C_GetSlotInfo
@ -914,6 +929,7 @@ namespace cryptoki {
} }
TokenInfo tokeninfo() { TokenInfo tokeninfo() {
CRYPTOKI_LOG("log");
TokenInfo info; TokenInfo info;
//! calls @c C_GetTokenInfo //! calls @c C_GetTokenInfo
CK_TOKEN_INFO cInfo; CK_TOKEN_INFO cInfo;
@ -943,6 +959,7 @@ namespace cryptoki {
/*! @bug does not compile: /*! @bug does not compile:
@code @code
bool inittoken(std::string pin, FixString<32> label) { bool inittoken(std::string pin, FixString<32> label) {
CRYPTOKI_LOG("log");
//! calls @c C_InitToken //! calls @c C_InitToken
return check(_init->_fn->C_InitToken return check(_init->_fn->C_InitToken
(_slot, (_slot,
@ -959,6 +976,7 @@ namespace cryptoki {
} }
bool registerforslotevent(SlotEventListener&) { bool registerforslotevent(SlotEventListener&) {
CRYPTOKI_LOG("log");
//! calls @c C_WaitForSlotEvent //! calls @c C_WaitForSlotEvent
return check(_init->_fn->C_WaitForSlotEvent(CK_FLAGS, &_slot, CK_VOID_PTR), return check(_init->_fn->C_WaitForSlotEvent(CK_FLAGS, &_slot, CK_VOID_PTR),
CRYPTOKI_FN_LOG("C_WaitForSlotEvent")); CRYPTOKI_FN_LOG("C_WaitForSlotEvent"));
@ -981,6 +999,7 @@ namespace cryptoki {
Session(); // forbidden Session(); // forbidden
bool check(CK_RV result, const std::string& context="") { bool check(CK_RV result, const std::string& context="") {
CRYPTOKI_LOG("log");
_res = result; _res = result;
if (_slot._init->_exc && !*this) if (_slot._init->_exc && !*this)
if (!context.empty()) if (!context.empty())
@ -991,6 +1010,7 @@ namespace cryptoki {
} }
void free() { void free() {
CRYPTOKI_LOG("log");
try { try {
//! closes login. //! closes login.
_login.reset(); _login.reset();
@ -1008,6 +1028,7 @@ namespace cryptoki {
/*! @param slot slot to open a session on */ /*! @param slot slot to open a session on */
Session(Slot& slot, bool rw=false): Session(Slot& slot, bool rw=false):
_slot(slot), _session(0), _res(CKR_OK) { _slot(slot), _session(0), _res(CKR_OK) {
CRYPTOKI_LOG("log");
//! calls @c C_OpenSession //! calls @c C_OpenSession
check(_slot._init->_fn->C_OpenSession check(_slot._init->_fn->C_OpenSession
(_slot._slot, CKF_SERIAL_SESSION|(rw?CKF_RW_SESSION:0), (_slot._slot, CKF_SERIAL_SESSION|(rw?CKF_RW_SESSION:0),
@ -1019,13 +1040,16 @@ namespace cryptoki {
Session(const Session& o): Session(const Session& o):
SmartResource(o), SmartResource(o),
_slot(o._slot), _session(o._session), _res(o._res) { _slot(o._slot), _session(o._session), _res(o._res) {
CRYPTOKI_LOG("log");
} }
~Session() { ~Session() {
CRYPTOKI_LOG("log");
destruct(); destruct();
} }
Session& operator=(const Session& o) { Session& operator=(const Session& o) {
CRYPTOKI_LOG("log");
SmartResource::operator=(o); SmartResource::operator=(o);
_slot = o._slot; _slot = o._slot;
_session = o._session; _session = o._session;
@ -1066,11 +1090,13 @@ namespace cryptoki {
/*! @return @c true if last cryptoki on this object call was successful */ /*! @return @c true if last cryptoki on this object call was successful */
operator bool() { operator bool() {
CRYPTOKI_LOG("log");
return _res==CKR_OK; return _res==CKR_OK;
} }
/*! @return error text of last cryptoki call */ /*! @return error text of last cryptoki call */
std::string error() { std::string error() {
CRYPTOKI_LOG("log");
return _slot._init->error(_res); return _slot._init->error(_res);
} }
@ -1083,6 +1109,7 @@ namespace cryptoki {
//@{ //@{
bool cancel() { bool cancel() {
CRYPTOKI_LOG("log");
//! calls @c C_CancelFunction //! calls @c C_CancelFunction
return check(_slot._init->_fn->C_CancelFunction(_session), return check(_slot._init->_fn->C_CancelFunction(_session),
CRYPTOKI_FN_LOG("C_CancelFunction")); CRYPTOKI_FN_LOG("C_CancelFunction"));
@ -1092,6 +1119,7 @@ namespace cryptoki {
Object create(const AttributeList& attrs); Object create(const AttributeList& attrs);
std::string digest(std::string in) { std::string digest(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1106,6 +1134,7 @@ namespace cryptoki {
} }
std::string digestencryptupdate(std::string in) { std::string digestencryptupdate(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1122,6 +1151,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool digestfinal() { bool digestfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_DigestFinal //! calls @c C_DigestFinal
return check(_slot._init->_fn->C_DigestFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_slot._init->_fn->C_DigestFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_DigestFinal")); CRYPTOKI_FN_LOG("C_DigestFinal"));
@ -1131,6 +1161,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool digestinit() { bool digestinit() {
CRYPTOKI_LOG("log");
//! calls @c C_DigestInit //! calls @c C_DigestInit
return check(_slot._init->_fn->C_DigestInit(_session, CK_MECHANISM_PTR), return check(_slot._init->_fn->C_DigestInit(_session, CK_MECHANISM_PTR),
CRYPTOKI_FN_LOG("C_DigestInit")); CRYPTOKI_FN_LOG("C_DigestInit"));
@ -1140,6 +1171,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool digestupdate() { bool digestupdate() {
CRYPTOKI_LOG("log");
//! calls @c C_DigestUpdate //! calls @c C_DigestUpdate
return check(_slot._init->_fn->C_DigestUpdate(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_DigestUpdate(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_DigestUpdate")); CRYPTOKI_FN_LOG("C_DigestUpdate"));
@ -1149,6 +1181,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool findobjectsfinal() { bool findobjectsfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_FindObjectsFinal //! calls @c C_FindObjectsFinal
return check(_slot._init->_fn->C_FindObjectsFinal(_session), return check(_slot._init->_fn->C_FindObjectsFinal(_session),
CRYPTOKI_FN_LOG("C_FindObjectsFinal")); CRYPTOKI_FN_LOG("C_FindObjectsFinal"));
@ -1158,6 +1191,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool findobjectsinit() { bool findobjectsinit() {
CRYPTOKI_LOG("log");
//! calls @c C_FindObjectsInit //! calls @c C_FindObjectsInit
return check(_slot._init->_fn->C_FindObjectsInit(_session, CK_ATTRIBUTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_FindObjectsInit(_session, CK_ATTRIBUTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_FindObjectsInit")); CRYPTOKI_FN_LOG("C_FindObjectsInit"));
@ -1167,6 +1201,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool findobjects() { bool findobjects() {
CRYPTOKI_LOG("log");
//! calls @c C_FindObjects //! calls @c C_FindObjects
return check(_session._slot._init->_fn->C_FindObjects(_session, CK_OBJECT_HANDLE_PTR, CK_ULONG, return check(_session._slot._init->_fn->C_FindObjects(_session, CK_OBJECT_HANDLE_PTR, CK_ULONG,
CK_ULONG_PTR), CK_ULONG_PTR),
@ -1177,6 +1212,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool generaterandom() { bool generaterandom() {
CRYPTOKI_LOG("log");
//! calls @c C_GenerateRandom //! calls @c C_GenerateRandom
return check(_slot._init->_fn->C_GenerateRandom(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_GenerateRandom(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_GenerateRandom")); CRYPTOKI_FN_LOG("C_GenerateRandom"));
@ -1186,6 +1222,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool getfunctionstatus() { bool getfunctionstatus() {
CRYPTOKI_LOG("log");
//! calls @c C_GetFunctionStatus //! calls @c C_GetFunctionStatus
return check(_slot._init->_fn->C_GetFunctionStatus(_session), return check(_slot._init->_fn->C_GetFunctionStatus(_session),
CRYPTOKI_FN_LOG("C_GetFunctionStatus")); CRYPTOKI_FN_LOG("C_GetFunctionStatus"));
@ -1195,6 +1232,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool getoperationstate() { bool getoperationstate() {
CRYPTOKI_LOG("log");
//! calls @c C_GetOperationState //! calls @c C_GetOperationState
return check(_slot._init->_fn->C_GetOperationState(_session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_slot._init->_fn->C_GetOperationState(_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_GetOperationState")); CRYPTOKI_FN_LOG("C_GetOperationState"));
@ -1204,6 +1242,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool getsessioninfo() { bool getsessioninfo() {
CRYPTOKI_LOG("log");
//! calls @c C_GetSessionInfo //! calls @c C_GetSessionInfo
return check(_slot._init->_fn->C_GetSessionInfo(_session, CK_SESSION_INFO_PTR), return check(_slot._init->_fn->C_GetSessionInfo(_session, CK_SESSION_INFO_PTR),
CRYPTOKI_FN_LOG("C_GetSessionInfo")); CRYPTOKI_FN_LOG("C_GetSessionInfo"));
@ -1213,6 +1252,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool initpin() { bool initpin() {
CRYPTOKI_LOG("log");
//! calls @c C_InitPIN //! calls @c C_InitPIN
return check(_slot._init->_fn->C_InitPIN(_session, CK_CHAR_PTR, CK_ULONG), return check(_slot._init->_fn->C_InitPIN(_session, CK_CHAR_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_InitPIN")); CRYPTOKI_FN_LOG("C_InitPIN"));
@ -1226,6 +1266,7 @@ namespace cryptoki {
Login(Session& session, Login(Session& session,
const std::string& pin, const std::string& pin,
CK_USER_TYPE userType=CKU_USER): _session(session) { CK_USER_TYPE userType=CKU_USER): _session(session) {
CRYPTOKI_LOG("log");
//! calls @c C_Login //! calls @c C_Login
_session.check(_session._slot._init->_fn->C_Login _session.check(_session._slot._init->_fn->C_Login
(_session._session, userType, (_session._session, userType,
@ -1252,9 +1293,11 @@ namespace cryptoki {
}; };
void login(const std::string& pin, CK_USER_TYPE userType=CKU_USER) { void login(const std::string& pin, CK_USER_TYPE userType=CKU_USER) {
CRYPTOKI_LOG("log");
_login = SharedPointer<Login>(new Login(*this, pin, userType)); _login = SharedPointer<Login>(new Login(*this, pin, userType));
} }
void logout() { void logout() {
CRYPTOKI_LOG("log");
_login.reset(); _login.reset();
} }
SharedPointer<Login> _login; SharedPointer<Login> _login;
@ -1262,6 +1305,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool seedrandom() { bool seedrandom() {
CRYPTOKI_LOG("log");
//! calls @c C_SeedRandom //! calls @c C_SeedRandom
return check(_slot._init->_fn->C_SeedRandom(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_SeedRandom(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SeedRandom")); CRYPTOKI_FN_LOG("C_SeedRandom"));
@ -1271,6 +1315,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool setpin() { bool setpin() {
CRYPTOKI_LOG("log");
//! calls @c C_SetPIN //! calls @c C_SetPIN
return check(_slot._init->_fn->C_SetPIN(_session, CK_CHAR_PTR, CK_ULONG, CK_CHAR_PTR, CK_ULONG), return check(_slot._init->_fn->C_SetPIN(_session, CK_CHAR_PTR, CK_ULONG, CK_CHAR_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SetPIN")); CRYPTOKI_FN_LOG("C_SetPIN"));
@ -1278,6 +1323,7 @@ namespace cryptoki {
@endcode */ @endcode */
std::string sign(std::string in) { std::string sign(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1292,6 +1338,7 @@ namespace cryptoki {
} }
std::string signencryptupdate(std::string in) { std::string signencryptupdate(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1308,6 +1355,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool signfinal() { bool signfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_SignFinal //! calls @c C_SignFinal
return check(_slot._init->_fn->C_SignFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_slot._init->_fn->C_SignFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_SignFinal")); CRYPTOKI_FN_LOG("C_SignFinal"));
@ -1315,6 +1363,7 @@ namespace cryptoki {
@endcode */ @endcode */
std::string signrecover(std::string in) { std::string signrecover(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1331,6 +1380,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool signupdate() { bool signupdate() {
CRYPTOKI_LOG("log");
//! calls @c C_SignUpdate //! calls @c C_SignUpdate
return check(_slot._init->_fn->C_SignUpdate(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_SignUpdate(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SignUpdate")); CRYPTOKI_FN_LOG("C_SignUpdate"));
@ -1340,6 +1390,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool verify() { bool verify() {
CRYPTOKI_LOG("log");
//! calls @c C_Verify //! calls @c C_Verify
return check(_slot._init->_fn->C_Verify(_session, CK_BYTE_PTR, CK_ULONG, return check(_slot._init->_fn->C_Verify(_session, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG), CK_BYTE_PTR, CK_ULONG),
@ -1350,6 +1401,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool verifyfinal() { bool verifyfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_VerifyFinal //! calls @c C_VerifyFinal
return check(_slot._init->_fn->C_VerifyFinal(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_VerifyFinal(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_VerifyFinal")); CRYPTOKI_FN_LOG("C_VerifyFinal"));
@ -1357,6 +1409,7 @@ namespace cryptoki {
@endcode */ @endcode */
std::string verifyrecover(std::string in) { std::string verifyrecover(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1373,6 +1426,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool verifyupdate() { bool verifyupdate() {
CRYPTOKI_LOG("log");
//! calls @c C_VerifyUpdate //! calls @c C_VerifyUpdate
return check(_slot._init->_fn->C_VerifyUpdate(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_VerifyUpdate(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_VerifyUpdate")); CRYPTOKI_FN_LOG("C_VerifyUpdate"));
@ -1392,6 +1446,7 @@ namespace cryptoki {
CK_RV _res; CK_RV _res;
bool check(CK_RV result, const std::string& context="") { bool check(CK_RV result, const std::string& context="") {
CRYPTOKI_LOG("log");
_res = result; _res = result;
if (_session._slot._init->_exc && !*this) if (_session._slot._init->_exc && !*this)
if (!context.empty()) if (!context.empty())
@ -1402,15 +1457,18 @@ namespace cryptoki {
} }
Object() { Object() {
CRYPTOKI_LOG("log");
} }
Object(const Session& session, CK_OBJECT_HANDLE obj): Object(const Session& session, CK_OBJECT_HANDLE obj):
_session(session), _object(obj), _res(CKR_OK) { _session(session), _object(obj), _res(CKR_OK) {
CRYPTOKI_LOG("log");
} }
public: public:
Object& operator=(Object& o) { Object& operator=(Object& o) {
CRYPTOKI_LOG("log");
_object = o._object; _object = o._object;
_session = o._session; _session = o._session;
_res = o._res; _res = o._res;
@ -1425,6 +1483,7 @@ namespace cryptoki {
std::string decrypt(std::string data, CK_MECHANISM_TYPE type, std::string decrypt(std::string data, CK_MECHANISM_TYPE type,
std::string param=std::string()) { std::string param=std::string()) {
CRYPTOKI_LOG("log");
CRYPTOKI_LOG("decryptinit"); CRYPTOKI_LOG("decryptinit");
decryptinit(type, param); decryptinit(type, param);
CRYPTOKI_LOG("decrypt"); CRYPTOKI_LOG("decrypt");
@ -1444,11 +1503,13 @@ namespace cryptoki {
/*! @return @c true if last cryptoki on this object call was successful */ /*! @return @c true if last cryptoki on this object call was successful */
operator bool() { operator bool() {
CRYPTOKI_LOG("log");
return _res==CKR_OK; return _res==CKR_OK;
} }
/*! @return error text of last cryptoki call */ /*! @return error text of last cryptoki call */
std::string error() { std::string error() {
CRYPTOKI_LOG("log");
return _session._slot._init->error(_res); return _session._slot._init->error(_res);
} }
@ -1463,6 +1524,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool copyobject() { bool copyobject() {
CRYPTOKI_LOG("log");
//! calls @c C_CopyObject //! calls @c C_CopyObject
return check(_session._slot._init->_fn->C_CopyObject(_session._session, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_CopyObject(_session._session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR), CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
@ -1471,6 +1533,7 @@ namespace cryptoki {
@endcode */ @endcode */
bool decryptinit(CK_MECHANISM_TYPE type, std::string param) { bool decryptinit(CK_MECHANISM_TYPE type, std::string param) {
CRYPTOKI_LOG("log");
CK_MECHANISM mech = { CK_MECHANISM mech = {
type, param.size()?&param[0]:0, param.size() type, param.size()?&param[0]:0, param.size()
}; };
@ -1484,6 +1547,7 @@ namespace cryptoki {
//! requires decryptinit to be called before //! requires decryptinit to be called before
std::string decrypt(std::string in) { std::string decrypt(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
CK_ULONG size(0); // two calls, first to get minimum buffer length CK_ULONG size(0); // two calls, first to get minimum buffer length
CRYPTOKI_LOG("get size"); CRYPTOKI_LOG("get size");
@ -1505,6 +1569,7 @@ namespace cryptoki {
} }
std::string decryptdigestupdate(std::string in) { std::string decryptdigestupdate(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1519,6 +1584,7 @@ namespace cryptoki {
} }
bool decryptfinal() { bool decryptfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_DecryptFinal //! calls @c C_DecryptFinal
return check(_session._slot._init->_fn->C_DecryptFinal return check(_session._slot._init->_fn->C_DecryptFinal
(_session._session, 0, 0), (_session._session, 0, 0),
@ -1527,6 +1593,7 @@ namespace cryptoki {
} }
std::string decryptupdate(std::string in) { std::string decryptupdate(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1541,6 +1608,7 @@ namespace cryptoki {
} }
std::string decryptverifyupdate(std::string in) { std::string decryptverifyupdate(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1557,6 +1625,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool derivekey() { bool derivekey() {
CRYPTOKI_LOG("log");
//! calls @c C_DeriveKey //! calls @c C_DeriveKey
return check(_session._slot._init->_fn->C_DeriveKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_DeriveKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR), CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
@ -1565,6 +1634,7 @@ namespace cryptoki {
@endcode */ @endcode */
bool destroy() { bool destroy() {
CRYPTOKI_LOG("log");
//! calls @c C_DestroyObject //! calls @c C_DestroyObject
return check(_session._slot._init->_fn->C_DestroyObject return check(_session._slot._init->_fn->C_DestroyObject
(_session._session, _object), (_session._session, _object),
@ -1575,6 +1645,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool digestkey() { bool digestkey() {
CRYPTOKI_LOG("log");
//! calls @c C_DigestKey //! calls @c C_DigestKey
return check(_session._slot._init->_fn->C_DigestKey(_session._session, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_DigestKey(_session._session, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_DigestKey")); CRYPTOKI_FN_LOG("C_DigestKey"));
@ -1585,6 +1656,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool encryptinit() { bool encryptinit() {
CRYPTOKI_LOG("log");
//! calls @c C_EncryptInit //! calls @c C_EncryptInit
return check(_session._slot._init->_fn->C_EncryptInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_EncryptInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_EncryptInit")); CRYPTOKI_FN_LOG("C_EncryptInit"));
@ -1592,6 +1664,7 @@ namespace cryptoki {
@endcode */ @endcode */
std::string encrypt(std::string in) { std::string encrypt(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1608,6 +1681,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool encryptfinal() { bool encryptfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_EncryptFinal //! calls @c C_EncryptFinal
return check(_session._slot._init->_fn->C_EncryptFinal(_session._session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_session._slot._init->_fn->C_EncryptFinal(_session._session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_EncryptFinal")); CRYPTOKI_FN_LOG("C_EncryptFinal"));
@ -1615,6 +1689,7 @@ namespace cryptoki {
@endcode */ @endcode */
std::string encryptupdate(std::string in) { std::string encryptupdate(std::string in) {
CRYPTOKI_LOG("log");
std::string res; std::string res;
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
@ -1631,6 +1706,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool generatekey() { bool generatekey() {
CRYPTOKI_LOG("log");
//! calls @c C_GenerateKey //! calls @c C_GenerateKey
return check(_session._slot._init->_fn->C_GenerateKey(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR, return check(_session._slot._init->_fn->C_GenerateKey(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
CK_ULONG, CK_OBJECT_HANDLE_PTR), CK_ULONG, CK_OBJECT_HANDLE_PTR),
@ -1642,6 +1718,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool generatekeypair() { bool generatekeypair() {
CRYPTOKI_LOG("log");
//! calls @c C_GenerateKeyPair //! calls @c C_GenerateKeyPair
return check(_session._slot._init->_fn->C_GenerateKeyPair(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR, return check(_session._slot._init->_fn->C_GenerateKeyPair(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
@ -1653,11 +1730,13 @@ namespace cryptoki {
//! Get a Single Attribute //! Get a Single Attribute
Attribute operator[](CK_ATTRIBUTE_TYPE a) { Attribute operator[](CK_ATTRIBUTE_TYPE a) {
CRYPTOKI_LOG("log");
return attribute(a); return attribute(a);
} }
//! Get a Single Attribute //! Get a Single Attribute
Attribute attribute(CK_ATTRIBUTE_TYPE a) { Attribute attribute(CK_ATTRIBUTE_TYPE a) {
CRYPTOKI_LOG("log");
Attribute res; Attribute res;
CK_ATTRIBUTE attr((CK_ATTRIBUTE){a, 0, 0}); CK_ATTRIBUTE attr((CK_ATTRIBUTE){a, 0, 0});
//! calls @c C_GetAttributeValue //! calls @c C_GetAttributeValue
@ -1714,6 +1793,7 @@ namespace cryptoki {
is no exception in this case. */ is no exception in this case. */
AttributeMap attributes(AttributeTypeList attrs AttributeMap attributes(AttributeTypeList attrs
= AttributeTypeList()) { = AttributeTypeList()) {
CRYPTOKI_LOG("log");
AttributeMap res; AttributeMap res;
//! Gets all attributes, if @c attrs is empty //! Gets all attributes, if @c attrs is empty
if (attrs.empty()) { if (attrs.empty()) {
@ -1759,7 +1839,7 @@ namespace cryptoki {
attrs.push_back(CKA_SUBPRIME); attrs.push_back(CKA_SUBPRIME);
attrs.push_back(CKA_BASE); attrs.push_back(CKA_BASE);
attrs.push_back(CKA_PRIME_BITS); attrs.push_back(CKA_PRIME_BITS);
attrs.push_back(CKA_SUBPRIME_BITS); //attrs.push_back(CKA_SUBPRIME_BITS);
attrs.push_back(CKA_VALUE_BITS); attrs.push_back(CKA_VALUE_BITS);
attrs.push_back(CKA_VALUE_LEN); attrs.push_back(CKA_VALUE_LEN);
attrs.push_back(CKA_EXTRACTABLE); attrs.push_back(CKA_EXTRACTABLE);
@ -1777,7 +1857,7 @@ namespace cryptoki {
attrs.push_back(CKA_RESET_ON_INIT); attrs.push_back(CKA_RESET_ON_INIT);
attrs.push_back(CKA_HAS_RESET); attrs.push_back(CKA_HAS_RESET);
attrs.push_back(CKA_VENDOR_DEFINED); attrs.push_back(CKA_VENDOR_DEFINED);
attrs.push_back(CKA_IBM_OPAQUE); //attrs.push_back(CKA_IBM_OPAQUE);
} }
CK_ATTRIBUTE attr; CK_ATTRIBUTE attr;
for (AttributeTypeList::const_iterator it(attrs.begin()); for (AttributeTypeList::const_iterator it(attrs.begin());
@ -1855,6 +1935,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool getobjectsize() { bool getobjectsize() {
CRYPTOKI_LOG("log");
//! calls @c C_GetObjectSize //! calls @c C_GetObjectSize
return check(_session._slot._init->_fn->C_GetObjectSize(_session._session, CK_OBJECT_HANDLE, CK_ULONG_PTR), return check(_session._slot._init->_fn->C_GetObjectSize(_session._session, CK_OBJECT_HANDLE, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_GetObjectSize")); CRYPTOKI_FN_LOG("C_GetObjectSize"));
@ -1865,6 +1946,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool setattributevalue() { bool setattributevalue() {
CRYPTOKI_LOG("log");
//! calls @c C_SetAttributeValue //! calls @c C_SetAttributeValue
return check(_session._slot._init->_fn->C_SetAttributeValue(_session._session, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_SetAttributeValue(_session._session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG), CK_ATTRIBUTE_PTR, CK_ULONG),
@ -1875,6 +1957,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool setoperationstate() { bool setoperationstate() {
CRYPTOKI_LOG("log");
//! calls @c C_SetOperationState //! calls @c C_SetOperationState
return check(_session._slot._init->_fn->C_SetOperationState(_session._session, CK_BYTE_PTR, CK_ULONG, return check(_session._slot._init->_fn->C_SetOperationState(_session._session, CK_BYTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE, CK_OBJECT_HANDLE), CK_OBJECT_HANDLE, CK_OBJECT_HANDLE),
@ -1885,6 +1968,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool signinit() { bool signinit() {
CRYPTOKI_LOG("log");
//! calls @c C_SignInit //! calls @c C_SignInit
return check(_session._slot._init->_fn->C_SignInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_SignInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SignInit")); CRYPTOKI_FN_LOG("C_SignInit"));
@ -1895,6 +1979,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool signrecoverinit() { bool signrecoverinit() {
CRYPTOKI_LOG("log");
//! calls @c C_SignRecoverInit //! calls @c C_SignRecoverInit
return check(_session._slot._init->_fn->C_SignRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_SignRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SignRecoverInit")); CRYPTOKI_FN_LOG("C_SignRecoverInit"));
@ -1904,6 +1989,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool unwrapkey() { bool unwrapkey() {
CRYPTOKI_LOG("log");
//! calls @c C_UnwrapKey //! calls @c C_UnwrapKey
return check(_session._slot._init->_fn->C_UnwrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_UnwrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_BYTE_PTR, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG, CK_BYTE_PTR, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
@ -1915,6 +2001,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool verifyinit() { bool verifyinit() {
CRYPTOKI_LOG("log");
//! calls @c C_VerifyInit //! calls @c C_VerifyInit
return check(_session._slot._init->_fn->C_VerifyInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_VerifyInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_VerifyInit")); CRYPTOKI_FN_LOG("C_VerifyInit"));
@ -1925,6 +2012,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool verifyrecoverinit() { bool verifyrecoverinit() {
CRYPTOKI_LOG("log");
//! calls @c C_VerifyRecoverInit //! calls @c C_VerifyRecoverInit
return check(_session._slot._init->_fn->C_VerifyRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_VerifyRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_VerifyRecoverInit")); CRYPTOKI_FN_LOG("C_VerifyRecoverInit"));
@ -1935,6 +2023,7 @@ namespace cryptoki {
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool wrapkey() { bool wrapkey() {
CRYPTOKI_LOG("log");
//! calls @c C_WrapKey //! calls @c C_WrapKey
return check(_session._slot._init->_fn->C_WrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_WrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_OBJECT_HANDLE, CK_BYTE_PTR, CK_ULONG_PTR), CK_OBJECT_HANDLE, CK_BYTE_PTR, CK_ULONG_PTR),
@ -1953,11 +2042,13 @@ namespace cryptoki {
//@{ //@{
inline cryptoki::AttributeList& operator<<(cryptoki::AttributeList& list, inline cryptoki::AttributeList& operator<<(cryptoki::AttributeList& list,
const cryptoki::Attribute& attr) { const cryptoki::Attribute& attr) {
CRYPTOKI_LOG("log");
list.push_back(attr); list.push_back(attr);
return list; return list;
} }
inline cryptoki::AttributeList operator<<(const cryptoki::AttributeList& list, inline cryptoki::AttributeList operator<<(const cryptoki::AttributeList& list,
const cryptoki::Attribute& attr) { const cryptoki::Attribute& attr) {
CRYPTOKI_LOG("log");
cryptoki::AttributeList res(list); cryptoki::AttributeList res(list);
res.push_back(attr); res.push_back(attr);
return res; return res;

@ -6,12 +6,11 @@
## 45678901234567890123456789012345678901234567890123456789012345678901234567890 ## 45678901234567890123456789012345678901234567890123456789012345678901234567890
include_HEADERS = pcsc.hxx cryptoki.hxx openssl.hxx cryptaux.hxx include_HEADERS = pcsc.hxx cryptoki.hxx openssl.hxx cryptaux.hxx
pkcs11_HEADERS = pkcs11/pkcs11.h pkcs11/pkcs11types.h pkcs11/apiclient.h
pkcs11dir = ${includedir}/pkcs11 pkcs11dir = ${includedir}/pkcs11
lib_LTLIBRARIES = libcryptoki++.la lib_LTLIBRARIES = libcryptoki++.la
libcryptoki___la_SOURCES = cryptoki.cxx cryptoki.hxx ${pkcs11_HEADERS} libcryptoki___la_SOURCES = cryptoki.cxx cryptoki.hxx
libcryptoki___la_LIBADD = -lssl libcryptoki___la_LIBADD = -lssl
clean-local: clean-local:

Loading…
Cancel
Save