2009-08-27 14:46:29 +00:00
|
|
|
|
#ifndef CRYPTOKI_HXX
|
|
|
|
|
#define CRYPTOKI_HXX
|
|
|
|
|
/*! @file
|
|
|
|
|
|
|
|
|
|
@id $Id$
|
|
|
|
|
*/
|
|
|
|
|
// 1 2 3 4 5 6 7 8
|
|
|
|
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
|
|
|
2009-08-28 14:57:40 +00:00
|
|
|
|
// interface
|
2009-09-21 07:43:32 +00:00
|
|
|
|
#include <openssl.hxx>
|
2009-10-23 14:57:28 +00:00
|
|
|
|
#ifndef WIN32
|
2014-05-06 15:42:09 +00:00
|
|
|
|
#include <pkcs11.h>
|
2009-10-23 14:57:28 +00:00
|
|
|
|
#else
|
|
|
|
|
#include <cryptoki.h>
|
|
|
|
|
#endif
|
2009-08-27 14:46:29 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2009-08-31 13:59:23 +00:00
|
|
|
|
#include <map>
|
2009-08-27 14:46:29 +00:00
|
|
|
|
#include <set>
|
2014-04-03 11:21:18 +00:00
|
|
|
|
#include <mrw/checkcxx11.hxx>
|
|
|
|
|
#include <memory>
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-08-28 14:57:40 +00:00
|
|
|
|
// for inline implementations only
|
2013-10-15 11:57:29 +00:00
|
|
|
|
#include <cryptaux.hxx>
|
2009-08-28 14:57:40 +00:00
|
|
|
|
#include <sstream>
|
2009-08-31 13:59:23 +00:00
|
|
|
|
#include <cstdlib> // malloc/free
|
2009-09-02 13:57:56 +00:00
|
|
|
|
#include <cstring> // memset
|
2009-09-29 07:24:04 +00:00
|
|
|
|
#include <cassert> // assert
|
2009-09-02 13:57:56 +00:00
|
|
|
|
#include <iomanip>
|
2009-08-28 14:57:40 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/*! @defgroup gcryptoki C++ Wrapper around Cryptoki API
|
|
|
|
|
|
|
|
|
|
Wrapper to abstract the ugly PKCS#11 C-API with nice C++ features,
|
|
|
|
|
such as exception handling, memory management, etc.
|
|
|
|
|
|
|
|
|
|
The cryptoky library loads a dynamic library that is responsible
|
|
|
|
|
for translating the card specific commands. The library is passed
|
|
|
|
|
in the constructor of cryptoki::Library. Then method
|
|
|
|
|
cryptoki::Library::slotList returns all slots found on the
|
|
|
|
|
computer. */
|
2009-09-18 11:41:30 +00:00
|
|
|
|
//@{
|
|
|
|
|
/*! @defgroup cryptokilib Cryptoki C++ Library */
|
|
|
|
|
/*! @defgroup cryptokitypes Cryptoki C++ Types and Auxiliary */
|
|
|
|
|
/*! @defgroup cryptokiexceptions Cryptoki Exceptions */
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/** @example cryptoki-demo.cxx */
|
|
|
|
|
/** @example cryptoki-sign-demo.cxx */
|
|
|
|
|
//@}
|
2009-09-18 11:41:30 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// @addtogroup cryptokitypes
|
|
|
|
|
//@{
|
2009-10-21 08:52:04 +00:00
|
|
|
|
#ifndef CRYPTOKI_FN_LOG
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#if __GNUC__ >= 2
|
|
|
|
|
//! Cryptoki Error Message Formatting
|
|
|
|
|
/*! If you want to change cryptoki error formatting, just
|
2014-04-01 13:10:51 +00:00
|
|
|
|
redefine your own CRYPTOKY_FN_LOG macro before <code>\#include
|
2009-10-21 08:52:04 +00:00
|
|
|
|
<cryptoki.hxx></code>.
|
|
|
|
|
#return std::String */
|
|
|
|
|
#define CRYPTOKI_FN_LOG(X) (std::string(X " failed in ") \
|
|
|
|
|
+std::string(__PRETTY_FUNCTION__))
|
|
|
|
|
#else
|
2013-11-06 12:24:52 +00:00
|
|
|
|
#define CRYPTOKI_QUOTE(X) CRYPTOKI_QUOTE2(X)
|
|
|
|
|
#define CRYPTOKI_QUOTE2(X) #X
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//! Cryptoki Error Message Formatting
|
|
|
|
|
/*! If you want to change cryptoki error formatting, just
|
2014-04-01 13:10:51 +00:00
|
|
|
|
redefine your own CRYPTOKY_FN_LOG macro before <code>\#include
|
2009-10-21 08:52:04 +00:00
|
|
|
|
<cryptoki.hxx></code>.
|
2014-04-01 13:10:51 +00:00
|
|
|
|
@return string */
|
2009-10-21 08:52:04 +00:00
|
|
|
|
#define CRYPTOKI_FN_LOG(X) X " failed in \
|
|
|
|
|
" __FILE__ ":" CRYPTOKI_QUOTE(__LINE__)
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//@}
|
2009-10-21 08:52:04 +00:00
|
|
|
|
|
2014-01-31 13:32:31 +00:00
|
|
|
|
//! @ref gcryptoki @copydoc gcryptoki
|
2009-08-27 14:46:29 +00:00
|
|
|
|
namespace cryptoki {
|
|
|
|
|
|
2009-09-18 11:41:30 +00:00
|
|
|
|
//! @addtogroup cryptokitypes
|
|
|
|
|
//@{
|
2009-09-02 13:57:56 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Map cryptoki number to a string, care about unavailable and infinite
|
|
|
|
|
/** Cryptoky knows illegal values (unavailable information), which
|
|
|
|
|
is mapped to @c - and infinite values which are mapped to @c ∞
|
|
|
|
|
when converted to string. All other numbers just show the number
|
|
|
|
|
as numeric string. */
|
2009-09-09 16:14:01 +00:00
|
|
|
|
inline std::string string(CK_ULONG num) {
|
|
|
|
|
switch (num) {
|
|
|
|
|
case CK_UNAVAILABLE_INFORMATION: return "-";
|
|
|
|
|
case CK_EFFECTIVELY_INFINITE: return "∞";
|
|
|
|
|
default: {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss<<num;
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Convert any kind of array (buffer) to an std::vector.
|
|
|
|
|
template <typename TYPE> std::vector<TYPE> toVector(TYPE in[]) {
|
|
|
|
|
return std::vector<TYPE>(in, in+sizeof(in)/sizeof(in[0]));
|
2009-08-31 13:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-18 11:41:30 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//============================================================================
|
2009-09-18 11:41:30 +00:00
|
|
|
|
/*! @addtogroup cryptokiexceptions */
|
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2009-08-27 14:46:29 +00:00
|
|
|
|
class exception: public std::exception {
|
|
|
|
|
public:
|
|
|
|
|
exception(const std::string& reason) throw():
|
|
|
|
|
_what("cryptoki: "+reason) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("ERROR: "<<what());
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
~exception() throw() {}
|
|
|
|
|
const char* what() const throw() {
|
|
|
|
|
return _what.c_str();
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
std::string _what;
|
|
|
|
|
};
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
class not_implemented: public exception {
|
|
|
|
|
public:
|
|
|
|
|
not_implemented(const std::string& reason) throw():
|
2013-11-06 12:24:52 +00:00
|
|
|
|
exception("feature is not implemented: "+reason) {}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
};
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
class access_error: public exception {
|
|
|
|
|
public:
|
|
|
|
|
access_error(const std::string& reason) throw():
|
2013-11-06 12:24:52 +00:00
|
|
|
|
exception("smardcard access error: "+reason) {}
|
|
|
|
|
};
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
class wrong_pin: public access_error {
|
|
|
|
|
public:
|
|
|
|
|
wrong_pin(const std::string& reason) throw():
|
|
|
|
|
access_error("wrong pin: "+reason) {}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
};
|
2009-09-18 11:41:30 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
/*! @addtogroup cryptokitypes */
|
|
|
|
|
//@{
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
|
|
|
|
class Slot;
|
|
|
|
|
typedef std::vector<Slot> SlotList;
|
2009-09-01 09:11:11 +00:00
|
|
|
|
|
|
|
|
|
class Object;
|
|
|
|
|
typedef std::vector<Object> ObjectList;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-08-31 11:28:33 +00:00
|
|
|
|
typedef std::vector<CK_ATTRIBUTE_TYPE> AttributeTypeList;
|
2009-08-31 13:59:23 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Represents a cryproki attribute and maps to C++ types.
|
2009-09-22 13:25:55 +00:00
|
|
|
|
class Attribute {
|
|
|
|
|
public:
|
2009-09-03 07:46:51 +00:00
|
|
|
|
Attribute(CK_ATTRIBUTE_TYPE t = -1): type(t) {}
|
2009-09-16 14:52:09 +00:00
|
|
|
|
Attribute(CK_ATTRIBUTE_TYPE t, const std::string& v): type(t), value(v) {}
|
2009-08-31 13:59:23 +00:00
|
|
|
|
Attribute(CK_ATTRIBUTE& attr):
|
|
|
|
|
type(attr.type), value((char*)attr.pValue, attr.ulValueLen) {
|
|
|
|
|
free(attr.pValue);
|
|
|
|
|
attr.pValue = 0;
|
|
|
|
|
}
|
2009-09-01 09:11:11 +00:00
|
|
|
|
Attribute& operator=(const std::string& v) {
|
|
|
|
|
value = v;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2009-09-29 07:24:04 +00:00
|
|
|
|
bool operator==(const Attribute& o) const {
|
|
|
|
|
return type==o.type && value==o.value;
|
|
|
|
|
}
|
|
|
|
|
bool operator!=(const Attribute& o) const {
|
|
|
|
|
return type!=o.type || value!=o.value;
|
|
|
|
|
}
|
2009-09-16 14:52:09 +00:00
|
|
|
|
//! Convert to a @c CK_ATTRIBUTE.
|
|
|
|
|
/*! @note @c pValue points to the internal buffer of this
|
|
|
|
|
element and must therefore not be changed. Also this object
|
|
|
|
|
must not be destructed before the returned @c
|
|
|
|
|
CK_ATTRIBUTE. */
|
|
|
|
|
operator CK_ATTRIBUTE() const {
|
|
|
|
|
CK_ATTRIBUTE a;
|
|
|
|
|
a.type = type;
|
2009-11-24 12:10:25 +00:00
|
|
|
|
a.pValue = const_cast<char*>(&value[0]);
|
2009-09-16 14:52:09 +00:00
|
|
|
|
a.ulValueLen = value.size();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Textual name of the attribute.
|
2009-09-29 07:24:04 +00:00
|
|
|
|
std::string name() const {
|
2009-09-02 08:45:49 +00:00
|
|
|
|
switch (type) {
|
2009-09-09 06:59:54 +00:00
|
|
|
|
case CKA_CLASS: return "CLASS";
|
|
|
|
|
case CKA_TOKEN: return "TOKEN";
|
|
|
|
|
case CKA_PRIVATE: return "PRIVATE";
|
|
|
|
|
case CKA_LABEL: return "LABEL";
|
|
|
|
|
case CKA_APPLICATION: return "APPLICATION";
|
|
|
|
|
case CKA_VALUE: return "VALUE";
|
|
|
|
|
case CKA_OBJECT_ID: return "OBJECT_ID";
|
|
|
|
|
case CKA_CERTIFICATE_TYPE: return "CERTIFICATE_TYPE";
|
|
|
|
|
case CKA_ISSUER: return "ISSUER";
|
|
|
|
|
case CKA_SERIAL_NUMBER: return "SERIAL_NUMBER";
|
|
|
|
|
case CKA_AC_ISSUER: return "AC_ISSUER";
|
|
|
|
|
case CKA_OWNER: return "OWNER";
|
|
|
|
|
case CKA_ATTR_TYPES: return "ATTR_TYPES";
|
|
|
|
|
case CKA_TRUSTED: return "TRUSTED";
|
|
|
|
|
case CKA_KEY_TYPE: return "KEY_TYPE";
|
|
|
|
|
case CKA_SUBJECT: return "SUBJECT";
|
|
|
|
|
case CKA_ID: return "ID";
|
|
|
|
|
case CKA_SENSITIVE: return "SENSITIVE";
|
|
|
|
|
case CKA_ENCRYPT: return "ENCRYPT";
|
|
|
|
|
case CKA_DECRYPT: return "DECRYPT";
|
|
|
|
|
case CKA_WRAP: return "WRAP";
|
|
|
|
|
case CKA_UNWRAP: return "UNWRAP";
|
|
|
|
|
case CKA_SIGN: return "SIGN";
|
|
|
|
|
case CKA_SIGN_RECOVER: return "SIGN_RECOVER";
|
|
|
|
|
case CKA_VERIFY: return "VERIFY";
|
|
|
|
|
case CKA_VERIFY_RECOVER: return "VERIFY_RECOVER";
|
|
|
|
|
case CKA_DERIVE: return "DERIVE";
|
|
|
|
|
case CKA_START_DATE: return "START_DATE";
|
|
|
|
|
case CKA_END_DATE: return "END_DATE";
|
|
|
|
|
case CKA_MODULUS: return "MODULUS";
|
|
|
|
|
case CKA_MODULUS_BITS: return "MODULUS_BITS";
|
|
|
|
|
case CKA_PUBLIC_EXPONENT: return "PUBLIC_EXPONENT";
|
|
|
|
|
case CKA_PRIVATE_EXPONENT: return "PRIVATE_EXPONENT";
|
|
|
|
|
case CKA_PRIME_1: return "PRIME_1";
|
|
|
|
|
case CKA_PRIME_2: return "PRIME_2";
|
|
|
|
|
case CKA_EXPONENT_1: return "EXPONENT_1";
|
|
|
|
|
case CKA_EXPONENT_2: return "EXPONENT_2";
|
|
|
|
|
case CKA_COEFFICIENT: return "COEFFICIENT";
|
|
|
|
|
case CKA_PRIME: return "PRIME";
|
|
|
|
|
case CKA_SUBPRIME: return "SUBPRIME";
|
|
|
|
|
case CKA_BASE: return "BASE";
|
|
|
|
|
case CKA_PRIME_BITS: return "PRIME_BITS";
|
2009-10-23 14:57:28 +00:00
|
|
|
|
//case CKA_SUBPRIME_BITS: return "SUBPRIME_BITS";
|
2009-09-09 06:59:54 +00:00
|
|
|
|
case CKA_VALUE_BITS: return "VALUE_BITS";
|
|
|
|
|
case CKA_VALUE_LEN: return "VALUE_LEN";
|
|
|
|
|
case CKA_EXTRACTABLE: return "EXTRACTABLE";
|
|
|
|
|
case CKA_LOCAL: return "LOCAL";
|
|
|
|
|
case CKA_NEVER_EXTRACTABLE: return "NEVER_EXTRACTABLE";
|
|
|
|
|
case CKA_ALWAYS_SENSITIVE: return "ALWAYS_SENSITIVE";
|
|
|
|
|
case CKA_KEY_GEN_MECHANISM: return "KEY_GEN_MECHANISM";
|
|
|
|
|
case CKA_MODIFIABLE: return "MODIFIABLE";
|
|
|
|
|
//case CKA_ECDSA_PARAMS: return "ECDSA_PARAMS";
|
|
|
|
|
case CKA_EC_PARAMS: return "ECDSA_PARAMS or EC_PARAMS";
|
|
|
|
|
case CKA_EC_POINT: return "EC_POINT";
|
|
|
|
|
case CKA_SECONDARY_AUTH: return "SECONDARY_AUTH";
|
|
|
|
|
case CKA_AUTH_PIN_FLAGS: return "AUTH_PIN_FLAGS";
|
|
|
|
|
case CKA_HW_FEATURE_TYPE: return "HW_FEATURE_TYPE";
|
|
|
|
|
case CKA_RESET_ON_INIT: return "RESET_ON_INIT";
|
|
|
|
|
case CKA_HAS_RESET: return "HAS_RESET";
|
|
|
|
|
case CKA_VENDOR_DEFINED: return "VENDOR_DEFINED";
|
2009-10-23 14:57:28 +00:00
|
|
|
|
//case CKA_IBM_OPAQUE: return "IBM_OPAQUE";
|
2014-02-27 12:57:44 +00:00
|
|
|
|
default: return "UNKNOWN";
|
2009-09-02 08:45:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Textual representation of the value.
|
|
|
|
|
std::string readableValue(std::string::size_type len=20,
|
|
|
|
|
std::string::size_type indent=0) const {
|
|
|
|
|
std::string res(indent, ' ');
|
2009-09-09 06:59:54 +00:00
|
|
|
|
switch (type) {
|
|
|
|
|
case CKA_CLASS:
|
2014-04-01 13:10:51 +00:00
|
|
|
|
switch (*((const CK_OBJECT_CLASS*)&value[0])) {
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKO_DATA: return res+"DATA";
|
|
|
|
|
case CKO_CERTIFICATE: return res+"CERTIFICATE";
|
|
|
|
|
case CKO_PUBLIC_KEY: return res+"PUBLIC_KEY";
|
|
|
|
|
case CKO_PRIVATE_KEY: return res+"PRIVATE_KEY";
|
|
|
|
|
case CKO_SECRET_KEY: return res+"SECRET_KEY";
|
|
|
|
|
case CKO_HW_FEATURE: return res+"HW_FEATURE";
|
|
|
|
|
case CKO_DOMAIN_PARAMETERS: return res+"DOMAIN_PARAMETERS";
|
|
|
|
|
case CKO_VENDOR_DEFINED: return res+"VENDOR_DEFINED";
|
|
|
|
|
default: return res+"UNKNOWN";
|
2009-09-09 06:59:54 +00:00
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
default: return crypto::readable(value, len, indent);
|
2009-09-09 06:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Initialize from a given type.
|
|
|
|
|
/** To use this method, you must know what type the attribute
|
|
|
|
|
represents. */
|
2009-10-21 08:52:04 +00:00
|
|
|
|
template<typename TYPE> Attribute& from(const TYPE& v) {
|
2014-04-01 13:10:51 +00:00
|
|
|
|
value = std::string((const char*)&v, sizeof(TYPE));
|
2009-09-16 14:52:09 +00:00
|
|
|
|
return *this;
|
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Convert to a given type.
|
|
|
|
|
/** To use this method, you must know what type the attribute
|
|
|
|
|
represents. */
|
2009-09-29 07:24:04 +00:00
|
|
|
|
template<typename TYPE> TYPE to() const {
|
|
|
|
|
assert(sizeof(TYPE)==value.size());
|
2009-11-24 12:10:25 +00:00
|
|
|
|
return *reinterpret_cast<const TYPE*>(&value[0]);
|
2009-09-29 07:24:04 +00:00
|
|
|
|
}
|
2009-08-31 13:59:23 +00:00
|
|
|
|
CK_ATTRIBUTE_TYPE type;
|
|
|
|
|
std::string value;
|
|
|
|
|
};
|
2009-09-01 09:11:11 +00:00
|
|
|
|
typedef std::map<CK_ATTRIBUTE_TYPE, Attribute> AttributeMap;
|
|
|
|
|
typedef std::vector<Attribute> AttributeList;
|
2009-09-10 12:13:54 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// String with fixed length.
|
|
|
|
|
/** FixString represents a string with a fix with spaces and can be
|
|
|
|
|
converted from and to a std::string by adding and removing the
|
|
|
|
|
fill-spaces. */
|
2009-08-27 14:46:29 +00:00
|
|
|
|
template<std::string::size_type SIZE>
|
|
|
|
|
class FixString: public std::string {
|
2014-02-27 12:57:44 +00:00
|
|
|
|
public:
|
|
|
|
|
FixString() {}
|
|
|
|
|
FixString(const char* const cStr) {
|
|
|
|
|
*this = std::string(cStr, SIZE);
|
|
|
|
|
size_type pos(find_last_not_of(" "));
|
|
|
|
|
if (pos!=npos) resize(pos+1); else resize(0);
|
|
|
|
|
}
|
|
|
|
|
FixString(const unsigned char* const cStr) {
|
|
|
|
|
*this = std::string((const char*)cStr, SIZE);
|
|
|
|
|
size_type pos(find_last_not_of(" "));
|
|
|
|
|
if (pos!=npos) resize(pos+1); else resize(0);
|
|
|
|
|
}
|
|
|
|
|
FixString& operator=(const std::string& other) {
|
|
|
|
|
std::string::operator=(other);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
FixString& operator=(const char* const cStr) {
|
|
|
|
|
*this = std::string(cStr, SIZE);
|
|
|
|
|
size_type pos(find_last_not_of(" "));
|
|
|
|
|
if (pos!=npos) resize(pos+1); else resize(0);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
FixString& operator=(const unsigned char* const cStr) {
|
|
|
|
|
*this = std::string((const char*)cStr, SIZE);
|
|
|
|
|
size_type pos(find_last_not_of(" "));
|
|
|
|
|
if (pos!=npos) resize(pos+1); else resize(0);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
operator unsigned char*() {
|
|
|
|
|
return (unsigned char*)begin().operator->();
|
|
|
|
|
}
|
|
|
|
|
FixString fix() {
|
|
|
|
|
FixString cpy(*this);
|
|
|
|
|
cpy.resize(SIZE, ' ');
|
|
|
|
|
return cpy;
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// C++ representation of mechanism information.
|
2009-08-28 14:57:40 +00:00
|
|
|
|
struct MechanismInfo {
|
|
|
|
|
CK_MECHANISM_TYPE id;
|
|
|
|
|
std::string name;
|
|
|
|
|
CK_ULONG minKeySize;
|
|
|
|
|
CK_ULONG maxKeySize;
|
|
|
|
|
CK_FLAGS flags;
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Construct from type with undefined infos. Use assigment later.
|
|
|
|
|
MechanismInfo(CK_MECHANISM_TYPE type):
|
|
|
|
|
minKeySize(0), maxKeySize(0), flags(0) {
|
|
|
|
|
*this=type;
|
|
|
|
|
}
|
|
|
|
|
/// Fully construct from type and infos.
|
|
|
|
|
MechanismInfo(CK_MECHANISM_TYPE type, const CK_MECHANISM_INFO& info) {
|
|
|
|
|
*this=type;
|
|
|
|
|
*this=info;
|
|
|
|
|
}
|
|
|
|
|
/// Set name and id from CK_MECHANISM_TYPE.
|
|
|
|
|
MechanismInfo& operator=(CK_MECHANISM_TYPE type) {
|
|
|
|
|
id=type;
|
2009-08-28 14:57:40 +00:00
|
|
|
|
switch (id) {
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#ifdef CKM_RSA_PKCS_KEY_PAIR_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_PKCS_KEY_PAIR_GEN: name="RSA_PKCS_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RSA_PKCS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_PKCS: name="RSA_PKCS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RSA_9796
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_9796: name="RSA_9796"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RSA_X_509
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_X_509: name="RSA_X_509"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD2_RSA_PKCS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD2_RSA_PKCS: name="MD2_RSA_PKCS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD5_RSA_PKCS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD5_RSA_PKCS: name="MD5_RSA_PKCS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA1_RSA_PKCS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SHA1_RSA_PKCS: name="SHA1_RSA_PKCS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD128_RSA_PKCS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD128_RSA_PKCS: name="RIPEMD128_RSA_PKCS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD160_RSA_PKCS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD160_RSA_PKCS: name="RIPEMD160_RSA_PKCS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RSA_PKCS_OAEP
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_PKCS_OAEP: name="RSA_PKCS_OAEP"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RSA_X9_31_KEY_PAIR_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_X9_31_KEY_PAIR_GEN: name="RSA_X9_31_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RSA_X9_31
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_X9_31: name="RSA_X9_31"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA1_RSA_X9_31
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SHA1_RSA_X9_31: name="SHA1_RSA_X9_31"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RSA_PKCS_PSS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RSA_PKCS_PSS: name="RSA_PKCS_PSS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA1_RSA_PKCS_PSS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SHA1_RSA_PKCS_PSS: name="SHA1_RSA_PKCS_PSS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DSA_KEY_PAIR_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DSA_KEY_PAIR_GEN: name="DSA_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DSA
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DSA: name="DSA"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DSA_SHA1
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DSA_SHA1: name="DSA_SHA1"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DH_PKCS_KEY_PAIR_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DH_PKCS_KEY_PAIR_GEN: name="DH_PKCS_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DH_PKCS_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DH_PKCS_DERIVE: name="DH_PKCS_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_X9_42_DH_KEY_PAIR_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_X9_42_DH_KEY_PAIR_GEN: name="X9_42_DH_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_X9_42_DH_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_X9_42_DH_DERIVE: name="X9_42_DH_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_X9_42_DH_HYBRID_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_X9_42_DH_HYBRID_DERIVE: name="X9_42_DH_HYBRID_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_X9_42_MQV_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_X9_42_MQV_DERIVE: name="X9_42_MQV_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA256_RSA_PKCS
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA256_RSA_PKCS: name="SHA256_RSA_PKCS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC2_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC2_KEY_GEN: name="RC2_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC2_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC2_ECB: name="RC2_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC2_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC2_CBC: name="RC2_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC2_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC2_MAC: name="RC2_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC2_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC2_MAC_GENERAL: name="RC2_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC2_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC2_CBC_PAD: name="RC2_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC4_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC4_KEY_GEN: name="RC4_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC4
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC4: name="RC4"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES_KEY_GEN: name="DES_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES_ECB: name="DES_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES_CBC: name="DES_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES_MAC: name="DES_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES_MAC_GENERAL: name="DES_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES_CBC_PAD: name="DES_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES2_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES2_KEY_GEN: name="DES2_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES3_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES3_KEY_GEN: name="DES3_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES3_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES3_ECB: name="DES3_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES3_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES3_CBC: name="DES3_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES3_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES3_MAC: name="DES3_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES3_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES3_MAC_GENERAL: name="DES3_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DES3_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DES3_CBC_PAD: name="DES3_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CDMF_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CDMF_KEY_GEN: name="CDMF_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CDMF_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CDMF_ECB: name="CDMF_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CDMF_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CDMF_CBC: name="CDMF_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CDMF_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CDMF_MAC: name="CDMF_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CDMF_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CDMF_MAC_GENERAL: name="CDMF_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CDMF_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CDMF_CBC_PAD: name="CDMF_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD2
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD2: name="MD2"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD2_HMAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD2_HMAC: name="MD2_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD2_HMAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD2_HMAC_GENERAL: name="MD2_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD5
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD5: name="MD5"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD5_HMAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD5_HMAC: name="MD5_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD5_HMAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD5_HMAC_GENERAL: name="MD5_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA_1
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SHA_1: name="SHA_1"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA_1_HMAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SHA_1_HMAC: name="SHA_1_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA_1_HMAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SHA_1_HMAC_GENERAL: name="SHA_1_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD128
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD128: name="RIPEMD128"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD128_HMAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD128_HMAC: name="RIPEMD128_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD128_HMAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD128_HMAC_GENERAL: name="RIPEMD128_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD160
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD160: name="RIPEMD160"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD160_HMAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD160_HMAC: name="RIPEMD160_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RIPEMD160_HMAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RIPEMD160_HMAC_GENERAL: name="RIPEMD160_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA256
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA256: name="SHA256"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA256_HMAC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA256_HMAC: name="SHA256_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA256_HMAC_GENERAL
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA256_HMAC_GENERAL: name="SHA256_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA384
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA384: name="SHA384"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA384_HMAC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA384_HMAC: name="SHA384_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA384_HMAC_GENERAL
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA384_HMAC_GENERAL: name="SHA384_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA512
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA512: name="SHA512"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA512_HMAC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA512_HMAC: name="SHA512_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA512_HMAC_GENERAL
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA512_HMAC_GENERAL: name="SHA512_HMAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST_KEY_GEN: name="CAST_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST_ECB: name="CAST_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST_CBC: name="CAST_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST_MAC: name="CAST_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST_MAC_GENERAL: name="CAST_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST_CBC_PAD: name="CAST_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST3_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST3_KEY_GEN: name="CAST3_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST3_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST3_ECB: name="CAST3_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST3_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST3_CBC: name="CAST3_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST3_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST3_MAC: name="CAST3_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST3_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST3_MAC_GENERAL: name="CAST3_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST3_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_CAST3_CBC_PAD: name="CAST3_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST5_KEY_GEN
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_CAST5_KEY_GEN: name="CAST5_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST128_KEY_GEN
|
|
|
|
|
//case CKM_CAST128_KEY_GEN: name="CAST5_KEY_GEN or
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//CAST128_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST5_ECB
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_CAST5_ECB: name="CAST5_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST128_ECB
|
|
|
|
|
//case CKM_CAST128_ECB: name="CAST5_ECB or CAST128_ECB"; break;
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST5_CBC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_CAST5_CBC: name="CAST5_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST128_CBC
|
|
|
|
|
//case CKM_CAST128_CBC: name="CAST5_CBC or CAST128_CBC"; break;
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST5_MAC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_CAST5_MAC: name="CAST5_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST128_MAC
|
|
|
|
|
//case CKM_CAST128_MAC: name="CAST5_MAC or CAST128_MAC"; break;
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST5_MAC_GENERAL
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_CAST5_MAC_GENERAL: name="CAST5_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST128_MAC_GENERAL
|
|
|
|
|
//case CKM_CAST128_MAC_GENERAL: name="CAST5_MAC_GENERAL or
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//CAST128_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST5_CBC_PAD
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_CAST5_CBC_PAD: name="CAST5_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CAST128_CBC_PAD
|
|
|
|
|
//case CKM_CAST128_CBC_PAD: name="CAST5_CBC_PAD or
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//CAST128_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC5_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC5_KEY_GEN: name="RC5_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC5_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC5_ECB: name="RC5_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC5_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC5_CBC: name="RC5_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC5_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC5_MAC: name="RC5_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC5_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC5_MAC_GENERAL: name="RC5_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_RC5_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_RC5_CBC_PAD: name="RC5_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_IDEA_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_IDEA_KEY_GEN: name="IDEA_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_IDEA_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_IDEA_ECB: name="IDEA_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_IDEA_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_IDEA_CBC: name="IDEA_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_IDEA_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_IDEA_MAC: name="IDEA_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_IDEA_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_IDEA_MAC_GENERAL: name="IDEA_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_IDEA_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_IDEA_CBC_PAD: name="IDEA_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_GENERIC_SECRET_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_GENERIC_SECRET_KEY_GEN: name="GENERIC_SECRET_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CONCATENATE_BASE_AND_KEY
|
2009-08-28 14:57:40 +00:00
|
|
|
|
case CKM_CONCATENATE_BASE_AND_KEY:
|
2009-09-08 14:45:54 +00:00
|
|
|
|
name="CONCATENATE_BASE_AND_KEY"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CONCATENATE_BASE_AND_DATA
|
2009-08-28 14:57:40 +00:00
|
|
|
|
case CKM_CONCATENATE_BASE_AND_DATA:
|
2009-09-08 14:45:54 +00:00
|
|
|
|
name="CONCATENATE_BASE_AND_DATA"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_CONCATENATE_DATA_AND_BASE
|
2009-08-28 14:57:40 +00:00
|
|
|
|
case CKM_CONCATENATE_DATA_AND_BASE:
|
2009-09-08 14:45:54 +00:00
|
|
|
|
name="CONCATENATE_DATA_AND_BASE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_XOR_BASE_AND_DATA
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_XOR_BASE_AND_DATA: name="XOR_BASE_AND_DATA"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_EXTRACT_KEY_FROM_KEY
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_EXTRACT_KEY_FROM_KEY: name="EXTRACT_KEY_FROM_KEY"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SSL3_PRE_MASTER_KEY_GEN
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SSL3_PRE_MASTER_KEY_GEN:
|
|
|
|
|
name="SSL3_PRE_MASTER_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SSL3_MASTER_KEY_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SSL3_MASTER_KEY_DERIVE: name="SSL3_MASTER_KEY_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SSL3_KEY_AND_MAC_DERIVE
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SSL3_KEY_AND_MAC_DERIVE:
|
|
|
|
|
name="SSL3_KEY_AND_MAC_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SSL3_MASTER_KEY_DERIVE_DH
|
2009-08-28 14:57:40 +00:00
|
|
|
|
case CKM_SSL3_MASTER_KEY_DERIVE_DH:
|
2009-09-08 14:45:54 +00:00
|
|
|
|
name="SSL3_MASTER_KEY_DERIVE_DH"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_TLS_PRE_MASTER_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_TLS_PRE_MASTER_KEY_GEN: name="TLS_PRE_MASTER_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_TLS_MASTER_KEY_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_TLS_MASTER_KEY_DERIVE: name="TLS_MASTER_KEY_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_TLS_KEY_AND_MAC_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_TLS_KEY_AND_MAC_DERIVE: name="TLS_KEY_AND_MAC_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_TLS_MASTER_KEY_DERIVE_DH
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_TLS_MASTER_KEY_DERIVE_DH:
|
|
|
|
|
name="TLS_MASTER_KEY_DERIVE_DH"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SSL3_MD5_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SSL3_MD5_MAC: name="SSL3_MD5_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SSL3_SHA1_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SSL3_SHA1_MAC: name="SSL3_SHA1_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD5_KEY_DERIVATION
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD5_KEY_DERIVATION: name="MD5_KEY_DERIVATION"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_MD2_KEY_DERIVATION
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_MD2_KEY_DERIVATION: name="MD2_KEY_DERIVATION"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA1_KEY_DERIVATION
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SHA1_KEY_DERIVATION: name="SHA1_KEY_DERIVATION"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SHA256_KEY_DERIVATION
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_SHA256_KEY_DERIVATION: name="SHA256_KEY_DERIVATION"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_MD2_DES_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_MD2_DES_CBC: name="PBE_MD2_DES_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_MD5_DES_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_MD5_DES_CBC: name="PBE_MD5_DES_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_MD5_CAST_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_MD5_CAST_CBC: name="PBE_MD5_CAST_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_MD5_CAST3_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_MD5_CAST3_CBC: name="PBE_MD5_CAST3_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_MD5_CAST5_CBC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_PBE_MD5_CAST5_CBC: name="PBE_MD5_CAST5_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_MD5_CAST128_CBC
|
|
|
|
|
//case CKM_PBE_MD5_CAST128_CBC: name="PBE_MD5_CAST5_CBC or
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//PBE_MD5_CAST128_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_CAST5_CBC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_PBE_SHA1_CAST5_CBC: name="PBE_SHA1_CAST5_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_CAST128_CBC
|
|
|
|
|
//case CKM_PBE_SHA1_CAST128_CBC: name="PBE_SHA1_CAST5_CBC or
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//PBE_SHA1_CAST128_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_RC4_128
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_SHA1_RC4_128: name="PBE_SHA1_RC4_128"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_RC4_40
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_SHA1_RC4_40: name="PBE_SHA1_RC4_40"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_DES3_EDE_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_SHA1_DES3_EDE_CBC: name="PBE_SHA1_DES3_EDE_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_DES2_EDE_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_SHA1_DES2_EDE_CBC: name="PBE_SHA1_DES2_EDE_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_RC2_128_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_SHA1_RC2_128_CBC: name="PBE_SHA1_RC2_128_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBE_SHA1_RC2_40_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PBE_SHA1_RC2_40_CBC: name="PBE_SHA1_RC2_40_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PKCS5_PBKD2
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_PKCS5_PBKD2: name="PKCS5_PBKD2"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_PBA_SHA1_WITH_SHA1_HMAC
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_PBA_SHA1_WITH_SHA1_HMAC:
|
|
|
|
|
name="PBA_SHA1_WITH_SHA1_HMAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_KEY_WRAP_LYNKS
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_KEY_WRAP_LYNKS: name="KEY_WRAP_LYNKS"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_KEY_WRAP_SET_OAEP
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_KEY_WRAP_SET_OAEP: name="KEY_WRAP_SET_OAEP"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_KEY_GEN: name="SKIPJACK_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_ECB64
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_ECB64: name="SKIPJACK_ECB64"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_CBC64
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_CBC64: name="SKIPJACK_CBC64"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_OFB64
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_OFB64: name="SKIPJACK_OFB64"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_CFB64
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_CFB64: name="SKIPJACK_CFB64"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_CFB32
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_CFB32: name="SKIPJACK_CFB32"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_CFB16
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_CFB16: name="SKIPJACK_CFB16"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_CFB8
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_CFB8: name="SKIPJACK_CFB8"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_WRAP
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_WRAP: name="SKIPJACK_WRAP"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_PRIVATE_WRAP
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_PRIVATE_WRAP: name="SKIPJACK_PRIVATE_WRAP"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_SKIPJACK_RELAYX
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_SKIPJACK_RELAYX: name="SKIPJACK_RELAYX"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_KEA_KEY_PAIR_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_KEA_KEY_PAIR_GEN: name="KEA_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_KEA_KEY_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_KEA_KEY_DERIVE: name="KEA_KEY_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_FORTEZZA_TIMESTAMP
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_FORTEZZA_TIMESTAMP: name="FORTEZZA_TIMESTAMP"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_BATON_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_BATON_KEY_GEN: name="BATON_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_BATON_ECB128
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_BATON_ECB128: name="BATON_ECB128"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_BATON_ECB96
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_BATON_ECB96: name="BATON_ECB96"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_BATON_CBC128
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_BATON_CBC128: name="BATON_CBC128"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_BATON_COUNTER
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_BATON_COUNTER: name="BATON_COUNTER"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_BATON_SHUFFLE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_BATON_SHUFFLE: name="BATON_SHUFFLE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_BATON_WRAP
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_BATON_WRAP: name="BATON_WRAP"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_ECDSA_KEY_PAIR_GEN
|
2014-02-27 12:57:44 +00:00
|
|
|
|
case CKM_ECDSA_KEY_PAIR_GEN: name="ECDSA_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_EC_KEY_PAIR_GEN
|
|
|
|
|
//case CKM_EC_KEY_PAIR_GEN: name="ECDSA_KEY_PAIR_GEN or
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//EC_KEY_PAIR_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_ECDSA
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_ECDSA: name="ECDSA"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_ECDSA_SHA1
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_ECDSA_SHA1: name="ECDSA_SHA1"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_ECDH1_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_ECDH1_DERIVE: name="ECDH1_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_ECDH1_COFACTOR_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_ECDH1_COFACTOR_DERIVE: name="ECDH1_COFACTOR_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_ECMQV_DERIVE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_ECMQV_DERIVE: name="ECMQV_DERIVE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_JUNIPER_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_JUNIPER_KEY_GEN: name="JUNIPER_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_JUNIPER_ECB128
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_JUNIPER_ECB128: name="JUNIPER_ECB128"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_JUNIPER_CBC128
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_JUNIPER_CBC128: name="JUNIPER_CBC128"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_JUNIPER_COUNTER
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_JUNIPER_COUNTER: name="JUNIPER_COUNTER"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_JUNIPER_SHUFFLE
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_JUNIPER_SHUFFLE: name="JUNIPER_SHUFFLE"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_JUNIPER_WRAP
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_JUNIPER_WRAP: name="JUNIPER_WRAP"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_FASTHASH
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_FASTHASH: name="FASTHASH"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_AES_KEY_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_AES_KEY_GEN: name="AES_KEY_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_AES_ECB
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_AES_ECB: name="AES_ECB"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_AES_CBC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_AES_CBC: name="AES_CBC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_AES_MAC
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_AES_MAC: name="AES_MAC"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_AES_MAC_GENERAL
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_AES_MAC_GENERAL: name="AES_MAC_GENERAL"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_AES_CBC_PAD
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_AES_CBC_PAD: name="AES_CBC_PAD"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DSA_PARAMETER_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DSA_PARAMETER_GEN: name="DSA_PARAMETER_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_DH_PKCS_PARAMETER_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_DH_PKCS_PARAMETER_GEN: name="DH_PKCS_PARAMETER_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_X9_42_DH_PARAMETER_GEN
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_X9_42_DH_PARAMETER_GEN: name="X9_42_DH_PARAMETER_GEN"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CKM_VENDOR_DEFINED
|
2009-09-08 14:45:54 +00:00
|
|
|
|
case CKM_VENDOR_DEFINED: name="VENDOR_DEFINED"; break;
|
2014-03-04 09:50:10 +00:00
|
|
|
|
#endif
|
2009-08-28 14:57:40 +00:00
|
|
|
|
default: {
|
|
|
|
|
std::stringstream ss;
|
2014-02-27 12:57:44 +00:00
|
|
|
|
ss<<id;
|
|
|
|
|
name=ss.str();
|
2009-08-28 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
/// Assign information.
|
|
|
|
|
MechanismInfo& operator=(const CK_MECHANISM_INFO& info) {
|
|
|
|
|
minKeySize = info.ulMinKeySize;
|
|
|
|
|
maxKeySize = info.ulMaxKeySize;
|
|
|
|
|
flags = info.flags;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
bool operator<(const MechanismInfo& o) const {
|
|
|
|
|
return id<o.id;
|
2009-08-28 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2014-02-27 12:57:44 +00:00
|
|
|
|
typedef std::set<MechanismInfo> MechanismList;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Handle slot information.
|
2009-08-27 14:46:29 +00:00
|
|
|
|
struct SlotInfo {
|
|
|
|
|
FixString<64> slotDescription;
|
|
|
|
|
FixString<32> manufacturerID;
|
|
|
|
|
CK_FLAGS flags;
|
|
|
|
|
CK_VERSION hardwareVersion;
|
|
|
|
|
CK_VERSION firmwareVersion;
|
2014-01-20 13:05:08 +00:00
|
|
|
|
|
2014-01-21 08:20:33 +00:00
|
|
|
|
SlotInfo() {
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-20 13:05:08 +00:00
|
|
|
|
//! Convert C-Structure of Slot Information Into C++
|
|
|
|
|
SlotInfo(const CK_SLOT_INFO& cInfo):
|
|
|
|
|
slotDescription(cInfo.slotDescription),
|
|
|
|
|
manufacturerID(cInfo.manufacturerID),
|
|
|
|
|
flags(cInfo.flags),
|
|
|
|
|
hardwareVersion(cInfo.hardwareVersion),
|
|
|
|
|
firmwareVersion(cInfo.firmwareVersion) {
|
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
};
|
2014-01-22 15:14:36 +00:00
|
|
|
|
|
|
|
|
|
struct TokenInfo; // forward declaration
|
2014-01-23 13:32:17 +00:00
|
|
|
|
inline std::ostream& operator<<(std::ostream& out, const TokenInfo& ti);
|
2014-01-22 15:14:36 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Handle token information.
|
2009-08-27 14:46:29 +00:00
|
|
|
|
struct TokenInfo {
|
|
|
|
|
FixString<32> label;
|
|
|
|
|
FixString<32> manufacturerID;
|
|
|
|
|
FixString<16> model;
|
|
|
|
|
FixString<16> serialNumber;
|
|
|
|
|
CK_FLAGS flags;
|
|
|
|
|
CK_ULONG maxSessionCount;
|
|
|
|
|
CK_ULONG sessionCount;
|
|
|
|
|
CK_ULONG maxRwSessionCount;
|
|
|
|
|
CK_ULONG rwSessionCount;
|
|
|
|
|
CK_ULONG maxPinLen;
|
|
|
|
|
CK_ULONG minPinLen;
|
|
|
|
|
CK_ULONG totalPublicMemory;
|
|
|
|
|
CK_ULONG freePublicMemory;
|
|
|
|
|
CK_ULONG totalPrivateMemory;
|
|
|
|
|
CK_ULONG freePrivateMemory;
|
|
|
|
|
CK_VERSION hardwareVersion;
|
|
|
|
|
CK_VERSION firmwareVersion;
|
|
|
|
|
FixString<16> utcTime;
|
2014-01-21 08:20:33 +00:00
|
|
|
|
|
|
|
|
|
TokenInfo() {
|
2014-01-22 15:14:36 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2014-01-21 08:20:33 +00:00
|
|
|
|
}
|
2014-01-20 13:05:08 +00:00
|
|
|
|
|
|
|
|
|
//! Convert C-Structure of Token Information Into C++
|
|
|
|
|
TokenInfo(const CK_TOKEN_INFO& cInfo):
|
|
|
|
|
label(cInfo.label),
|
|
|
|
|
manufacturerID(cInfo.manufacturerID),
|
|
|
|
|
model(cInfo.model),
|
|
|
|
|
serialNumber(cInfo.serialNumber),
|
|
|
|
|
flags(cInfo.flags),
|
|
|
|
|
maxSessionCount(cInfo.ulMaxSessionCount),
|
|
|
|
|
sessionCount(cInfo.ulSessionCount),
|
|
|
|
|
maxRwSessionCount(cInfo.ulMaxRwSessionCount),
|
|
|
|
|
rwSessionCount(cInfo.ulRwSessionCount),
|
|
|
|
|
maxPinLen(cInfo.ulMaxPinLen),
|
|
|
|
|
minPinLen(cInfo.ulMinPinLen),
|
|
|
|
|
totalPublicMemory(cInfo.ulTotalPublicMemory),
|
|
|
|
|
freePublicMemory(cInfo.ulFreePublicMemory),
|
|
|
|
|
totalPrivateMemory(cInfo.ulTotalPrivateMemory),
|
|
|
|
|
freePrivateMemory(cInfo.ulFreePrivateMemory),
|
|
|
|
|
hardwareVersion(cInfo.hardwareVersion),
|
|
|
|
|
firmwareVersion(cInfo.firmwareVersion),
|
|
|
|
|
utcTime(cInfo.utcTime) {
|
2014-04-04 11:27:08 +00:00
|
|
|
|
CRYPTOLOG("log *this={"<<*this<<'}');
|
2014-01-20 13:05:08 +00:00
|
|
|
|
}
|
2014-01-22 15:14:36 +00:00
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
};
|
2014-01-22 15:14:36 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Textual representation for token information.
|
2014-01-23 13:32:17 +00:00
|
|
|
|
inline std::ostream& operator<<(std::ostream& out, const TokenInfo& ti) {
|
2014-01-22 15:14:36 +00:00
|
|
|
|
return out
|
|
|
|
|
<<"label="<<ti.label<<std::endl
|
|
|
|
|
<<"manufacturerID="<<ti.manufacturerID<<std::endl
|
|
|
|
|
<<"model="<<ti.model<<std::endl
|
|
|
|
|
<<"serialNumber="<<ti.serialNumber<<std::endl
|
|
|
|
|
<<"flags="<<ti.flags<<std::endl
|
|
|
|
|
<<"maxSessionCount="<<ti.maxSessionCount<<std::endl
|
|
|
|
|
<<"sessionCount="<<ti.sessionCount<<std::endl
|
|
|
|
|
<<"maxRwSessionCount="<<ti.maxRwSessionCount<<std::endl
|
|
|
|
|
<<"rwSessionCount="<<ti.rwSessionCount<<std::endl
|
|
|
|
|
<<"maxPinLen="<<ti.maxPinLen<<std::endl
|
|
|
|
|
<<"minPinLen="<<ti.minPinLen<<std::endl
|
|
|
|
|
<<"totalPublicMemory="<<ti.totalPublicMemory<<std::endl
|
|
|
|
|
<<"freePublicMemory="<<ti.freePublicMemory<<std::endl
|
|
|
|
|
<<"totalPrivateMemory="<<ti.totalPrivateMemory<<std::endl
|
|
|
|
|
<<"freePrivateMemory="<<ti.freePrivateMemory<<std::endl
|
|
|
|
|
<<"hardwareVersion="<<ti.hardwareVersion.major<<'.'
|
|
|
|
|
<<ti.hardwareVersion.minor<<std::endl
|
|
|
|
|
<<"firmwareVersion="<<ti.firmwareVersion.major<<'.'
|
|
|
|
|
<<ti.firmwareVersion.minor<<std::endl
|
|
|
|
|
<<"utcTime="<<ti.utcTime;
|
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
|
|
|
|
|
/// Handle library information.
|
2009-08-27 14:46:29 +00:00
|
|
|
|
struct Info {
|
|
|
|
|
CK_VERSION cryptokiVersion;
|
|
|
|
|
FixString<32> manufacturerID;
|
|
|
|
|
CK_FLAGS flags;
|
|
|
|
|
FixString<32> libraryDescription;
|
|
|
|
|
CK_VERSION libraryVersion;
|
|
|
|
|
};
|
|
|
|
|
|
2009-09-18 11:41:30 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
/*! @addtogroup cryptokilib */
|
|
|
|
|
//@{
|
|
|
|
|
|
2013-10-21 12:13:55 +00:00
|
|
|
|
/// Load Cryptoki Library for use with Smart Card.
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/** This is your starting point when accessing tokens through
|
|
|
|
|
PKCS#11. Get an instance using Library::Library. */
|
2013-10-15 11:57:29 +00:00
|
|
|
|
class Library {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2013-11-11 11:49:09 +00:00
|
|
|
|
friend class Slot;
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
//! Initialize for a given library
|
|
|
|
|
/*! @note Do not instanciate more than one Library instance per
|
|
|
|
|
shared library. Normally you need only one instance.
|
2013-10-15 11:57:29 +00:00
|
|
|
|
|
2009-09-02 13:57:56 +00:00
|
|
|
|
@param library name of the shared library that supports pkcs#11
|
2014-04-01 13:10:51 +00:00
|
|
|
|
@param exceptions whether exceptions should be thrown */
|
|
|
|
|
Library(const std::string& library, bool exceptions=true):
|
|
|
|
|
_init(new Init(library, exceptions)) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-09-02 13:57:56 +00:00
|
|
|
|
}
|
2013-11-11 11:49:09 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
Library() {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
}
|
2013-10-15 11:57:29 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
/// Initiatlize the library: load and unload the shared object.
|
2013-10-15 11:57:29 +00:00
|
|
|
|
class Init {
|
2009-09-02 13:57:56 +00:00
|
|
|
|
|
2013-10-15 11:57:29 +00:00
|
|
|
|
private:
|
2009-12-09 11:13:54 +00:00
|
|
|
|
|
2013-10-15 11:57:29 +00:00
|
|
|
|
friend class Library;
|
|
|
|
|
|
|
|
|
|
bool _exc;
|
|
|
|
|
CK_RV _res;
|
|
|
|
|
CK_FUNCTION_LIST* _fn;
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
void* _lib;
|
|
|
|
|
#else
|
|
|
|
|
HINSTANCE _lib;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//! Initialize Funcion List for this Instance
|
|
|
|
|
bool functionList(const std::string& library);
|
|
|
|
|
|
|
|
|
|
bool check(CK_RV result, const std::string& context="");
|
|
|
|
|
|
|
|
|
|
/*! @return error text of last cryptoki call */
|
|
|
|
|
std::string error(CK_RV res);
|
|
|
|
|
|
|
|
|
|
public:
|
2014-02-27 12:57:44 +00:00
|
|
|
|
|
|
|
|
|
/// Called from Library::Library
|
2013-10-15 11:57:29 +00:00
|
|
|
|
Init(const std::string& library="opensc-pkcs11.so", bool exc=true);
|
|
|
|
|
|
|
|
|
|
~Init();
|
|
|
|
|
|
|
|
|
|
Init& reset() {
|
|
|
|
|
check(_fn->C_Finalize(0), CRYPTOKI_FN_LOG("C_Finalize"));
|
|
|
|
|
check(_fn->C_Initialize(0), CRYPTOKI_FN_LOG("C_Initialize"));
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CK_FUNCTION_LIST* fn() {
|
|
|
|
|
return _fn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @name C Like Error Handling
|
|
|
|
|
|
|
|
|
|
You are strongly recommended not to disable exception
|
|
|
|
|
handling. If you disable it, you must check after every
|
|
|
|
|
operation whether it was successful or not. These methods
|
|
|
|
|
provide all you need for that. */
|
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
/*! @return @c true if last cryptoki on this object call was
|
|
|
|
|
successful */
|
|
|
|
|
operator bool();
|
|
|
|
|
|
|
|
|
|
/*! @return error text of last cryptoki call */
|
|
|
|
|
std::string error();
|
|
|
|
|
|
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
};
|
2009-08-28 06:56:23 +00:00
|
|
|
|
|
2013-10-15 11:57:29 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Get pointer to cryptoki API functions.
|
|
|
|
|
/** Used internally, normally you shouldn't use this directly. */
|
2013-10-15 11:57:29 +00:00
|
|
|
|
CK_FUNCTION_LIST* operator->() {
|
|
|
|
|
return _init->fn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @name C Like Error Handling
|
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
You are strongly recommended not to disable exception
|
|
|
|
|
handling. If you disable it, you must check after every
|
|
|
|
|
operation whether it was successful or not. These methods
|
|
|
|
|
provide all you need for that. */
|
|
|
|
|
//@{
|
2014-02-27 12:57:44 +00:00
|
|
|
|
|
|
|
|
|
/// @return true if exceptions are thrown in case of error
|
|
|
|
|
bool exc() {
|
|
|
|
|
return _init->_exc;
|
|
|
|
|
}
|
2013-10-15 11:57:29 +00:00
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @return @c true if last cryptoki on this object call was successful */
|
2013-10-15 11:57:29 +00:00
|
|
|
|
operator bool() {
|
|
|
|
|
return *_init;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @return error text of last cryptoki call */
|
2013-10-15 11:57:29 +00:00
|
|
|
|
std::string error() {
|
|
|
|
|
return _init->error();
|
|
|
|
|
}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
|
|
|
|
|
/// Convert @c CK_RV return code to a human readable text.
|
2013-10-15 11:57:29 +00:00
|
|
|
|
std::string error(CK_RV res) {
|
|
|
|
|
return _init->error(res);
|
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
//@}
|
2014-02-27 12:57:44 +00:00
|
|
|
|
|
|
|
|
|
/// Get cryptoki library informartion.
|
2009-08-27 14:46:29 +00:00
|
|
|
|
Info info() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
Info inf;
|
|
|
|
|
CK_INFO cInf;
|
|
|
|
|
//! calls @c C_GetInfo
|
2013-10-15 11:57:29 +00:00
|
|
|
|
if (!_init->check(_init->fn()
|
|
|
|
|
->C_GetInfo(&cInf), CRYPTOKI_FN_LOG("C_GetInfo")))
|
2009-08-27 14:46:29 +00:00
|
|
|
|
return inf;
|
|
|
|
|
inf.cryptokiVersion = cInf.cryptokiVersion;
|
|
|
|
|
inf.manufacturerID = cInf.manufacturerID;
|
|
|
|
|
inf.flags = cInf.flags;
|
|
|
|
|
inf.libraryDescription = cInf.libraryDescription;
|
|
|
|
|
inf.libraryVersion = cInf.libraryVersion;
|
|
|
|
|
return inf;
|
|
|
|
|
}
|
2013-10-15 11:57:29 +00:00
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! Get a list of available slots
|
2013-10-15 11:57:29 +00:00
|
|
|
|
/*! @param tokenPresent whether a token must be inserted into the
|
|
|
|
|
reader
|
2013-10-10 09:13:19 +00:00
|
|
|
|
@param name if given, only return slots with a given name
|
2009-08-27 14:46:29 +00:00
|
|
|
|
@return list of matching slots */
|
2013-10-15 11:57:29 +00:00
|
|
|
|
SlotList slotList(bool tokenPresent=true,
|
|
|
|
|
std::string name=std::string());
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2013-10-15 11:57:29 +00:00
|
|
|
|
private:
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
std::shared_ptr<Init> _init;
|
2013-10-15 11:57:29 +00:00
|
|
|
|
|
|
|
|
|
};
|
2013-10-21 12:13:55 +00:00
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! Slot and Token Management
|
|
|
|
|
class Slot {
|
|
|
|
|
private:
|
|
|
|
|
|
2013-10-15 11:57:29 +00:00
|
|
|
|
friend class Library;
|
2009-08-28 06:56:23 +00:00
|
|
|
|
friend class Session;
|
|
|
|
|
friend class Object;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2013-10-15 11:57:29 +00:00
|
|
|
|
Library _library;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_SLOT_ID _slot;
|
|
|
|
|
CK_RV _res;
|
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
Slot(const Slot& o):
|
|
|
|
|
_library(o._library), _slot(o._slot), _res(o._res) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("ID="<<_slot);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Slots are created from Library::slotList.
|
2014-03-04 07:51:30 +00:00
|
|
|
|
/** @note Empty constructor needs immediate assignment. This
|
|
|
|
|
constructor is public only to be inserted to STL
|
|
|
|
|
containers. */
|
2013-11-11 11:49:09 +00:00
|
|
|
|
Slot(): _slot(0), _res(-1) {
|
|
|
|
|
CRYPTOLOG("ID="<<_slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Slot& operator=(const Slot& o) {
|
|
|
|
|
_library = o._library;
|
|
|
|
|
_slot = o._slot;
|
|
|
|
|
_res = o._res;
|
|
|
|
|
CRYPTOLOG("ID="<<_slot);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 07:51:30 +00:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
/// Slots are created from Library::slotList.
|
|
|
|
|
Slot(const Library& lib, CK_SLOT_ID slot):
|
|
|
|
|
_library(lib), _slot(slot), _res(CKR_OK) {
|
|
|
|
|
CRYPTOLOG("ID="<<_slot);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
bool check(CK_RV result, const std::string& context="") {
|
|
|
|
|
_res = result;
|
2013-11-11 11:49:09 +00:00
|
|
|
|
if (_library.exc() && !*this) {
|
|
|
|
|
if (!context.empty()) {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
throw access_error(context+": "+error());
|
2013-11-11 11:49:09 +00:00
|
|
|
|
} else {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
throw access_error(error());
|
2013-11-11 11:49:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
return _res==CKR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
/*! @name C Like Error Handling
|
|
|
|
|
|
|
|
|
|
You are strongly recommended not to disable exception
|
|
|
|
|
handling. If you disable it, you must check after every
|
|
|
|
|
operation whether it was successful or not. These methods
|
|
|
|
|
provide all you need for that. */
|
|
|
|
|
//@{
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @return @c true if last cryptoki on this object call was successful */
|
|
|
|
|
operator bool() {
|
|
|
|
|
return _res==CKR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @return error text of last cryptoki call */
|
|
|
|
|
std::string error() {
|
2013-10-15 11:57:29 +00:00
|
|
|
|
return _library.error(_res);
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Access to the Library.
|
2013-11-12 15:06:45 +00:00
|
|
|
|
Library& library() {
|
|
|
|
|
return _library;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Get the Slot's MechanismInfo given a @c CK_MECHANISM_TYPE
|
|
|
|
|
/** Used internally by mechanismlist(). */
|
2009-08-28 14:57:40 +00:00
|
|
|
|
MechanismInfo mechanisminfo(CK_MECHANISM_TYPE mechanism) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2014-02-27 12:57:44 +00:00
|
|
|
|
CK_MECHANISM_INFO info;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GetMechanismInfo
|
2014-02-27 12:57:44 +00:00
|
|
|
|
check(_library->C_GetMechanismInfo(_slot, mechanism, &info),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetMechanismInfo"));
|
2014-02-27 12:57:44 +00:00
|
|
|
|
return MechanismInfo(mechanism, info);
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Get a list of the Slot's mechanisms.
|
2009-08-27 14:46:29 +00:00
|
|
|
|
MechanismList mechanismlist() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
MechanismList res;
|
|
|
|
|
CK_ULONG count(0);
|
|
|
|
|
//! calls @c C_GetMechanismList
|
2013-10-15 11:57:29 +00:00
|
|
|
|
if (!check(_library->C_GetMechanismList(_slot, 0, &count),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetMechanismList")) || !count) return res;
|
|
|
|
|
CK_MECHANISM_TYPE* mechanisms = 0;
|
|
|
|
|
try {
|
|
|
|
|
mechanisms = new CK_MECHANISM_TYPE[count];
|
2013-10-15 11:57:29 +00:00
|
|
|
|
if (!check(_library->C_GetMechanismList(_slot, mechanisms, &count),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetMechanismList"))) {
|
|
|
|
|
delete[] mechanisms;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2009-08-28 14:57:40 +00:00
|
|
|
|
for (CK_ULONG i(0); i<count; ++i)
|
2014-02-27 12:57:44 +00:00
|
|
|
|
res.insert(mechanisminfo(mechanisms[i]));
|
2009-08-27 14:46:29 +00:00
|
|
|
|
} catch (...) {
|
|
|
|
|
delete[] mechanisms;
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
delete[] mechanisms;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 10:41:34 +00:00
|
|
|
|
//! Read Slot Information
|
2009-08-28 14:57:40 +00:00
|
|
|
|
SlotInfo slotinfo() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_SLOT_INFO cInfo;
|
|
|
|
|
//! calls @c C_GetSlotInfo
|
2013-10-15 11:57:29 +00:00
|
|
|
|
if (!check(_library->C_GetSlotInfo(_slot, &cInfo),
|
2014-01-13 10:41:34 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetSlotInfo")))
|
2014-01-22 15:14:36 +00:00
|
|
|
|
return SlotInfo();
|
|
|
|
|
return SlotInfo(cInfo);
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
2014-01-13 10:41:34 +00:00
|
|
|
|
|
|
|
|
|
//! Read Token Information
|
2009-08-28 14:57:40 +00:00
|
|
|
|
TokenInfo tokeninfo() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GetTokenInfo
|
|
|
|
|
CK_TOKEN_INFO cInfo;
|
2013-10-15 11:57:29 +00:00
|
|
|
|
if (!check(_library->C_GetTokenInfo(_slot, &cInfo),
|
2014-01-13 10:41:34 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetTokenInfo")))
|
2014-01-22 15:14:36 +00:00
|
|
|
|
return TokenInfo();
|
|
|
|
|
return TokenInfo(cInfo);
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Initialize a token.
|
|
|
|
|
/** If the token has not been initialized (i.e. new from the
|
|
|
|
|
factory), then the @c pin parameter becomes the initial value
|
|
|
|
|
of the SO PIN. If the token is being reinitialized, the @c pin
|
|
|
|
|
parameter is checked against the existing SO PIN to
|
|
|
|
|
authorize the initialization operation. In both cases, the
|
|
|
|
|
SO PIN is the value @c pin after the function completes
|
|
|
|
|
successfully. If the SO PIN is lost, then the card must be
|
|
|
|
|
reinitialized using a mechanism outside the scope of this
|
|
|
|
|
standard. The CKF_TOKEN_INITIALIZED flag in the
|
|
|
|
|
CK_TOKEN_INFO structure indicates the action that will
|
|
|
|
|
result from calling C_InitToken. If set, the token will be
|
|
|
|
|
reinitialized, and the client must supply the existing SO
|
|
|
|
|
password in @c pin.
|
|
|
|
|
|
|
|
|
|
When a token is initialized, all objects that can be
|
|
|
|
|
destroyed are destroyed (i.e., all except for
|
|
|
|
|
“indestructible” objects such as keys built into the
|
|
|
|
|
token). Also, access by the normal user is disabled until
|
|
|
|
|
the SO sets the normal user’s PIN. Depending on the token,
|
|
|
|
|
some “default” objects may be created, and attributes of
|
|
|
|
|
some objects may be set to default values.
|
|
|
|
|
|
|
|
|
|
If the token has a “protected authentication path”, as
|
|
|
|
|
indicated by the CKF_PROTECTED_AUTHENTICATION_PATH flag in
|
|
|
|
|
its CK_TOKEN_INFO being set, then that means that there is
|
|
|
|
|
some way for a user to be authenticated to the token without
|
|
|
|
|
having the application send a PIN through the Cryptoki
|
|
|
|
|
library. One such possibility is that the user enters a PIN
|
|
|
|
|
on a PINpad on the token itself, or on the slot device. To
|
|
|
|
|
initialize a token with such a protected authentication
|
|
|
|
|
path, the @c pin parameter to C_InitToken should be empty.
|
|
|
|
|
During the execution of C_InitToken, the SO’s PIN will be
|
|
|
|
|
entered through the protected authentication path.
|
|
|
|
|
|
|
|
|
|
If the token has a protected authentication path other than
|
|
|
|
|
a PINpad, then it is token- dependent whether or not
|
|
|
|
|
C_InitToken can be used to initialize the token.
|
|
|
|
|
|
|
|
|
|
A token cannot be initialized if Cryptoki detects that any
|
|
|
|
|
application has an open session with it; when a call to
|
|
|
|
|
C_InitToken is made under such circumstances, the call fails
|
|
|
|
|
with error CKR_SESSION_EXISTS. Unfortunately, it may happen
|
|
|
|
|
when C_InitToken is called that some other application does
|
|
|
|
|
have an open session with the token, but Cryptoki cannot
|
|
|
|
|
detect this, because it cannot detect anything about other
|
|
|
|
|
applications using the token. If this is the case, then the
|
|
|
|
|
consequences of the C_InitToken call are undefined.
|
|
|
|
|
|
|
|
|
|
The C_InitToken function may not be sufficient to properly
|
|
|
|
|
initialize complex tokens. In these situations, an
|
|
|
|
|
initialization mechanism outside the scope of Cryptoki must
|
|
|
|
|
be employed. The definition of “complex token” is product
|
|
|
|
|
specific.
|
|
|
|
|
|
|
|
|
|
@param pin SO's initial PIN
|
|
|
|
|
@param label label of the token */
|
2009-08-28 14:57:40 +00:00
|
|
|
|
bool inittoken(std::string pin, FixString<32> label) {
|
2014-02-27 12:57:44 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_InitToken
|
2014-03-04 08:51:54 +00:00
|
|
|
|
std::string in(label);
|
|
|
|
|
in.resize(32, ' ');
|
2014-02-27 12:57:44 +00:00
|
|
|
|
if (pin.size())
|
|
|
|
|
return check(_library->C_InitToken
|
|
|
|
|
(_slot,
|
|
|
|
|
(unsigned char*)&pin[0], pin.size(),
|
2014-03-04 08:51:54 +00:00
|
|
|
|
(unsigned char*)&in[0]),
|
2014-02-27 12:57:44 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_InitToken"));
|
|
|
|
|
else
|
|
|
|
|
return check(_library->C_InitToken
|
|
|
|
|
(_slot,
|
|
|
|
|
0, 0, // pin from external pin pad
|
2014-03-04 08:51:54 +00:00
|
|
|
|
(unsigned char*)&in[0]),
|
2014-02-27 12:57:44 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_InitToken"));
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
2009-08-28 06:56:23 +00:00
|
|
|
|
class SlotEventListener {
|
|
|
|
|
public: virtual void slotEvent() = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool registerforslotevent(SlotEventListener&) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_WaitForSlotEvent
|
2014-02-27 12:57:44 +00:00
|
|
|
|
return check(_library->C_WaitForSlotEvent(CK_FLAGS, &_slot, 0),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_WaitForSlotEvent"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Session Management
|
|
|
|
|
/** @note Not implemented: CK_RV C_CloseAllSessions(CK_SLOT_ID); */
|
2010-09-17 07:44:11 +00:00
|
|
|
|
class Session {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
private:
|
|
|
|
|
|
2009-09-10 12:13:54 +00:00
|
|
|
|
friend class Login;
|
2009-08-28 06:56:23 +00:00
|
|
|
|
friend class Object;
|
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
typedef std::multimap<CK_SLOT_ID, CK_SESSION_HANDLE> Slots;
|
|
|
|
|
|
|
|
|
|
Slot _slot;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_SESSION_HANDLE _session;
|
|
|
|
|
CK_RV _res;
|
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
static Slots& slots() {
|
|
|
|
|
static Slots _slots;
|
|
|
|
|
return _slots;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
Session(); // forbidden
|
|
|
|
|
|
|
|
|
|
bool check(CK_RV result, const std::string& context="") {
|
|
|
|
|
_res = result;
|
2013-11-12 15:06:45 +00:00
|
|
|
|
if (_slot.library().exc() && !*this) {
|
2013-11-11 11:49:09 +00:00
|
|
|
|
if (!context.empty()) {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
throw access_error(context+": "+error());
|
2013-11-11 11:49:09 +00:00
|
|
|
|
} else {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
throw access_error(error());
|
2013-11-11 11:49:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
return _res==CKR_OK;
|
|
|
|
|
}
|
2010-09-17 07:44:11 +00:00
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
//! calls @c C_OpenSession if it's the first session
|
|
|
|
|
void open(bool rw=false) {
|
|
|
|
|
CRYPTOLOG("references: "<<slots().count(_slot._slot));
|
|
|
|
|
if (slots().count(_slot._slot)==0) {
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_slot.library()->C_OpenSession
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_slot._slot, CKF_SERIAL_SESSION|(rw?CKF_RW_SESSION:0),
|
|
|
|
|
0, 0, &_session),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_OpenSession"));
|
|
|
|
|
} else {
|
|
|
|
|
_session = slots().find(_slot._slot)->second;
|
2009-10-01 19:14:18 +00:00
|
|
|
|
}
|
2013-11-06 12:24:52 +00:00
|
|
|
|
slots().insert(std::make_pair(_slot._slot, _session));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! calls @c C_CloseSession if it's the last session
|
|
|
|
|
void close() {
|
|
|
|
|
CRYPTOLOG("references: "<<slots().count(_slot._slot));
|
|
|
|
|
if (slots().count(_slot._slot)==1) {
|
|
|
|
|
slots().erase(slots().find(_slot._slot));
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_slot.library()->C_CloseSession(_session),
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_CloseSession"));
|
|
|
|
|
} else {
|
|
|
|
|
slots().erase(slots().find(_slot._slot));
|
|
|
|
|
}
|
|
|
|
|
_session=0;
|
2009-10-01 19:14:18 +00:00
|
|
|
|
}
|
2010-09-17 07:44:11 +00:00
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
//! Opens a new session.
|
2014-04-01 13:10:51 +00:00
|
|
|
|
/*! @param slot slot to open a session on
|
|
|
|
|
@param rw whether session is read/write or read only*/
|
2013-11-06 12:24:52 +00:00
|
|
|
|
Session(const Slot& slot, bool rw=false):
|
2013-10-15 11:57:29 +00:00
|
|
|
|
_slot(slot), _session(0), _res(CKR_OK) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
open(rw);
|
|
|
|
|
//! @todo pass parameter
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 13:10:51 +00:00
|
|
|
|
//! Copy session.
|
2013-11-06 12:24:52 +00:00
|
|
|
|
Session(const Session& o):
|
|
|
|
|
_slot(o._slot), _session(o._session), _res(CKR_OK) {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
slots().insert(std::make_pair(_slot._slot, _session));
|
2009-08-28 06:56:23 +00:00
|
|
|
|
//! @todo pass parameter
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-17 07:44:11 +00:00
|
|
|
|
~Session() try {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log "<<(std::uncaught_exception()?"IN EXCEPTION":""));
|
|
|
|
|
try {
|
|
|
|
|
logout();
|
|
|
|
|
} catch (const std::exception& x) {
|
|
|
|
|
CRYPTOLOG("caught: "<<x.what());
|
|
|
|
|
close();
|
|
|
|
|
if (!std::uncaught_exception()) throw;
|
|
|
|
|
} catch (...) {
|
|
|
|
|
CRYPTOLOG("caught");
|
|
|
|
|
close();
|
|
|
|
|
if (!std::uncaught_exception()) throw;
|
|
|
|
|
}
|
|
|
|
|
close();
|
|
|
|
|
} catch (const std::exception& x) {
|
|
|
|
|
CRYPTOLOG("caught: "<<x.what());
|
|
|
|
|
if (!std::uncaught_exception()) throw;
|
2010-09-17 07:44:11 +00:00
|
|
|
|
} catch (...) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("caught");
|
2010-09-17 07:44:11 +00:00
|
|
|
|
if (!std::uncaught_exception()) throw;
|
2009-10-01 19:14:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-01 09:11:11 +00:00
|
|
|
|
/*! @name Comfortable Access
|
|
|
|
|
|
|
|
|
|
Use these methods in favour of the Low Level Cryptoki
|
|
|
|
|
Functions. They provide a higher level simpler access. */
|
|
|
|
|
//@{
|
|
|
|
|
|
2009-09-16 14:52:09 +00:00
|
|
|
|
//! Get a list of matching objects.
|
2009-09-01 09:11:11 +00:00
|
|
|
|
ObjectList find(const AttributeList& attrs=AttributeList());
|
|
|
|
|
|
2009-10-14 13:31:27 +00:00
|
|
|
|
//! Get a list of matching objects.
|
|
|
|
|
ObjectList find(const Attribute& a);
|
|
|
|
|
//! Get a list of matching objects.
|
|
|
|
|
ObjectList find(const Attribute& a1, const Attribute& a2);
|
|
|
|
|
|
2009-09-16 14:52:09 +00:00
|
|
|
|
//! Create a new Certificate Object.
|
2009-09-22 11:21:22 +00:00
|
|
|
|
Object create(const std::string& label, const openssl::X509& cert);
|
2009-09-21 07:43:32 +00:00
|
|
|
|
//! Create a new PrivateKey Object.
|
2009-10-01 19:14:18 +00:00
|
|
|
|
Object create(const std::string& label, const openssl::PrivateKey& key,
|
|
|
|
|
const openssl::X509& cert);
|
2009-09-16 14:52:09 +00:00
|
|
|
|
|
2009-09-01 09:11:11 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
/*! @name C Like Error Handling
|
|
|
|
|
|
|
|
|
|
You are strongly recommended not to disable exception
|
|
|
|
|
handling. If you disable it, you must check after every
|
|
|
|
|
operation whether it was successful or not. These methods
|
|
|
|
|
provide all you need for that. */
|
|
|
|
|
//@{
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @return @c true if last cryptoki on this object call was successful */
|
|
|
|
|
operator bool() {
|
|
|
|
|
return _res==CKR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @return error text of last cryptoki call */
|
|
|
|
|
std::string error() {
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return _slot.library().error(_res);
|
2009-08-28 06:56:23 +00:00
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
/*! @name Low Level Cryptoki Functions
|
|
|
|
|
|
|
|
|
|
Direct access to the low level cryptoki API. Better use the
|
|
|
|
|
comfort methods. */
|
|
|
|
|
//@{
|
2009-09-16 14:52:09 +00:00
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
bool cancel() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_CancelFunction
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_CancelFunction(_session),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_CancelFunction"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-16 14:52:09 +00:00
|
|
|
|
//! Create a new object.
|
|
|
|
|
Object create(const AttributeList& attrs);
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
std::string digest(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-28 06:56:23 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_Digest
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_slot.library()->C_Digest
|
2009-08-28 06:56:23 +00:00
|
|
|
|
(_session,
|
2009-11-24 12:10:25 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
2009-08-28 06:56:23 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_Digest"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string digestencryptupdate(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-28 06:56:23 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_DigestEncryptUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_slot.library()->C_DigestEncryptUpdate
|
2009-08-28 06:56:23 +00:00
|
|
|
|
(_session,
|
2009-11-24 12:10:25 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
2009-08-28 06:56:23 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DigestEncryptUpdate"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool digestfinal() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_DigestFinal
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_DigestFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DigestFinal"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool digestinit() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_DigestInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_DigestInit(_session, CK_MECHANISM_PTR),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DigestInit"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool digestupdate() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_DigestUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_DigestUpdate(_session, CK_BYTE_PTR, CK_ULONG),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DigestUpdate"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool findobjectsfinal() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_FindObjectsFinal
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_FindObjectsFinal(_session),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_FindObjectsFinal"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool findobjectsinit() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_FindObjectsInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_FindObjectsInit(_session, CK_ATTRIBUTE_PTR, CK_ULONG),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_FindObjectsInit"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2009-09-01 09:11:11 +00:00
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool findobjects() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-09-01 09:11:11 +00:00
|
|
|
|
//! calls @c C_FindObjects
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session->_slot.library()->C_FindObjects(_session, CK_OBJECT_HANDLE_PTR, CK_ULONG,
|
2009-09-01 09:11:11 +00:00
|
|
|
|
CK_ULONG_PTR),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_FindObjects"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool generaterandom() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GenerateRandom
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_GenerateRandom(_session, CK_BYTE_PTR, CK_ULONG),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GenerateRandom"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool getfunctionstatus() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GetFunctionStatus
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_GetFunctionStatus(_session),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetFunctionStatus"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool getoperationstate() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GetOperationState
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_GetOperationState(_session, CK_BYTE_PTR, CK_ULONG_PTR),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetOperationState"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
/** definition of session info:
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
@code
|
2013-11-06 12:24:52 +00:00
|
|
|
|
struct CK_SESSION_INFO {
|
|
|
|
|
CK_SLOT_ID slotID;
|
|
|
|
|
CK_STATE state;
|
|
|
|
|
CK_FLAGS flags;
|
|
|
|
|
CK_ULONG ulDeviceError;
|
|
|
|
|
};
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
|
|
where:
|
|
|
|
|
- @c slotID ID of the slot that interfaces with the token
|
|
|
|
|
- @c state The state of the session
|
|
|
|
|
- @c 0 @c CKS_RO_PUBLIC_SESSION
|
|
|
|
|
- @c 1 @c CKS_RO_USER_FUNCTIONS
|
|
|
|
|
- @c 2 @c CKS_RW_PUBLIC_SESSION
|
|
|
|
|
- @c 3 @c CKS_RW_USER_FUNCTIONS
|
|
|
|
|
- @c 4 @c CKS_RW_SO_FUNCTIONS
|
|
|
|
|
- @c flags Bit flags that define the type of session; the
|
|
|
|
|
flags are defined as:
|
|
|
|
|
- @c CKF_RW_SESSION
|
|
|
|
|
- True if the session is read/write.
|
|
|
|
|
- False if the session is read only.
|
|
|
|
|
- @c CKF_SERIAL_SESSION Deprecated, always true.
|
|
|
|
|
- @c ulDeviceError An error code defined by the
|
|
|
|
|
cryptographic device. Used for errors not covered by
|
|
|
|
|
Cryptoki. */
|
2014-01-22 15:14:36 +00:00
|
|
|
|
struct Info: public CK_SESSION_INFO {
|
|
|
|
|
Info(const CK_SESSION_INFO& si): CK_SESSION_INFO(si) {
|
|
|
|
|
}
|
|
|
|
|
bool readonly() {
|
|
|
|
|
return !readwrite();
|
|
|
|
|
}
|
|
|
|
|
bool readwrite() {
|
|
|
|
|
return flags|CKF_RW_SESSION;
|
|
|
|
|
}
|
|
|
|
|
std::string stateString() {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case 0: return "CKS_RO_PUBLIC_SESSION";
|
|
|
|
|
case 1: return "CKS_RO_USER_FUNCTIONS";
|
|
|
|
|
case 2: return "CKS_RW_PUBLIC_SESSION ";
|
|
|
|
|
case 3: return "CKS_RW_USER_FUNCTIONS";
|
|
|
|
|
case 4: return "CKS_RW_SO_FUNCTIONS";
|
|
|
|
|
default: return "<UNKNOWN>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
|
|
|
|
|
/** @return session information */
|
|
|
|
|
Info getsessioninfo() {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
CK_SESSION_INFO info;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GetSessionInfo
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_slot.library()->C_GetSessionInfo(_session, &info),
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetSessionInfo"));
|
|
|
|
|
return info;
|
|
|
|
|
}
|
2014-04-01 13:10:51 +00:00
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool seedrandom() {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
//! calls @c C_SeedRandom
|
|
|
|
|
return check(_slot.library()->C_SeedRandom(_session, CK_BYTE_PTR, CK_ULONG),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_SeedRandom"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool setpin() {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
//! calls @c C_SetPIN
|
|
|
|
|
return check(_slot.library()->C_SetPIN(_session, CK_CHAR_PTR, CK_ULONG, CK_CHAR_PTR, CK_ULONG),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_SetPIN"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
2013-11-06 12:24:52 +00:00
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool initpin() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_InitPIN
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_InitPIN(_session, CK_CHAR_PTR, CK_ULONG),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_InitPIN"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2014-04-01 13:10:51 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
/** @name login with pin
|
|
|
|
|
|
|
|
|
|
Unlock access with pin (login) and unlock after use (logout). */
|
|
|
|
|
//@{
|
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
private:
|
|
|
|
|
|
2009-09-10 12:13:54 +00:00
|
|
|
|
class Login {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
Login(Session& session,
|
2009-09-10 12:13:54 +00:00
|
|
|
|
const std::string& pin,
|
|
|
|
|
CK_USER_TYPE userType=CKU_USER): _session(session) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-09-10 12:13:54 +00:00
|
|
|
|
//! calls @c C_Login
|
2013-11-12 15:06:45 +00:00
|
|
|
|
_session.check(_session._slot.library()->C_Login
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session, userType,
|
2014-04-01 13:10:51 +00:00
|
|
|
|
const_cast<CK_CHAR*>((const CK_CHAR*)pin.c_str()),
|
|
|
|
|
(int)pin.size()),
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_Login"));
|
2009-09-10 12:13:54 +00:00
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-09-10 12:13:54 +00:00
|
|
|
|
~Login() {
|
|
|
|
|
try {
|
|
|
|
|
//! calls @c C_Logout
|
2013-11-12 15:06:45 +00:00
|
|
|
|
_session.check(_session._slot.library()->C_Logout
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session),
|
2009-09-10 12:13:54 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_Logout"));
|
2013-11-06 12:24:52 +00:00
|
|
|
|
} catch (const std::exception& x) {
|
|
|
|
|
if (!std::uncaught_exception()) throw;
|
|
|
|
|
CRYPTOLOG("ERROR during error cleanup: "<<x.what());
|
2009-09-10 12:13:54 +00:00
|
|
|
|
} catch (...) {
|
|
|
|
|
if (!std::uncaught_exception()) throw;
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("ERROR during error cleanup.");
|
2009-09-10 12:13:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2013-11-06 12:24:52 +00:00
|
|
|
|
|
|
|
|
|
Session& _session;
|
2009-09-10 12:13:54 +00:00
|
|
|
|
|
|
|
|
|
};
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2014-04-01 13:10:51 +00:00
|
|
|
|
/// Login to card
|
|
|
|
|
/** @param pin to unlock card
|
|
|
|
|
@param userType user type */
|
|
|
|
|
void login(const std::string& pin,
|
|
|
|
|
CK_USER_TYPE userType=CKU_USER) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2014-04-03 11:21:18 +00:00
|
|
|
|
_login = std::shared_ptr<Login>(new Login(*this, pin, userType));
|
2009-09-10 12:13:54 +00:00
|
|
|
|
}
|
2014-04-01 13:10:51 +00:00
|
|
|
|
|
|
|
|
|
/// Logout from card
|
|
|
|
|
/** Undo the last login. */
|
2009-09-10 12:13:54 +00:00
|
|
|
|
void logout() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
_login.reset();
|
|
|
|
|
}
|
2010-09-17 07:44:11 +00:00
|
|
|
|
|
2014-04-03 11:21:18 +00:00
|
|
|
|
std::shared_ptr<Login> _login;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2014-04-01 13:10:51 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Object {
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
friend class Session;
|
2009-08-28 14:57:40 +00:00
|
|
|
|
|
|
|
|
|
CK_OBJECT_HANDLE _object;
|
2013-11-06 12:24:52 +00:00
|
|
|
|
Session _session;
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_RV _res;
|
|
|
|
|
|
|
|
|
|
bool check(CK_RV result, const std::string& context="") {
|
|
|
|
|
_res = result;
|
2013-11-12 15:06:45 +00:00
|
|
|
|
if (_session._slot.library().exc() && !*this) {
|
2013-11-11 11:49:09 +00:00
|
|
|
|
if (!context.empty()) {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
throw access_error(context+": "+error());
|
2013-11-11 11:49:09 +00:00
|
|
|
|
} else {
|
2009-08-27 14:46:29 +00:00
|
|
|
|
throw access_error(error());
|
2013-11-11 11:49:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
return _res==CKR_OK;
|
|
|
|
|
}
|
2009-08-28 06:56:23 +00:00
|
|
|
|
|
2010-09-17 07:44:11 +00:00
|
|
|
|
Object(); // forbidden
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
|
Object(const Session& session, CK_OBJECT_HANDLE obj):
|
2013-10-15 11:57:29 +00:00
|
|
|
|
_object(obj), _session(session), _res(CKR_OK) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-28 14:57:40 +00:00
|
|
|
|
}
|
2009-08-28 06:56:23 +00:00
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2009-10-21 08:52:04 +00:00
|
|
|
|
/*! @name Comfortable Access
|
|
|
|
|
|
|
|
|
|
Use these methods in favour of the Low Level Cryptoki
|
|
|
|
|
Functions. They provide a higher level simpler access. */
|
|
|
|
|
//@{
|
|
|
|
|
|
2009-11-24 12:10:25 +00:00
|
|
|
|
std::string encrypt(const std::string& data, CK_MECHANISM_TYPE type,
|
|
|
|
|
const std::string& param=std::string()) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
CRYPTOLOG("encryptinit");
|
2009-11-24 12:10:25 +00:00
|
|
|
|
encryptinit(type, param);
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("encrypt");
|
2009-11-24 12:10:25 +00:00
|
|
|
|
return encrypt(data);
|
|
|
|
|
//! @todo don't call encryptfinal()?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string decrypt(const std::string& data, CK_MECHANISM_TYPE type,
|
|
|
|
|
const std::string& param=std::string()) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
CRYPTOLOG("decryptinit");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
decryptinit(type, param);
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("decrypt");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
return decrypt(data);
|
|
|
|
|
//! @todo don't call decryptfinal()?
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-21 06:30:51 +00:00
|
|
|
|
std::string sign(const std::string& data, CK_MECHANISM_TYPE type,
|
|
|
|
|
const std::string& param=std::string()) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
CRYPTOLOG("signinit");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
signinit(type, param);
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("sign");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
return sign(data);
|
|
|
|
|
//! @todo don't call signfinal()?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool verify(const std::string& data, const std::string& signature,
|
|
|
|
|
CK_MECHANISM_TYPE type,
|
|
|
|
|
const std::string& param=std::string()) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
CRYPTOLOG("verifyinit");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
verifyinit(type, param);
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("verify");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
return verify(data, signature);
|
|
|
|
|
//! @todo don't call verifyfinal()?
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 13:10:51 +00:00
|
|
|
|
bool destroy() {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
//! calls @c C_DestroyObject
|
|
|
|
|
return check(_session._slot.library()->C_DestroyObject
|
|
|
|
|
(_session._session, _object),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_DestroyObject"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Get a Single Attribute
|
|
|
|
|
Attribute operator[](CK_ATTRIBUTE_TYPE a) {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
return attribute(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Get a Single Attribute
|
|
|
|
|
Attribute attribute(CK_ATTRIBUTE_TYPE a) {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
Attribute res;
|
2014-04-02 06:31:17 +00:00
|
|
|
|
CK_ATTRIBUTE attr;
|
|
|
|
|
attr.type = a;
|
2014-04-02 06:57:31 +00:00
|
|
|
|
attr.pValue = 0;
|
2014-04-02 06:31:17 +00:00
|
|
|
|
attr.ulValueLen = 0;
|
2014-04-01 13:10:51 +00:00
|
|
|
|
//! calls @c C_GetAttributeValue
|
|
|
|
|
if (!check(_session._slot.library()->C_GetAttributeValue
|
|
|
|
|
(_session._session, _object, &attr, 1),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_GetAttributeValue"))
|
|
|
|
|
|| !(long)attr.ulValueLen>0l)
|
|
|
|
|
//! Without exception handling, size and type must be checked too.
|
|
|
|
|
return res;
|
|
|
|
|
try {
|
|
|
|
|
attr.pValue = malloc(attr.ulValueLen);
|
|
|
|
|
attr.pValue = memset(attr.pValue, 0, attr.ulValueLen);
|
|
|
|
|
if (check(_session._slot.library()->C_GetAttributeValue
|
|
|
|
|
(_session._session, _object, &attr, 1),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_GetAttributeValue")))
|
|
|
|
|
/*! @todo There's no @c CKA_WRAP_TEMPLATE in Open
|
|
|
|
|
Cryptoki. From the Specs: «In the special case
|
|
|
|
|
of an attribute whose value is an array of
|
|
|
|
|
attributes, for example CKA_WRAP_TEMPLATE, where
|
|
|
|
|
it is passed in with pValue not NULL, then if
|
|
|
|
|
the pValue of elements within the array is
|
|
|
|
|
NULL_PTR then the ulValueLen of elements within
|
|
|
|
|
the array will be set to the required length. If
|
|
|
|
|
the pValue of elements within the array is not
|
|
|
|
|
NULL_PTR, then the ulValueLen element of
|
|
|
|
|
attributes within the array must reflect the
|
|
|
|
|
space that the corresponding pValue points to,
|
|
|
|
|
and pValue is filled in if there is sufficient
|
|
|
|
|
room. Therefore it is important to initialize
|
|
|
|
|
the contents of a buffer before calling
|
|
|
|
|
C_GetAttributeValue to get such an array
|
|
|
|
|
value. If any ulValueLen within the array isn't
|
|
|
|
|
large enough, it will be set to -1 and the
|
|
|
|
|
function will return CKR_BUFFER_TOO_SMALL, as it
|
|
|
|
|
does if an attribute in the pTemplate argument
|
|
|
|
|
has ulValueLen too small. Note that any
|
|
|
|
|
attribute whose value is an array of attributes
|
|
|
|
|
is identifiable by virtue of the attribute type
|
|
|
|
|
having the CKF_ARRAY_ATTRIBUTE bit set.» */
|
|
|
|
|
res = Attribute(attr);
|
|
|
|
|
else
|
|
|
|
|
free(attr.pValue);
|
|
|
|
|
} catch (...) {
|
|
|
|
|
free(attr.pValue);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Get a List of Attributes.
|
|
|
|
|
/*! If @c attrs is empty, all available attributes are
|
|
|
|
|
returned. Attributes that cannot be accessed or that are not
|
|
|
|
|
available in this Object won't be in the result map. There
|
|
|
|
|
is no exception in this case. */
|
|
|
|
|
AttributeMap attributes(AttributeTypeList attrs
|
|
|
|
|
= AttributeTypeList()) {
|
|
|
|
|
CRYPTOLOG("log");
|
|
|
|
|
AttributeMap res;
|
|
|
|
|
//! Gets all attributes, if @c attrs is empty
|
|
|
|
|
if (attrs.empty()) {
|
|
|
|
|
attrs.push_back(CKA_CLASS);
|
|
|
|
|
attrs.push_back(CKA_TOKEN);
|
|
|
|
|
attrs.push_back(CKA_PRIVATE);
|
|
|
|
|
attrs.push_back(CKA_LABEL);
|
|
|
|
|
attrs.push_back(CKA_APPLICATION);
|
|
|
|
|
attrs.push_back(CKA_VALUE);
|
|
|
|
|
attrs.push_back(CKA_OBJECT_ID);
|
|
|
|
|
attrs.push_back(CKA_CERTIFICATE_TYPE);
|
|
|
|
|
attrs.push_back(CKA_ISSUER);
|
|
|
|
|
attrs.push_back(CKA_SERIAL_NUMBER);
|
|
|
|
|
attrs.push_back(CKA_AC_ISSUER);
|
|
|
|
|
attrs.push_back(CKA_OWNER);
|
|
|
|
|
attrs.push_back(CKA_ATTR_TYPES);
|
|
|
|
|
attrs.push_back(CKA_TRUSTED);
|
|
|
|
|
attrs.push_back(CKA_KEY_TYPE);
|
|
|
|
|
attrs.push_back(CKA_SUBJECT);
|
|
|
|
|
attrs.push_back(CKA_ID);
|
|
|
|
|
attrs.push_back(CKA_SENSITIVE);
|
|
|
|
|
attrs.push_back(CKA_ENCRYPT);
|
|
|
|
|
attrs.push_back(CKA_DECRYPT);
|
|
|
|
|
attrs.push_back(CKA_WRAP);
|
|
|
|
|
attrs.push_back(CKA_UNWRAP);
|
|
|
|
|
attrs.push_back(CKA_SIGN);
|
|
|
|
|
attrs.push_back(CKA_SIGN_RECOVER);
|
|
|
|
|
attrs.push_back(CKA_VERIFY);
|
|
|
|
|
attrs.push_back(CKA_VERIFY_RECOVER);
|
|
|
|
|
attrs.push_back(CKA_DERIVE);
|
|
|
|
|
attrs.push_back(CKA_START_DATE);
|
|
|
|
|
attrs.push_back(CKA_END_DATE);
|
|
|
|
|
attrs.push_back(CKA_MODULUS);
|
|
|
|
|
attrs.push_back(CKA_MODULUS_BITS);
|
|
|
|
|
attrs.push_back(CKA_PUBLIC_EXPONENT);
|
|
|
|
|
attrs.push_back(CKA_PRIVATE_EXPONENT);
|
|
|
|
|
attrs.push_back(CKA_PRIME_1);
|
|
|
|
|
attrs.push_back(CKA_PRIME_2);
|
|
|
|
|
attrs.push_back(CKA_EXPONENT_1);
|
|
|
|
|
attrs.push_back(CKA_EXPONENT_2);
|
|
|
|
|
attrs.push_back(CKA_COEFFICIENT);
|
|
|
|
|
attrs.push_back(CKA_PRIME);
|
|
|
|
|
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_VALUE_BITS);
|
|
|
|
|
attrs.push_back(CKA_VALUE_LEN);
|
|
|
|
|
attrs.push_back(CKA_EXTRACTABLE);
|
|
|
|
|
attrs.push_back(CKA_LOCAL);
|
|
|
|
|
attrs.push_back(CKA_NEVER_EXTRACTABLE);
|
|
|
|
|
attrs.push_back(CKA_ALWAYS_SENSITIVE);
|
|
|
|
|
attrs.push_back(CKA_KEY_GEN_MECHANISM);
|
|
|
|
|
attrs.push_back(CKA_MODIFIABLE);
|
|
|
|
|
attrs.push_back(CKA_ECDSA_PARAMS);
|
|
|
|
|
attrs.push_back(CKA_EC_PARAMS);
|
|
|
|
|
attrs.push_back(CKA_EC_POINT);
|
|
|
|
|
attrs.push_back(CKA_SECONDARY_AUTH);
|
|
|
|
|
attrs.push_back(CKA_AUTH_PIN_FLAGS);
|
|
|
|
|
attrs.push_back(CKA_HW_FEATURE_TYPE);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
for (AttributeTypeList::const_iterator it(attrs.begin());
|
|
|
|
|
it!=attrs.end(); ++it) {
|
2014-04-02 06:31:17 +00:00
|
|
|
|
CK_ATTRIBUTE attr;
|
|
|
|
|
attr.type = *it;
|
2014-04-02 06:57:31 +00:00
|
|
|
|
attr.pValue = 0;
|
2014-04-02 06:31:17 +00:00
|
|
|
|
attr.ulValueLen = 0;
|
2014-04-01 13:10:51 +00:00
|
|
|
|
try {
|
|
|
|
|
//! calls @c C_GetAttributeValue
|
|
|
|
|
if (_session._slot.library()->C_GetAttributeValue
|
|
|
|
|
(_session._session, _object, &attr, 1)
|
|
|
|
|
== CKR_ATTRIBUTE_TYPE_INVALID
|
|
|
|
|
|| _res == CKR_ATTRIBUTE_SENSITIVE) {
|
|
|
|
|
continue; //! Ignores unsupported Attributes.
|
|
|
|
|
} else {
|
|
|
|
|
check(_res, CRYPTOKI_FN_LOG("C_GetAttributeValue"));
|
|
|
|
|
if ((long)attr.ulValueLen>0l) {
|
|
|
|
|
attr.pValue = malloc(attr.ulValueLen);
|
|
|
|
|
attr.pValue = memset(attr.pValue, 0, attr.ulValueLen);
|
|
|
|
|
if (check(_session._slot.library()->C_GetAttributeValue
|
|
|
|
|
(_session._session, _object, &attr, 1),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_GetAttributeValue")))
|
|
|
|
|
/*! @todo There's no @c CKA_WRAP_TEMPLATE in Open
|
|
|
|
|
Cryptoki. From the Specs: «In the special
|
|
|
|
|
case of an attribute whose value is an
|
|
|
|
|
array of attributes, for example
|
|
|
|
|
CKA_WRAP_TEMPLATE, where it is passed in
|
|
|
|
|
with pValue not NULL, then if the pValue
|
|
|
|
|
of elements within the array is NULL_PTR
|
|
|
|
|
then the ulValueLen of elements within the
|
|
|
|
|
array will be set to the required
|
|
|
|
|
length. If the pValue of elements within
|
|
|
|
|
the array is not NULL_PTR, then the
|
|
|
|
|
ulValueLen element of attributes within
|
|
|
|
|
the array must reflect the space that the
|
|
|
|
|
corresponding pValue points to, and pValue
|
|
|
|
|
is filled in if there is sufficient
|
|
|
|
|
room. Therefore it is important to
|
|
|
|
|
initialize the contents of a buffer before
|
|
|
|
|
calling C_GetAttributeValue to get such an
|
|
|
|
|
array value. If any ulValueLen within the
|
|
|
|
|
array isn't large enough, it will be set
|
|
|
|
|
to -1 and the function will return
|
|
|
|
|
CKR_BUFFER_TOO_SMALL, as it does if an
|
|
|
|
|
attribute in the pTemplate argument has
|
|
|
|
|
ulValueLen too small. Note that any
|
|
|
|
|
attribute whose value is an array of
|
|
|
|
|
attributes is identifiable by virtue of
|
|
|
|
|
the attribute type having the
|
|
|
|
|
CKF_ARRAY_ATTRIBUTE bit set.» */
|
|
|
|
|
res.insert(std::make_pair(attr.type, Attribute(attr)));
|
|
|
|
|
else
|
|
|
|
|
free(attr.pValue);
|
|
|
|
|
} else if (*it==CKA_MODULUS && attr.ulValueLen==0) {
|
|
|
|
|
/*! @bug This is a bug in opensc-pkcs11.so: If
|
|
|
|
|
@c CKA_MODULUS has a size of 0 bytes, the
|
|
|
|
|
following query to @c CKA_MODULUS_BITS ends
|
|
|
|
|
in a segmentation fault.
|
|
|
|
|
|
|
|
|
|
@note @c CKA_MODULUS @b must immediately be
|
|
|
|
|
followed by @c CKA_MODULUS_BITS in the
|
|
|
|
|
attribute list, because if the size of @c
|
|
|
|
|
CKA_MODULUS is 0 Bytes, the following
|
|
|
|
|
attribute query is skipped as a work around
|
|
|
|
|
to this bug. */
|
|
|
|
|
if (++it==attrs.end()) break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (...) {
|
|
|
|
|
free(attr.pValue);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
/*! @name C Like Error Handling
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-08-28 06:56:23 +00:00
|
|
|
|
You are strongly recommended not to disable exception
|
|
|
|
|
handling. If you disable it, you must check after every
|
|
|
|
|
operation whether it was successful or not. These methods
|
|
|
|
|
provide all you need for that. */
|
|
|
|
|
//@{
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @return @c true if last cryptoki on this object call was successful */
|
|
|
|
|
operator bool() {
|
|
|
|
|
return _res==CKR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @return error text of last cryptoki call */
|
|
|
|
|
std::string error() {
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return _session._slot.library().error(_res);
|
2009-08-27 14:46:29 +00:00
|
|
|
|
}
|
2009-08-28 06:56:23 +00:00
|
|
|
|
|
|
|
|
|
//@}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2009-08-28 14:57:40 +00:00
|
|
|
|
/*! @name Low Level Cryptoki Functions
|
|
|
|
|
|
|
|
|
|
Direct access to the low level cryptoki API. Better use the
|
|
|
|
|
comfort methods. */
|
|
|
|
|
//@{
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool copyobject() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_CopyObject
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_CopyObject(_session._session, CK_OBJECT_HANDLE,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_CopyObject"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
2009-10-21 08:52:04 +00:00
|
|
|
|
|
2009-09-29 07:24:04 +00:00
|
|
|
|
bool decryptinit(CK_MECHANISM_TYPE type, std::string param) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-28 14:57:40 +00:00
|
|
|
|
CK_MECHANISM mech = {
|
2014-04-29 08:31:51 +00:00
|
|
|
|
type, param.size()?¶m[0]:0, (CK_ULONG)param.size()
|
2009-08-28 14:57:40 +00:00
|
|
|
|
};
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("decryptinit: type="<<type<<"; mech=("<<mech.mechanism
|
2009-10-21 08:52:04 +00:00
|
|
|
|
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_DecryptInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_DecryptInit
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session, &mech, _object),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DecryptInit"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//! requires decryptinit to be called before
|
2009-11-24 12:10:25 +00:00
|
|
|
|
std::string decrypt(const std::string& in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
CK_ULONG size(0); // two calls, first to get minimum buffer length
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("get size");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//! calls @c C_Decrypt
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_Decrypt
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2014-04-01 13:10:51 +00:00
|
|
|
|
const_cast<CK_BYTE_PTR>((const unsigned char*)&in[0]),
|
|
|
|
|
in.size(), 0, &size),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_Decrypt"));
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("maximum size is "<<size<<"Bytes");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
res.resize(size, 0);
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_Decrypt
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2014-04-01 13:10:51 +00:00
|
|
|
|
const_cast<CK_BYTE_PTR>((const unsigned char*)&in[0]),
|
|
|
|
|
in.size(),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
(unsigned char*)&res[0], &size),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_Decrypt"));
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("exact size is "<<size<<"Bytes");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string decryptdigestupdate(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
|
|
|
|
//! calls @c C_DecryptDigestUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_DecryptDigestUpdate
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2014-04-01 13:10:51 +00:00
|
|
|
|
const_cast<CK_BYTE_PTR>((const unsigned char*)&in[0]), in.size(),
|
2009-11-24 12:10:25 +00:00
|
|
|
|
(unsigned char*)&res[0], &size),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DecryptDigestUpdate"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool decryptfinal() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//! calls @c C_DecryptFinal
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_DecryptFinal
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session, 0, 0),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DecryptFinal"));
|
|
|
|
|
//! @todo does this work?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string decryptupdate(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
|
|
|
|
//! calls @c C_DecryptUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_DecryptUpdate
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2009-11-24 12:10:25 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DecryptUpdate"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string decryptverifyupdate(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
|
|
|
|
//! calls @c C_DecryptVerifyUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_DecryptVerifyUpdate
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2009-11-24 12:10:25 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DecryptVerifyUpdate"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
2011-04-21 06:30:51 +00:00
|
|
|
|
|
|
|
|
|
std::string sign(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
CK_ULONG size(0);
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_Sign
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2011-04-21 06:30:51 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),0, &size),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_Sign"));
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("maximum size is "<<size<<"Bytes");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
res.resize(size, 0);
|
|
|
|
|
//! calls @c C_Sign
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_Sign
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2011-04-21 06:30:51 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_Sign"));
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("exact size is "<<size<<"Bytes");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string signencryptupdate(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
|
|
|
|
//! calls @c C_SignEncryptUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_SignEncryptUpdate
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2011-04-21 06:30:51 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_SignEncryptUpdate"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool signfinal() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
//! calls @c C_SignFinal
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_slot.library()->C_SignFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR),
|
2011-04-21 06:30:51 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_SignFinal"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
std::string signrecover(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
|
|
|
|
//! calls @c C_SignRecover
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_SignRecover
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2011-04-21 06:30:51 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_SignRecover"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool signupdate() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
//! calls @c C_SignUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_SignUpdate(_session._session, CK_BYTE_PTR, CK_ULONG),
|
2011-04-21 06:30:51 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_SignUpdate"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
bool verify(std::string data, std::string signature) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
//! calls @c C_Verify
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_Verify
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2011-04-21 06:30:51 +00:00
|
|
|
|
(unsigned char*)&data[0], data.size(),
|
|
|
|
|
(unsigned char*)&signature[0], signature.size()),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_Verify"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool verifyfinal() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
//! calls @c C_VerifyFinal
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_VerifyFinal(_session._session, CK_BYTE_PTR, CK_ULONG),
|
2011-04-21 06:30:51 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_VerifyFinal"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
std::string verifyrecover(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
|
|
|
|
//! calls @c C_VerifyRecover
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_VerifyRecover
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2011-04-21 06:30:51 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_VerifyRecover"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool verifyupdate() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
//! calls @c C_VerifyUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_VerifyUpdate(_session._session, CK_BYTE_PTR, CK_ULONG),
|
2011-04-21 06:30:51 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_VerifyUpdate"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool derivekey() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_DeriveKey
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_DeriveKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_DeriveKey"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool digestkey() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_DigestKey
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_DigestKey(_session._session, CK_OBJECT_HANDLE),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_DigestKey"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2009-11-24 12:10:25 +00:00
|
|
|
|
bool encryptinit(CK_MECHANISM_TYPE type, const std::string& param) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-11-24 12:10:25 +00:00
|
|
|
|
CK_MECHANISM mech = {
|
2014-04-01 13:10:51 +00:00
|
|
|
|
type, param.size()?const_cast<CK_VOID_PTR>((const void*)¶m[0]):0,
|
2014-04-29 08:31:51 +00:00
|
|
|
|
(CK_ULONG)param.size()
|
2009-11-24 12:10:25 +00:00
|
|
|
|
};
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("encryptinit: type="<<type<<"; mech=("<<mech.mechanism
|
2009-11-24 12:10:25 +00:00
|
|
|
|
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_EncryptInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_EncryptInit
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session, &mech, _object),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_EncryptInit"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-24 12:10:25 +00:00
|
|
|
|
std::string encrypt(const std::string& in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
std::string res;
|
2009-11-24 12:10:25 +00:00
|
|
|
|
CK_ULONG size(0); // two calls, first to get minimum buffer length
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("get size");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//! calls @c C_Encrypt
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_Encrypt
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2014-04-01 13:10:51 +00:00
|
|
|
|
const_cast<CK_BYTE_PTR>((const unsigned char*)&in[0]),
|
|
|
|
|
in.size(), 0, &size),
|
2009-11-24 12:10:25 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_Decrypt"));
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("maximum size is "<<size<<"Bytes");
|
2009-11-24 12:10:25 +00:00
|
|
|
|
res.resize(size, 0);
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_Encrypt
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2014-04-01 13:10:51 +00:00
|
|
|
|
const_cast<CK_BYTE_PTR>((const unsigned char*)&in[0]), in.size(),
|
2009-11-24 12:10:25 +00:00
|
|
|
|
(unsigned char*)&res[0], &size),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_Encrypt"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool encryptfinal() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//! calls @c C_EncryptFinal
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_EncryptFinal(_session._session, CK_BYTE_PTR, CK_ULONG_PTR),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_EncryptFinal"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
std::string encryptupdate(std::string in) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
std::string res;
|
|
|
|
|
res.resize(in.size());
|
|
|
|
|
CK_ULONG size(res.size()); //! @todo check if size is ok
|
|
|
|
|
//! calls @c C_EncryptUpdate
|
2013-11-12 15:06:45 +00:00
|
|
|
|
check(_session._slot.library()->C_EncryptUpdate
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session,
|
2009-11-24 12:10:25 +00:00
|
|
|
|
(unsigned char*)&in[0], in.size(),
|
|
|
|
|
(unsigned char*)&res[0], &size),
|
2009-10-21 08:52:04 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_EncryptUpdate"));
|
|
|
|
|
res.resize(size);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool generatekey() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GenerateKey
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_GenerateKey(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_ULONG, CK_OBJECT_HANDLE_PTR),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_GenerateKey"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool generatekeypair() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GenerateKeyPair
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_GenerateKeyPair(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
|
|
|
|
|
CK_OBJECT_HANDLE_PTR, CK_OBJECT_HANDLE_PTR),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_GenerateKeyPair"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool getobjectsize() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_GetObjectSize
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_GetObjectSize(_session._session, CK_OBJECT_HANDLE, CK_ULONG_PTR),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_GetObjectSize"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool setattributevalue() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_SetAttributeValue
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_SetAttributeValue(_session._session, CK_OBJECT_HANDLE,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_ATTRIBUTE_PTR, CK_ULONG),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_SetAttributeValue"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool setoperationstate() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_SetOperationState
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_SetOperationState(_session._session, CK_BYTE_PTR, CK_ULONG,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_OBJECT_HANDLE, CK_OBJECT_HANDLE),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_SetOperationState"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2011-04-21 06:30:51 +00:00
|
|
|
|
bool signinit(CK_MECHANISM_TYPE type, std::string param) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
CK_MECHANISM mech = {
|
2014-04-29 08:31:51 +00:00
|
|
|
|
type, param.size()?¶m[0]:0, (CK_ULONG)param.size()
|
2011-04-21 06:30:51 +00:00
|
|
|
|
};
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("signinit: type="<<type<<"; mech=("<<mech.mechanism
|
2011-04-21 06:30:51 +00:00
|
|
|
|
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_SignInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_SignInit
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session, &mech, _object),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_SignInit"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool signrecoverinit() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_SignRecoverInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_SignRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_SignRecoverInit"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool unwrapkey() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_UnwrapKey
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_UnwrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_BYTE_PTR, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
|
|
|
|
|
CK_OBJECT_HANDLE_PTR),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_UnwrapKey"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2011-04-21 06:30:51 +00:00
|
|
|
|
bool verifyinit(CK_MECHANISM_TYPE type, std::string param) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2011-04-21 06:30:51 +00:00
|
|
|
|
CK_MECHANISM mech = {
|
2014-04-29 08:31:51 +00:00
|
|
|
|
type, param.size()?¶m[0]:0, (CK_ULONG)param.size()
|
2011-04-21 06:30:51 +00:00
|
|
|
|
};
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("verifyinit: type="<<type<<"; mech=("<<mech.mechanism
|
2011-04-21 06:30:51 +00:00
|
|
|
|
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
|
|
|
|
|
//! calls @c C_VerifyInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_VerifyInit
|
2013-11-06 12:24:52 +00:00
|
|
|
|
(_session._session, &mech, _object),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_VerifyInit"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool verifyrecoverinit() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_VerifyRecoverInit
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_VerifyRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CRYPTOKI_FN_LOG("C_VerifyRecoverInit"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code
|
|
|
|
|
bool wrapkey() {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-08-27 14:46:29 +00:00
|
|
|
|
//! calls @c C_WrapKey
|
2013-11-12 15:06:45 +00:00
|
|
|
|
return check(_session._slot.library()->C_WrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
|
2009-08-27 14:46:29 +00:00
|
|
|
|
CK_OBJECT_HANDLE, CK_BYTE_PTR, CK_ULONG_PTR),
|
|
|
|
|
CRYPTOKI_FN_LOG("C_WrapKey"));
|
|
|
|
|
}
|
|
|
|
|
@endcode */
|
|
|
|
|
|
2009-08-28 14:57:40 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
|
};
|
2009-09-18 11:41:30 +00:00
|
|
|
|
//@}
|
2009-08-27 14:46:29 +00:00
|
|
|
|
|
|
|
|
|
}
|
2009-10-21 08:52:04 +00:00
|
|
|
|
|
2014-04-01 13:10:51 +00:00
|
|
|
|
//! @addtogroup cryptokitypes
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//@{
|
2014-04-01 13:10:51 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Append a cryptoki::Attribute to a cryptoki::AttributeList.
|
2009-10-21 08:52:04 +00:00
|
|
|
|
inline cryptoki::AttributeList& operator<<(cryptoki::AttributeList& list,
|
|
|
|
|
const cryptoki::Attribute& attr) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
list.push_back(attr);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2014-04-01 13:10:51 +00:00
|
|
|
|
|
2014-02-27 12:57:44 +00:00
|
|
|
|
/// Append a cryptoki::Attribute to a new copy of a cryptoki::AttributeList.
|
2009-10-21 08:52:04 +00:00
|
|
|
|
inline cryptoki::AttributeList operator<<(const cryptoki::AttributeList& list,
|
|
|
|
|
const cryptoki::Attribute& attr) {
|
2013-11-06 12:24:52 +00:00
|
|
|
|
CRYPTOLOG("log");
|
2009-10-21 08:52:04 +00:00
|
|
|
|
cryptoki::AttributeList res(list);
|
|
|
|
|
res.push_back(attr);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2014-04-01 13:10:51 +00:00
|
|
|
|
|
2009-10-21 08:52:04 +00:00
|
|
|
|
//@}
|
|
|
|
|
|
2009-09-16 14:52:09 +00:00
|
|
|
|
#endif
|