00001 #ifndef TOKEN_H
00002 #define TOKEN_H
00003
00004 #include "Mechanism.h"
00005 #include "common.h"
00006 #include "Session.h"
00007 #include "Pkcs11Exception.h"
00008 #include "EsiPkcs11Module.h"
00009 #include "time.h"
00010 #include "PivMechanism.h"
00011 #include "Slot.h"
00012 #include "CryptoObject.h"
00013 #include "PivObject.h"
00014 #include "X509ForCardAuth.h"
00015 #include "X509ForPivAuth.h"
00016 #include "X509Certificate.h"
00017 #include "X509ForDigitalSig.h"
00018 #include "X509ForKeyMan.h"
00019 #include "PivRsaPkcsMechanism.h"
00020
00021 class Session;
00022 class Slot;
00023
00024
00029 class Token
00030 {
00031 public:
00032
00039 CK_RV getInfo (CK_TOKEN_INFO_PTR infoOut);
00040
00044 string getManufacturer(void);
00045 string getModel (void);
00046 string getSerialNum(void);
00047 CK_FLAGS getFlags (void);
00048 CK_ULONG getMaxRWSessions (void);
00049 CK_ULONG getRWSessionCount (void);
00050 CK_ULONG getPinMaxLength (void);
00051 CK_ULONG getPinMinLength (void);
00052 CK_ULONG getTotalPubMemory (void);
00053 CK_ULONG getTotalFreePubMemory (void);
00054 CK_ULONG getTotalPrivMemory (void);
00055 CK_ULONG getTotalFreePrivMemory (void);
00056 CK_VERSION getHardwareVersion (void);
00057 CK_VERSION getFirmwareVersion (void);
00058 CK_CHAR *getUtc(void);
00059
00064 size_t getMechanismCount();
00065
00070 list<Mechanism*> getMechanisms();
00076 list<CryptoObject*> findObjects(Session* session,CK_ATTRIBUTE_PTR attributes,CK_ULONG ulCount);
00083 Session* openSession(CK_FLAGS flags, CK_VOID_PTR data, CK_NOTIFY notifyFunc);
00088 void closeSession(Session* session);
00093 list<Session*> getSessions();
00099 Mechanism* getMechanism(CK_MECHANISM_TYPE type);
00105 Session* getSession(CK_SESSION_HANDLE handle);
00111 CryptoObject* getCryptoObject(CK_OBJECT_HANDLE handle);
00117 CryptoObject* addCryptoObject(CryptoObject* obj);
00118
00128 CK_RV sign(Session* sess,CK_BYTE* in,CK_ULONG inLen,CK_BYTE* out,CK_ULONG* outLen);
00138 CK_RV decrypt(Session* sess,CK_BYTE* in,CK_ULONG inLen,CK_BYTE* out,CK_ULONG* outLen);
00139
00144 Token(Slot* slot);
00148 ~Token(void);
00149
00150 private:
00151
00156 void loadObjects(Session* session);
00162 Session* addSession(Session* sess);
00163 bool validate(unsigned char* original, int inLen, unsigned char* data) ;
00164
00165
00166 PivMechanism* addMechanism(PivMechanism* mech);
00167
00168
00169 void* reverseBytes(unsigned char* in,int end);
00170
00174 map<CK_SESSION_HANDLE,Session*> sessions;
00178 map<CK_MECHANISM_TYPE,PivMechanism*> mechMap;
00182 map<CK_OBJECT_HANDLE,CryptoObject*> objects;
00186 Slot* slot;
00187
00191 unsigned char connectCmd[512];
00196 CK_TOKEN_INFO info;
00200 static bool initialized;
00201
00202 };
00203 #endif
00204