works for certimporter on win

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

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

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

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

Loading…
Cancel
Save