master
Marc Wäckerlin 15 years ago
parent f1cd9514f3
commit b5643a87a2
  1. 17
      doc/examples/cryptoki-demo.cxx
  2. 525
      src/cryptoki.hxx

@ -16,7 +16,7 @@ int main(int argc, char const*const*const argv) try {
cryptoki::SlotList slots(init.slotList()); cryptoki::SlotList slots(init.slotList());
for (cryptoki::SlotList::iterator it(slots.begin()); it!=slots.end(); ++it) for (cryptoki::SlotList::iterator it(slots.begin()); it!=slots.end(); ++it)
try { try {
cryptoki::SlotInfo slotInfo(it->slotInfo()); cryptoki::SlotInfo slotInfo(it->slotinfo());
std::cout<<"##################### S-CARD #####################"<<std::endl std::cout<<"##################### S-CARD #####################"<<std::endl
<<"slotDescription: \""<<slotInfo.slotDescription<<'"'<<std::endl <<"slotDescription: \""<<slotInfo.slotDescription<<'"'<<std::endl
<<"manufacturerID: \""<<slotInfo.manufacturerID<<'"'<<std::endl <<"manufacturerID: \""<<slotInfo.manufacturerID<<'"'<<std::endl
@ -25,8 +25,8 @@ int main(int argc, char const*const*const argv) try {
<<'.'<<(int)slotInfo.hardwareVersion.minor<<'"'<<std::endl <<'.'<<(int)slotInfo.hardwareVersion.minor<<'"'<<std::endl
<<"firmwareVersion: \""<<(int)slotInfo.firmwareVersion.major <<"firmwareVersion: \""<<(int)slotInfo.firmwareVersion.major
<<'.'<<(int)slotInfo.firmwareVersion.minor<<'"'<<std::endl; <<'.'<<(int)slotInfo.firmwareVersion.minor<<'"'<<std::endl;
cryptoki::TokenInfo info(it->tokenInfo()); cryptoki::TokenInfo info(it->tokeninfo());
std::cout<<"--------------------------------------------------"<<std::endl std::cout<<"--------------------- Token ----------------------"<<std::endl
<<"label: \""<<info.label<<'"'<<std::endl <<"label: \""<<info.label<<'"'<<std::endl
<<"manufacturerID: \""<<info.manufacturerID<<'"'<<std::endl <<"manufacturerID: \""<<info.manufacturerID<<'"'<<std::endl
<<"model: \""<<info.model<<'"'<<std::endl <<"model: \""<<info.model<<'"'<<std::endl
@ -48,6 +48,17 @@ int main(int argc, char const*const*const argv) try {
<<"firmwareVersion: \""<<(int)info.firmwareVersion.major <<"firmwareVersion: \""<<(int)info.firmwareVersion.major
<<'.'<<(int)info.firmwareVersion.minor<<'"'<<std::endl <<'.'<<(int)info.firmwareVersion.minor<<'"'<<std::endl
<<"utcTime: \""<<info.utcTime<<'"'<<std::endl; <<"utcTime: \""<<info.utcTime<<'"'<<std::endl;
cryptoki::MechanismList mechs(it->mechanismlist());
for (cryptoki::MechanismList::iterator it2(mechs.begin());
it2!=mechs.end(); ++it2) {
cryptoki::MechanismInfo mechinfo(it->mechanisminfo(*it2));
std::cout<<"-------------------- Mechanism -----------------"<<std::endl
<<"id: \""<<mechinfo.id<<'"'<<std::endl
<<"name: \""<<mechinfo.name<<'"'<<std::endl
<<"minKeySize: \""<<mechinfo.minKeySize<<'"'<<std::endl
<<"maxKeySize: \""<<mechinfo.maxKeySize<<'"'<<std::endl
<<"flags: \""<<mechinfo.flags<<'"'<<std::endl;
}
} catch (std::exception& x) { } catch (std::exception& x) {
std::cerr<<"**** FEHLER in "<<*argv<<": "<<x.what()<<std::endl; std::cerr<<"**** FEHLER in "<<*argv<<": "<<x.what()<<std::endl;
} }

@ -7,11 +7,15 @@
// 1 2 3 4 5 6 7 8 // 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890 // 45678901234567890123456789012345678901234567890123456789012345678901234567890
// interface
#include <opencryptoki/apiclient.h> #include <opencryptoki/apiclient.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <set> #include <set>
// for inline implementations only
#include <sstream>
//! C++ Wrapper around Cryptoki API //! C++ Wrapper around Cryptoki API
namespace cryptoki { namespace cryptoki {
@ -57,204 +61,28 @@ namespace cryptoki {
class Slot; class Slot;
typedef std::vector<Slot> SlotList; typedef std::vector<Slot> SlotList;
enum Mechanism { typedef std::set<CK_MECHANISM_TYPE> MechanismList;
RSA_PKCS_KEY_PAIR_GEN = CKM_RSA_PKCS_KEY_PAIR_GEN,
RSA_PKCS = CKM_RSA_PKCS, //! Map Attribute Class to type
RSA_9796 = CKM_RSA_9796, /*! @todo to be completed ... */
RSA_X_509 = CKM_RSA_X_509, template<CK_ATTRIBUTE_TYPE Attribute> class AttributeType {};
MD2_RSA_PKCS = CKM_MD2_RSA_PKCS, template<> class AttributeType<CKA_CLASS> {
MD5_RSA_PKCS = CKM_MD5_RSA_PKCS, public: typedef CK_OBJECT_CLASS Type;
SHA1_RSA_PKCS = CKM_SHA1_RSA_PKCS, };
RIPEMD128_RSA_PKCS = CKM_RIPEMD128_RSA_PKCS, /*
RIPEMD160_RSA_PKCS = CKM_RIPEMD160_RSA_PKCS, template<> class AttributeType<> {
RSA_PKCS_OAEP = CKM_RSA_PKCS_OAEP, public: typedef Type;
RSA_X9_31_KEY_PAIR_GEN = CKM_RSA_X9_31_KEY_PAIR_GEN, };
RSA_X9_31 = CKM_RSA_X9_31, template<> class AttributeType<> {
SHA1_RSA_X9_31 = CKM_SHA1_RSA_X9_31, public: typedef Type;
RSA_PKCS_PSS = CKM_RSA_PKCS_PSS, };
SHA1_RSA_PKCS_PSS = CKM_SHA1_RSA_PKCS_PSS, template<> class AttributeType<> {
DSA_KEY_PAIR_GEN = CKM_DSA_KEY_PAIR_GEN, public: typedef Type;
DSA = CKM_DSA,
DSA_SHA1 = CKM_DSA_SHA1,
DH_PKCS_KEY_PAIR_GEN = CKM_DH_PKCS_KEY_PAIR_GEN,
DH_PKCS_DERIVE = CKM_DH_PKCS_DERIVE,
X9_42_DH_KEY_PAIR_GEN = CKM_X9_42_DH_KEY_PAIR_GEN,
X9_42_DH_DERIVE = CKM_X9_42_DH_DERIVE,
X9_42_DH_HYBRID_DERIVE = CKM_X9_42_DH_HYBRID_DERIVE,
X9_42_MQV_DERIVE = CKM_X9_42_MQV_DERIVE,
SHA256_RSA_PKCS = CKM_SHA256_RSA_PKCS,
RC2_KEY_GEN = CKM_RC2_KEY_GEN,
RC2_ECB = CKM_RC2_ECB,
RC2_CBC = CKM_RC2_CBC,
RC2_MAC = CKM_RC2_MAC,
RC2_MAC_GENERAL = CKM_RC2_MAC_GENERAL,
RC2_CBC_PAD = CKM_RC2_CBC_PAD,
RC4_KEY_GEN = CKM_RC4_KEY_GEN,
RC4 = CKM_RC4,
DES_KEY_GEN = CKM_DES_KEY_GEN,
DES_ECB = CKM_DES_ECB,
DES_CBC = CKM_DES_CBC,
DES_MAC = CKM_DES_MAC,
DES_MAC_GENERAL = CKM_DES_MAC_GENERAL,
DES_CBC_PAD = CKM_DES_CBC_PAD,
DES2_KEY_GEN = CKM_DES2_KEY_GEN,
DES3_KEY_GEN = CKM_DES3_KEY_GEN,
DES3_ECB = CKM_DES3_ECB,
DES3_CBC = CKM_DES3_CBC,
DES3_MAC = CKM_DES3_MAC,
DES3_MAC_GENERAL = CKM_DES3_MAC_GENERAL,
DES3_CBC_PAD = CKM_DES3_CBC_PAD,
CDMF_KEY_GEN = CKM_CDMF_KEY_GEN,
CDMF_ECB = CKM_CDMF_ECB,
CDMF_CBC = CKM_CDMF_CBC,
CDMF_MAC = CKM_CDMF_MAC,
CDMF_MAC_GENERAL = CKM_CDMF_MAC_GENERAL,
CDMF_CBC_PAD = CKM_CDMF_CBC_PAD,
MD2 = CKM_MD2,
MD2_HMAC = CKM_MD2_HMAC,
MD2_HMAC_GENERAL = CKM_MD2_HMAC_GENERAL,
MD5 = CKM_MD5,
MD5_HMAC = CKM_MD5_HMAC,
MD5_HMAC_GENERAL = CKM_MD5_HMAC_GENERAL,
SHA_1 = CKM_SHA_1,
SHA_1_HMAC = CKM_SHA_1_HMAC,
SHA_1_HMAC_GENERAL = CKM_SHA_1_HMAC_GENERAL,
RIPEMD128 = CKM_RIPEMD128,
RIPEMD128_HMAC = CKM_RIPEMD128_HMAC,
RIPEMD128_HMAC_GENERAL = CKM_RIPEMD128_HMAC_GENERAL,
RIPEMD160 = CKM_RIPEMD160,
RIPEMD160_HMAC = CKM_RIPEMD160_HMAC,
RIPEMD160_HMAC_GENERAL = CKM_RIPEMD160_HMAC_GENERAL,
SHA256 = CKM_SHA256,
SHA256_HMAC = CKM_SHA256_HMAC,
SHA256_HMAC_GENERAL = CKM_SHA256_HMAC_GENERAL,
SHA384 = CKM_SHA384,
SHA384_HMAC = CKM_SHA384_HMAC,
SHA384_HMAC_GENERAL = CKM_SHA384_HMAC_GENERAL,
SHA512 = CKM_SHA512,
SHA512_HMAC = CKM_SHA512_HMAC,
SHA512_HMAC_GENERAL = CKM_SHA512_HMAC_GENERAL,
CAST_KEY_GEN = CKM_CAST_KEY_GEN,
CAST_ECB = CKM_CAST_ECB,
CAST_CBC = CKM_CAST_CBC,
CAST_MAC = CKM_CAST_MAC,
CAST_MAC_GENERAL = CKM_CAST_MAC_GENERAL,
CAST_CBC_PAD = CKM_CAST_CBC_PAD,
CAST3_KEY_GEN = CKM_CAST3_KEY_GEN,
CAST3_ECB = CKM_CAST3_ECB,
CAST3_CBC = CKM_CAST3_CBC,
CAST3_MAC = CKM_CAST3_MAC,
CAST3_MAC_GENERAL = CKM_CAST3_MAC_GENERAL,
CAST3_CBC_PAD = CKM_CAST3_CBC_PAD,
CAST5_KEY_GEN = CKM_CAST5_KEY_GEN,
CAST128_KEY_GEN = CKM_CAST128_KEY_GEN,
CAST5_ECB = CKM_CAST5_ECB,
CAST128_ECB = CKM_CAST128_ECB,
CAST5_CBC = CKM_CAST5_CBC,
CAST128_CBC = CKM_CAST128_CBC,
CAST5_MAC = CKM_CAST5_MAC,
CAST128_MAC = CKM_CAST128_MAC,
CAST5_MAC_GENERAL = CKM_CAST5_MAC_GENERAL,
CAST128_MAC_GENERAL = CKM_CAST128_MAC_GENERAL,
CAST5_CBC_PAD = CKM_CAST5_CBC_PAD,
CAST128_CBC_PAD = CKM_CAST128_CBC_PAD,
RC5_KEY_GEN = CKM_RC5_KEY_GEN,
RC5_ECB = CKM_RC5_ECB,
RC5_CBC = CKM_RC5_CBC,
RC5_MAC = CKM_RC5_MAC,
RC5_MAC_GENERAL = CKM_RC5_MAC_GENERAL,
RC5_CBC_PAD = CKM_RC5_CBC_PAD,
IDEA_KEY_GEN = CKM_IDEA_KEY_GEN,
IDEA_ECB = CKM_IDEA_ECB,
IDEA_CBC = CKM_IDEA_CBC,
IDEA_MAC = CKM_IDEA_MAC,
IDEA_MAC_GENERAL = CKM_IDEA_MAC_GENERAL,
IDEA_CBC_PAD = CKM_IDEA_CBC_PAD,
GENERIC_SECRET_KEY_GEN = CKM_GENERIC_SECRET_KEY_GEN,
CONCATENATE_BASE_AND_KEY = CKM_CONCATENATE_BASE_AND_KEY,
CONCATENATE_BASE_AND_DATA = CKM_CONCATENATE_BASE_AND_DATA,
CONCATENATE_DATA_AND_BASE = CKM_CONCATENATE_DATA_AND_BASE,
XOR_BASE_AND_DATA = CKM_XOR_BASE_AND_DATA,
EXTRACT_KEY_FROM_KEY = CKM_EXTRACT_KEY_FROM_KEY,
SSL3_PRE_MASTER_KEY_GEN = CKM_SSL3_PRE_MASTER_KEY_GEN,
SSL3_MASTER_KEY_DERIVE = CKM_SSL3_MASTER_KEY_DERIVE,
SSL3_KEY_AND_MAC_DERIVE = CKM_SSL3_KEY_AND_MAC_DERIVE,
SSL3_MASTER_KEY_DERIVE_DH = CKM_SSL3_MASTER_KEY_DERIVE_DH,
TLS_PRE_MASTER_KEY_GEN = CKM_TLS_PRE_MASTER_KEY_GEN,
TLS_MASTER_KEY_DERIVE = CKM_TLS_MASTER_KEY_DERIVE,
TLS_KEY_AND_MAC_DERIVE = CKM_TLS_KEY_AND_MAC_DERIVE,
TLS_MASTER_KEY_DERIVE_DH = CKM_TLS_MASTER_KEY_DERIVE_DH,
SSL3_MD5_MAC = CKM_SSL3_MD5_MAC,
SSL3_SHA1_MAC = CKM_SSL3_SHA1_MAC,
MD5_KEY_DERIVATION = CKM_MD5_KEY_DERIVATION,
MD2_KEY_DERIVATION = CKM_MD2_KEY_DERIVATION,
SHA1_KEY_DERIVATION = CKM_SHA1_KEY_DERIVATION,
SHA256_KEY_DERIVATION = CKM_SHA256_KEY_DERIVATION,
PBE_MD2_DES_CBC = CKM_PBE_MD2_DES_CBC,
PBE_MD5_DES_CBC = CKM_PBE_MD5_DES_CBC,
PBE_MD5_CAST_CBC = CKM_PBE_MD5_CAST_CBC,
PBE_MD5_CAST3_CBC = CKM_PBE_MD5_CAST3_CBC,
PBE_MD5_CAST5_CBC = CKM_PBE_MD5_CAST5_CBC,
PBE_MD5_CAST128_CBC = CKM_PBE_MD5_CAST128_CBC,
PBE_SHA1_CAST5_CBC = CKM_PBE_SHA1_CAST5_CBC,
PBE_SHA1_CAST128_CBC = CKM_PBE_SHA1_CAST128_CBC,
PBE_SHA1_RC4_128 = CKM_PBE_SHA1_RC4_128,
PBE_SHA1_RC4_40 = CKM_PBE_SHA1_RC4_40,
PBE_SHA1_DES3_EDE_CBC = CKM_PBE_SHA1_DES3_EDE_CBC,
PBE_SHA1_DES2_EDE_CBC = CKM_PBE_SHA1_DES2_EDE_CBC,
PBE_SHA1_RC2_128_CBC = CKM_PBE_SHA1_RC2_128_CBC,
PBE_SHA1_RC2_40_CBC = CKM_PBE_SHA1_RC2_40_CBC,
PKCS5_PBKD2 = CKM_PKCS5_PBKD2,
PBA_SHA1_WITH_SHA1_HMAC = CKM_PBA_SHA1_WITH_SHA1_HMAC,
KEY_WRAP_LYNKS = CKM_KEY_WRAP_LYNKS,
KEY_WRAP_SET_OAEP = CKM_KEY_WRAP_SET_OAEP,
SKIPJACK_KEY_GEN = CKM_SKIPJACK_KEY_GEN,
SKIPJACK_ECB64 = CKM_SKIPJACK_ECB64,
SKIPJACK_CBC64 = CKM_SKIPJACK_CBC64,
SKIPJACK_OFB64 = CKM_SKIPJACK_OFB64,
SKIPJACK_CFB64 = CKM_SKIPJACK_CFB64,
SKIPJACK_CFB32 = CKM_SKIPJACK_CFB32,
SKIPJACK_CFB16 = CKM_SKIPJACK_CFB16,
SKIPJACK_CFB8 = CKM_SKIPJACK_CFB8,
SKIPJACK_WRAP = CKM_SKIPJACK_WRAP,
SKIPJACK_PRIVATE_WRAP = CKM_SKIPJACK_PRIVATE_WRAP,
SKIPJACK_RELAYX = CKM_SKIPJACK_RELAYX,
KEA_KEY_PAIR_GEN = CKM_KEA_KEY_PAIR_GEN,
KEA_KEY_DERIVE = CKM_KEA_KEY_DERIVE,
FORTEZZA_TIMESTAMP = CKM_FORTEZZA_TIMESTAMP,
BATON_KEY_GEN = CKM_BATON_KEY_GEN,
BATON_ECB128 = CKM_BATON_ECB128,
BATON_ECB96 = CKM_BATON_ECB96,
BATON_CBC128 = CKM_BATON_CBC128,
BATON_COUNTER = CKM_BATON_COUNTER,
BATON_SHUFFLE = CKM_BATON_SHUFFLE,
BATON_WRAP = CKM_BATON_WRAP,
ECDSA_KEY_PAIR_GEN = CKM_ECDSA_KEY_PAIR_GEN,
EC_KEY_PAIR_GEN = CKM_EC_KEY_PAIR_GEN,
ECDSA = CKM_ECDSA,
ECDSA_SHA1 = CKM_ECDSA_SHA1,
ECDH1_DERIVE = CKM_ECDH1_DERIVE,
ECDH1_COFACTOR_DERIVE = CKM_ECDH1_COFACTOR_DERIVE,
ECMQV_DERIVE = CKM_ECMQV_DERIVE,
JUNIPER_KEY_GEN = CKM_JUNIPER_KEY_GEN,
JUNIPER_ECB128 = CKM_JUNIPER_ECB128,
JUNIPER_CBC128 = CKM_JUNIPER_CBC128,
JUNIPER_COUNTER = CKM_JUNIPER_COUNTER,
JUNIPER_SHUFFLE = CKM_JUNIPER_SHUFFLE,
JUNIPER_WRAP = CKM_JUNIPER_WRAP,
FASTHASH = CKM_FASTHASH,
AES_KEY_GEN = CKM_AES_KEY_GEN,
AES_ECB = CKM_AES_ECB,
AES_CBC = CKM_AES_CBC,
AES_MAC = CKM_AES_MAC,
AES_MAC_GENERAL = CKM_AES_MAC_GENERAL,
AES_CBC_PAD = CKM_AES_CBC_PAD,
DSA_PARAMETER_GEN = CKM_DSA_PARAMETER_GEN,
DH_PKCS_PARAMETER_GEN = CKM_DH_PKCS_PARAMETER_GEN,
X9_42_DH_PARAMETER_GEN = CKM_X9_42_DH_PARAMETER_GEN,
VENDOR_DEFINED = CKM_VENDOR_DEFINED
}; };
typedef std::set<Mechanism> MechanismList; template<> class AttributeType<> {
public: typedef Type;
};*/
template<std::string::size_type SIZE> template<std::string::size_type SIZE>
class FixString: public std::string { class FixString: public std::string {
@ -286,6 +114,9 @@ namespace cryptoki {
if (pos!=npos) resize(pos+1); else resize(0); if (pos!=npos) resize(pos+1); else resize(0);
return *this; return *this;
} }
operator unsigned char*() {
return (unsigned char*)begin().operator->();
}
FixString fix() { FixString fix() {
FixString cpy(*this); FixString cpy(*this);
cpy.resize(SIZE, ' '); cpy.resize(SIZE, ' ');
@ -293,7 +124,225 @@ namespace cryptoki {
} }
}; };
typedef CK_MECHANISM_INFO MechanismInfo; struct MechanismInfo {
CK_MECHANISM_TYPE id;
std::string name;
CK_ULONG minKeySize;
CK_ULONG maxKeySize;
CK_FLAGS flags;
MechanismInfo(CK_MECHANISM_TYPE type): id(type) {
switch (id) {
case CKM_RSA_PKCS_KEY_PAIR_GEN: name="CKM_RSA_PKCS_KEY_PAIR_GEN"; break;
case CKM_RSA_PKCS: name="CKM_RSA_PKCS"; break;
case CKM_RSA_9796: name="CKM_RSA_9796"; break;
case CKM_RSA_X_509: name="CKM_RSA_X_509"; break;
case CKM_MD2_RSA_PKCS: name="CKM_MD2_RSA_PKCS"; break;
case CKM_MD5_RSA_PKCS: name="CKM_MD5_RSA_PKCS"; break;
case CKM_SHA1_RSA_PKCS: name="CKM_SHA1_RSA_PKCS"; break;
case CKM_RIPEMD128_RSA_PKCS: name="CKM_RIPEMD128_RSA_PKCS"; break;
case CKM_RIPEMD160_RSA_PKCS: name="CKM_RIPEMD160_RSA_PKCS"; break;
case CKM_RSA_PKCS_OAEP: name="CKM_RSA_PKCS_OAEP"; break;
case CKM_RSA_X9_31_KEY_PAIR_GEN: name="CKM_RSA_X9_31_KEY_PAIR_GEN"; break;
case CKM_RSA_X9_31: name="CKM_RSA_X9_31"; break;
case CKM_SHA1_RSA_X9_31: name="CKM_SHA1_RSA_X9_31"; break;
case CKM_RSA_PKCS_PSS: name="CKM_RSA_PKCS_PSS"; break;
case CKM_SHA1_RSA_PKCS_PSS: name="CKM_SHA1_RSA_PKCS_PSS"; break;
case CKM_DSA_KEY_PAIR_GEN: name="CKM_DSA_KEY_PAIR_GEN"; break;
case CKM_DSA: name="CKM_DSA"; break;
case CKM_DSA_SHA1: name="CKM_DSA_SHA1"; break;
case CKM_DH_PKCS_KEY_PAIR_GEN: name="CKM_DH_PKCS_KEY_PAIR_GEN"; break;
case CKM_DH_PKCS_DERIVE: name="CKM_DH_PKCS_DERIVE"; break;
case CKM_X9_42_DH_KEY_PAIR_GEN: name="CKM_X9_42_DH_KEY_PAIR_GEN"; break;
case CKM_X9_42_DH_DERIVE: name="CKM_X9_42_DH_DERIVE"; break;
case CKM_X9_42_DH_HYBRID_DERIVE: name="CKM_X9_42_DH_HYBRID_DERIVE"; break;
case CKM_X9_42_MQV_DERIVE: name="CKM_X9_42_MQV_DERIVE"; break;
case CKM_SHA256_RSA_PKCS: name="CKM_SHA256_RSA_PKCS"; break;
case CKM_RC2_KEY_GEN: name="CKM_RC2_KEY_GEN"; break;
case CKM_RC2_ECB: name="CKM_RC2_ECB"; break;
case CKM_RC2_CBC: name="CKM_RC2_CBC"; break;
case CKM_RC2_MAC: name="CKM_RC2_MAC"; break;
case CKM_RC2_MAC_GENERAL: name="CKM_RC2_MAC_GENERAL"; break;
case CKM_RC2_CBC_PAD: name="CKM_RC2_CBC_PAD"; break;
case CKM_RC4_KEY_GEN: name="CKM_RC4_KEY_GEN"; break;
case CKM_RC4: name="CKM_RC4"; break;
case CKM_DES_KEY_GEN: name="CKM_DES_KEY_GEN"; break;
case CKM_DES_ECB: name="CKM_DES_ECB"; break;
case CKM_DES_CBC: name="CKM_DES_CBC"; break;
case CKM_DES_MAC: name="CKM_DES_MAC"; break;
case CKM_DES_MAC_GENERAL: name="CKM_DES_MAC_GENERAL"; break;
case CKM_DES_CBC_PAD: name="CKM_DES_CBC_PAD"; break;
case CKM_DES2_KEY_GEN: name="CKM_DES2_KEY_GEN"; break;
case CKM_DES3_KEY_GEN: name="CKM_DES3_KEY_GEN"; break;
case CKM_DES3_ECB: name="CKM_DES3_ECB"; break;
case CKM_DES3_CBC: name="CKM_DES3_CBC"; break;
case CKM_DES3_MAC: name="CKM_DES3_MAC"; break;
case CKM_DES3_MAC_GENERAL: name="CKM_DES3_MAC_GENERAL"; break;
case CKM_DES3_CBC_PAD: name="CKM_DES3_CBC_PAD"; break;
case CKM_CDMF_KEY_GEN: name="CKM_CDMF_KEY_GEN"; break;
case CKM_CDMF_ECB: name="CKM_CDMF_ECB"; break;
case CKM_CDMF_CBC: name="CKM_CDMF_CBC"; break;
case CKM_CDMF_MAC: name="CKM_CDMF_MAC"; break;
case CKM_CDMF_MAC_GENERAL: name="CKM_CDMF_MAC_GENERAL"; break;
case CKM_CDMF_CBC_PAD: name="CKM_CDMF_CBC_PAD"; break;
case CKM_MD2: name="CKM_MD2"; break;
case CKM_MD2_HMAC: name="CKM_MD2_HMAC"; break;
case CKM_MD2_HMAC_GENERAL: name="CKM_MD2_HMAC_GENERAL"; break;
case CKM_MD5: name="CKM_MD5"; break;
case CKM_MD5_HMAC: name="CKM_MD5_HMAC"; break;
case CKM_MD5_HMAC_GENERAL: name="CKM_MD5_HMAC_GENERAL"; break;
case CKM_SHA_1: name="CKM_SHA_1"; break;
case CKM_SHA_1_HMAC: name="CKM_SHA_1_HMAC"; break;
case CKM_SHA_1_HMAC_GENERAL: name="CKM_SHA_1_HMAC_GENERAL"; break;
case CKM_RIPEMD128: name="CKM_RIPEMD128"; break;
case CKM_RIPEMD128_HMAC: name="CKM_RIPEMD128_HMAC"; break;
case CKM_RIPEMD128_HMAC_GENERAL: name="CKM_RIPEMD128_HMAC_GENERAL"; break;
case CKM_RIPEMD160: name="CKM_RIPEMD160"; break;
case CKM_RIPEMD160_HMAC: name="CKM_RIPEMD160_HMAC"; break;
case CKM_RIPEMD160_HMAC_GENERAL: name="CKM_RIPEMD160_HMAC_GENERAL"; break;
case CKM_SHA256: name="CKM_SHA256"; break;
case CKM_SHA256_HMAC: name="CKM_SHA256_HMAC"; break;
case CKM_SHA256_HMAC_GENERAL: name="CKM_SHA256_HMAC_GENERAL"; break;
case CKM_SHA384: name="CKM_SHA384"; break;
case CKM_SHA384_HMAC: name="CKM_SHA384_HMAC"; break;
case CKM_SHA384_HMAC_GENERAL: name="CKM_SHA384_HMAC_GENERAL"; break;
case CKM_SHA512: name="CKM_SHA512"; break;
case CKM_SHA512_HMAC: name="CKM_SHA512_HMAC"; break;
case CKM_SHA512_HMAC_GENERAL: name="CKM_SHA512_HMAC_GENERAL"; break;
case CKM_CAST_KEY_GEN: name="CKM_CAST_KEY_GEN"; break;
case CKM_CAST_ECB: name="CKM_CAST_ECB"; break;
case CKM_CAST_CBC: name="CKM_CAST_CBC"; break;
case CKM_CAST_MAC: name="CKM_CAST_MAC"; break;
case CKM_CAST_MAC_GENERAL: name="CKM_CAST_MAC_GENERAL"; break;
case CKM_CAST_CBC_PAD: name="CKM_CAST_CBC_PAD"; break;
case CKM_CAST3_KEY_GEN: name="CKM_CAST3_KEY_GEN"; break;
case CKM_CAST3_ECB: name="CKM_CAST3_ECB"; break;
case CKM_CAST3_CBC: name="CKM_CAST3_CBC"; break;
case CKM_CAST3_MAC: name="CKM_CAST3_MAC"; break;
case CKM_CAST3_MAC_GENERAL: name="CKM_CAST3_MAC_GENERAL"; break;
case CKM_CAST3_CBC_PAD: name="CKM_CAST3_CBC_PAD"; break;
//case CKM_CAST5_KEY_GEN: name="CKM_CAST5_KEY_GEN"; break;
case CKM_CAST128_KEY_GEN: name="CKM_CAST5_KEY_GEN or CKM_CAST128_KEY_GEN"; break;
//case CKM_CAST5_ECB: name="CKM_CAST5_ECB"; break;
case CKM_CAST128_ECB: name="CKM_CAST5_ECB or CKM_CAST128_ECB"; break;
//case CKM_CAST5_CBC: name="CKM_CAST5_CBC"; break;
case CKM_CAST128_CBC: name="CKM_CAST5_CBC or CKM_CAST128_CBC"; break;
//case CKM_CAST5_MAC: name="CKM_CAST5_MAC"; break;
case CKM_CAST128_MAC: name="CKM_CAST5_MAC or CKM_CAST128_MAC"; break;
//case CKM_CAST5_MAC_GENERAL: name="CKM_CAST5_MAC_GENERAL"; break;
case CKM_CAST128_MAC_GENERAL:
name="CKM_CAST5_MAC_GENERAL or CKM_CAST128_MAC_GENERAL"; break;
//case CKM_CAST5_CBC_PAD: name="CKM_CAST5_CBC_PAD"; break;
case CKM_CAST128_CBC_PAD: name="CKM_CAST5_CBC_PAD or CKM_CAST128_CBC_PAD"; break;
case CKM_RC5_KEY_GEN: name="CKM_RC5_KEY_GEN"; break;
case CKM_RC5_ECB: name="CKM_RC5_ECB"; break;
case CKM_RC5_CBC: name="CKM_RC5_CBC"; break;
case CKM_RC5_MAC: name="CKM_RC5_MAC"; break;
case CKM_RC5_MAC_GENERAL: name="CKM_RC5_MAC_GENERAL"; break;
case CKM_RC5_CBC_PAD: name="CKM_RC5_CBC_PAD"; break;
case CKM_IDEA_KEY_GEN: name="CKM_IDEA_KEY_GEN"; break;
case CKM_IDEA_ECB: name="CKM_IDEA_ECB"; break;
case CKM_IDEA_CBC: name="CKM_IDEA_CBC"; break;
case CKM_IDEA_MAC: name="CKM_IDEA_MAC"; break;
case CKM_IDEA_MAC_GENERAL: name="CKM_IDEA_MAC_GENERAL"; break;
case CKM_IDEA_CBC_PAD: name="CKM_IDEA_CBC_PAD"; break;
case CKM_GENERIC_SECRET_KEY_GEN: name="CKM_GENERIC_SECRET_KEY_GEN"; break;
case CKM_CONCATENATE_BASE_AND_KEY:
name="CKM_CONCATENATE_BASE_AND_KEY"; break;
case CKM_CONCATENATE_BASE_AND_DATA:
name="CKM_CONCATENATE_BASE_AND_DATA"; break;
case CKM_CONCATENATE_DATA_AND_BASE:
name="CKM_CONCATENATE_DATA_AND_BASE"; break;
case CKM_XOR_BASE_AND_DATA: name="CKM_XOR_BASE_AND_DATA"; break;
case CKM_EXTRACT_KEY_FROM_KEY: name="CKM_EXTRACT_KEY_FROM_KEY"; break;
case CKM_SSL3_PRE_MASTER_KEY_GEN: name="CKM_SSL3_PRE_MASTER_KEY_GEN"; break;
case CKM_SSL3_MASTER_KEY_DERIVE: name="CKM_SSL3_MASTER_KEY_DERIVE"; break;
case CKM_SSL3_KEY_AND_MAC_DERIVE: name="CKM_SSL3_KEY_AND_MAC_DERIVE"; break;
case CKM_SSL3_MASTER_KEY_DERIVE_DH:
name="CKM_SSL3_MASTER_KEY_DERIVE_DH"; break;
case CKM_TLS_PRE_MASTER_KEY_GEN: name="CKM_TLS_PRE_MASTER_KEY_GEN"; break;
case CKM_TLS_MASTER_KEY_DERIVE: name="CKM_TLS_MASTER_KEY_DERIVE"; break;
case CKM_TLS_KEY_AND_MAC_DERIVE: name="CKM_TLS_KEY_AND_MAC_DERIVE"; break;
case CKM_TLS_MASTER_KEY_DERIVE_DH: name="CKM_TLS_MASTER_KEY_DERIVE_DH"; break;
case CKM_SSL3_MD5_MAC: name="CKM_SSL3_MD5_MAC"; break;
case CKM_SSL3_SHA1_MAC: name="CKM_SSL3_SHA1_MAC"; break;
case CKM_MD5_KEY_DERIVATION: name="CKM_MD5_KEY_DERIVATION"; break;
case CKM_MD2_KEY_DERIVATION: name="CKM_MD2_KEY_DERIVATION"; break;
case CKM_SHA1_KEY_DERIVATION: name="CKM_SHA1_KEY_DERIVATION"; break;
case CKM_SHA256_KEY_DERIVATION: name="CKM_SHA256_KEY_DERIVATION"; break;
case CKM_PBE_MD2_DES_CBC: name="CKM_PBE_MD2_DES_CBC"; break;
case CKM_PBE_MD5_DES_CBC: name="CKM_PBE_MD5_DES_CBC"; break;
case CKM_PBE_MD5_CAST_CBC: name="CKM_PBE_MD5_CAST_CBC"; break;
case CKM_PBE_MD5_CAST3_CBC: name="CKM_PBE_MD5_CAST3_CBC"; break;
//case CKM_PBE_MD5_CAST5_CBC: name="CKM_PBE_MD5_CAST5_CBC"; break;
case CKM_PBE_MD5_CAST128_CBC:
name="CKM_PBE_MD5_CAST5_CBC or CKM_PBE_MD5_CAST128_CBC"; break;
//case CKM_PBE_SHA1_CAST5_CBC: name="CKM_PBE_SHA1_CAST5_CBC"; break;
case CKM_PBE_SHA1_CAST128_CBC:
name="CKM_PBE_SHA1_CAST5_CBC or CKM_PBE_SHA1_CAST128_CBC"; break;
case CKM_PBE_SHA1_RC4_128: name="CKM_PBE_SHA1_RC4_128"; break;
case CKM_PBE_SHA1_RC4_40: name="CKM_PBE_SHA1_RC4_40"; break;
case CKM_PBE_SHA1_DES3_EDE_CBC: name="CKM_PBE_SHA1_DES3_EDE_CBC"; break;
case CKM_PBE_SHA1_DES2_EDE_CBC: name="CKM_PBE_SHA1_DES2_EDE_CBC"; break;
case CKM_PBE_SHA1_RC2_128_CBC: name="CKM_PBE_SHA1_RC2_128_CBC"; break;
case CKM_PBE_SHA1_RC2_40_CBC: name="CKM_PBE_SHA1_RC2_40_CBC"; break;
case CKM_PKCS5_PBKD2: name="CKM_PKCS5_PBKD2"; break;
case CKM_PBA_SHA1_WITH_SHA1_HMAC: name="CKM_PBA_SHA1_WITH_SHA1_HMAC"; break;
case CKM_KEY_WRAP_LYNKS: name="CKM_KEY_WRAP_LYNKS"; break;
case CKM_KEY_WRAP_SET_OAEP: name="CKM_KEY_WRAP_SET_OAEP"; break;
case CKM_SKIPJACK_KEY_GEN: name="CKM_SKIPJACK_KEY_GEN"; break;
case CKM_SKIPJACK_ECB64: name="CKM_SKIPJACK_ECB64"; break;
case CKM_SKIPJACK_CBC64: name="CKM_SKIPJACK_CBC64"; break;
case CKM_SKIPJACK_OFB64: name="CKM_SKIPJACK_OFB64"; break;
case CKM_SKIPJACK_CFB64: name="CKM_SKIPJACK_CFB64"; break;
case CKM_SKIPJACK_CFB32: name="CKM_SKIPJACK_CFB32"; break;
case CKM_SKIPJACK_CFB16: name="CKM_SKIPJACK_CFB16"; break;
case CKM_SKIPJACK_CFB8: name="CKM_SKIPJACK_CFB8"; break;
case CKM_SKIPJACK_WRAP: name="CKM_SKIPJACK_WRAP"; break;
case CKM_SKIPJACK_PRIVATE_WRAP: name="CKM_SKIPJACK_PRIVATE_WRAP"; break;
case CKM_SKIPJACK_RELAYX: name="CKM_SKIPJACK_RELAYX"; break;
case CKM_KEA_KEY_PAIR_GEN: name="CKM_KEA_KEY_PAIR_GEN"; break;
case CKM_KEA_KEY_DERIVE: name="CKM_KEA_KEY_DERIVE"; break;
case CKM_FORTEZZA_TIMESTAMP: name="CKM_FORTEZZA_TIMESTAMP"; break;
case CKM_BATON_KEY_GEN: name="CKM_BATON_KEY_GEN"; break;
case CKM_BATON_ECB128: name="CKM_BATON_ECB128"; break;
case CKM_BATON_ECB96: name="CKM_BATON_ECB96"; break;
case CKM_BATON_CBC128: name="CKM_BATON_CBC128"; break;
case CKM_BATON_COUNTER: name="CKM_BATON_COUNTER"; break;
case CKM_BATON_SHUFFLE: name="CKM_BATON_SHUFFLE"; break;
case CKM_BATON_WRAP: name="CKM_BATON_WRAP"; break;
//case CKM_ECDSA_KEY_PAIR_GEN: name="CKM_ECDSA_KEY_PAIR_GEN"; break;
case CKM_EC_KEY_PAIR_GEN:
name="CKM_ECDSA_KEY_PAIR_GEN or CKM_EC_KEY_PAIR_GEN"; break;
case CKM_ECDSA: name="CKM_ECDSA"; break;
case CKM_ECDSA_SHA1: name="CKM_ECDSA_SHA1"; break;
case CKM_ECDH1_DERIVE: name="CKM_ECDH1_DERIVE"; break;
case CKM_ECDH1_COFACTOR_DERIVE: name="CKM_ECDH1_COFACTOR_DERIVE"; break;
case CKM_ECMQV_DERIVE: name="CKM_ECMQV_DERIVE"; break;
case CKM_JUNIPER_KEY_GEN: name="CKM_JUNIPER_KEY_GEN"; break;
case CKM_JUNIPER_ECB128: name="CKM_JUNIPER_ECB128"; break;
case CKM_JUNIPER_CBC128: name="CKM_JUNIPER_CBC128"; break;
case CKM_JUNIPER_COUNTER: name="CKM_JUNIPER_COUNTER"; break;
case CKM_JUNIPER_SHUFFLE: name="CKM_JUNIPER_SHUFFLE"; break;
case CKM_JUNIPER_WRAP: name="CKM_JUNIPER_WRAP"; break;
case CKM_FASTHASH: name="CKM_FASTHASH"; break;
case CKM_AES_KEY_GEN: name="CKM_AES_KEY_GEN"; break;
case CKM_AES_ECB: name="CKM_AES_ECB"; break;
case CKM_AES_CBC: name="CKM_AES_CBC"; break;
case CKM_AES_MAC: name="CKM_AES_MAC"; break;
case CKM_AES_MAC_GENERAL: name="CKM_AES_MAC_GENERAL"; break;
case CKM_AES_CBC_PAD: name="CKM_AES_CBC_PAD"; break;
case CKM_DSA_PARAMETER_GEN: name="CKM_DSA_PARAMETER_GEN"; break;
case CKM_DH_PKCS_PARAMETER_GEN: name="CKM_DH_PKCS_PARAMETER_GEN"; break;
case CKM_X9_42_DH_PARAMETER_GEN: name="CKM_X9_42_DH_PARAMETER_GEN"; break;
case CKM_VENDOR_DEFINED: name="CKM_VENDOR_DEFINED"; break;
default: {
std::stringstream ss;
ss<<"unknown mechanism: "<<id;
throw exception(ss.str());
}
}
}
};
struct SlotInfo { struct SlotInfo {
FixString<64> slotDescription; FixString<64> slotDescription;
@ -451,11 +500,15 @@ namespace cryptoki {
//@} //@}
MechanismInfo mechanismInfo(Mechanism mechanism) { MechanismInfo mechanisminfo(CK_MECHANISM_TYPE mechanism) {
MechanismInfo info; MechanismInfo info(mechanism);
CK_MECHANISM_INFO cInfo;
//! calls @c C_GetMechanismInfo //! calls @c C_GetMechanismInfo
check(_init->_fn->C_GetMechanismInfo(_slot, mechanism, &info), check(_init->_fn->C_GetMechanismInfo(_slot, mechanism, &cInfo),
CRYPTOKI_FN_LOG("C_GetMechanismInfo")); CRYPTOKI_FN_LOG("C_GetMechanismInfo"));
info.minKeySize = cInfo.ulMinKeySize;
info.maxKeySize = cInfo.ulMaxKeySize;
info.flags = cInfo.flags;
return info; return info;
} }
@ -473,7 +526,8 @@ namespace cryptoki {
delete[] mechanisms; delete[] mechanisms;
return res; return res;
} }
for (CK_ULONG i(0); i<count; ++i) res.insert((Mechanism)mechanisms[i]); for (CK_ULONG i(0); i<count; ++i)
res.insert(mechanisms[i]);
} catch (...) { } catch (...) {
delete[] mechanisms; delete[] mechanisms;
throw; throw;
@ -482,7 +536,7 @@ namespace cryptoki {
return res; return res;
} }
SlotInfo slotInfo() { SlotInfo slotinfo() {
SlotInfo info; SlotInfo info;
CK_SLOT_INFO cInfo; CK_SLOT_INFO cInfo;
//! calls @c C_GetSlotInfo //! calls @c C_GetSlotInfo
@ -496,7 +550,7 @@ namespace cryptoki {
return info; return info;
} }
TokenInfo tokenInfo() { TokenInfo tokeninfo() {
TokenInfo info; TokenInfo info;
//! calls @c C_GetTokenInfo //! calls @c C_GetTokenInfo
CK_TOKEN_INFO cInfo; CK_TOKEN_INFO cInfo;
@ -523,17 +577,17 @@ namespace cryptoki {
return info; return info;
} }
std::string inittoken(std::string in) { /*! @bug does not compile:
std::string res; @code
res.resize(in.size()); bool inittoken(std::string pin, FixString<32> label) {
//! calls @c C_InitToken //! calls @c C_InitToken
check(_init->_fn->C_InitToken return check(_init->_fn->C_InitToken
(_slot, (_slot,
(unsigned char*)in.begin().operator->(), in.size(), (unsigned char*)pin.begin().operator->(), pin.size(),
(unsigned char*)res.begin().operator->()), (unsigned char*)label.fix().begin().operator->())
CRYPTOKI_FN_LOG("C_InitToken")); CRYPTOKI_FN_LOG("C_InitToken"));
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
@ -631,7 +685,7 @@ namespace cryptoki {
std::string decrypt(std::string in) { std::string decrypt(std::string in) {
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 (seems so ...)
//! calls @c C_Decrypt //! calls @c C_Decrypt
check(_slot._init->_fn->C_Decrypt check(_slot._init->_fn->C_Decrypt
(_session, (_session,
@ -656,19 +710,11 @@ namespace cryptoki {
return res; return res;
} }
std::string decryptfinal(std::string in) { bool decryptfinal() {
std::string res; //! calls @c C_DecryptFinal
// res.resize(in.size()); return check(_slot._init->_fn->C_DecryptFinal(_session, 0, 0),
// CK_ULONG size(res.size()); //! @todo check if size is ok CRYPTOKI_FN_LOG("C_DecryptFinal"));
// //! calls @c C_DecryptFinal //! @todo does this work?
// check(_slot._init->_fn->C_DecryptFinal
// (_session,
// (unsigned char*)in.begin().operator->(), in.size(),
// (unsigned char*)res.begin().operator->(), &size),
// CRYPTOKI_FN_LOG("C_DecryptFinal"));
// res.resize(size);
//! @todo check docu
return res;
} }
std::string decryptupdate(std::string in) { std::string decryptupdate(std::string in) {
@ -1010,6 +1056,7 @@ namespace cryptoki {
friend class Session; friend class Session;
CK_OBJECT_HANDLE _object;
Session& _session; Session& _session;
CK_RV _res; CK_RV _res;
@ -1025,7 +1072,9 @@ namespace cryptoki {
Object(); //! forbidden Object(); //! forbidden
Object(Session& session): _session(session), _res(CKR_OK) {} Object(Session& session): _session(session), _res(CKR_OK) {
//! @todo _object = ???
}
public: public:
@ -1049,6 +1098,12 @@ namespace cryptoki {
//@} //@}
/*! @name Low Level Cryptoki Functions
Direct access to the low level cryptoki API. Better use the
comfort methods. */
//@{
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool copyobject() { bool copyobject() {
@ -1069,14 +1124,16 @@ namespace cryptoki {
} }
@endcode */ @endcode */
/*! @todo Not implemented: bool decryptinit(CK_MECHANISM_TYPE type, std::string param,
@code const Object& key) {
bool decryptinit() { CK_MECHANISM mech = {
type, param.begin().operator->(), param.size()
};
//! calls @c C_DecryptInit //! calls @c C_DecryptInit
return check(_session._slot._init->_fn->C_DecryptInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_DecryptInit
(_session, &mech, key._object),
CRYPTOKI_FN_LOG("C_DecryptInit")); CRYPTOKI_FN_LOG("C_DecryptInit"));
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@ -1251,6 +1308,8 @@ namespace cryptoki {
} }
@endcode */ @endcode */
//@}
}; };
#endif #endif

Loading…
Cancel
Save