Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.DSI.Pkcs11

Feature notes: PKIX / CMS implementation notes

Classes, interfaces and records

recordCK_VERSION

major: CK_BYTE; minor: CK_BYTE;

recordCK_INFO

cryptokiVersion : CK_VERSION; manufacturerID : array [0..31] of CK_UTF8CHAR; flags : CK_FLAGS; libraryDescription: array [0..31] of CK_UTF8CHAR; libraryVersion : CK_VERSION;

recordCK_SLOT_INFO

slotDescription: array [0..63] of CK_UTF8CHAR; manufacturerID : array [0..31] of CK_UTF8CHAR; flags : CK_FLAGS; hardwareVersion: CK_VERSION; firmwareVersion: CK_VERSION;

recordCK_TOKEN_INFO

'label' is a reserved word in Delphi, hence tokenLabel for the C "label".

tokenLabel : array [0..31] of CK_UTF8CHAR; manufacturerID : array [0..31] of CK_UTF8CHAR; model : array [0..15] of CK_UTF8CHAR; serialNumber : array [0..15] of CK_CHAR; flags : CK_FLAGS; ulMaxSessionCount : CK_ULONG; ulSessionCount : CK_ULONG; ulMaxRwSessionCount : CK_ULONG; ulRwSessionCount : CK_ULONG; ulMaxPinLen : CK_ULONG; ulMinPinLen : CK_ULONG; ulTotalPublicMemory : CK_ULONG; ulFreePublicMemory : CK_ULONG; ulTotalPrivateMemory: CK_ULONG; ulFreePrivateMemory : CK_ULONG; hardwareVersion : CK_VERSION; firmwareVersion : CK_VERSION; utcTime : array [0..15] of CK_CHAR;

recordCK_MECHANISM_INFO

ulMinKeySize: CK_ULONG; ulMaxKeySize: CK_ULONG; flags : CK_FLAGS;

recordCK_ATTRIBUTE

_type : CK_ATTRIBUTE_TYPE; pValue : Pointer; ulValueLen: CK_ULONG;

recordCK_MECHANISM

mechanism : CK_MECHANISM_TYPE; pParameter : Pointer; ulParameterLen: CK_ULONG;

recordCK_SESSION_INFO

slotID : CK_SLOT_ID; state : CK_STATE; flags : CK_FLAGS; ulDeviceError: CK_ULONG;

recordCK_C_INITIALIZE_ARGS

CreateMutex : Pointer; DestroyMutex: Pointer; LockMutex : Pointer; UnlockMutex : Pointer; flags : CK_FLAGS; pReserved : Pointer;

recordCK_RSA_PKCS_PSS_PARAMS

hashAlg: CK_MECHANISM_TYPE; mgf : CK_ULONG; sLen : CK_ULONG;

recordCK_RSA_PKCS_OAEP_PARAMS

hashAlg : CK_MECHANISM_TYPE; mgf : CK_ULONG; source : CK_ULONG; pSourceData : Pointer; ulSourceDataLen: CK_ULONG;

recordCK_FUNCTION_LIST

The full v2.40 function list, in wire order. Entries the library does not need yet are declared as Pointer so the offsets of the ones it does need stay correct; the C name is kept in a comment against each so promoting one to a typed field later is a local edit.

version : CK_VERSION; C_Initialize : CK_C_Initialize; C_Finalize : CK_C_Finalize; C_GetInfo : CK_C_GetInfo; C_GetFunctionList : CK_C_GetFunctionList; C_GetSlotList : CK_C_GetSlotList; C_GetSlotInfo : CK_C_GetSlotInfo; C_GetTokenInfo : CK_C_GetTokenInfo; C_GetMechanismList : CK_C_GetMechanismList; C_GetMechanismInfo : CK_C_GetMechanismInfo; C_InitToken : Pointer; C_InitPIN : Pointer; C_SetPIN : Pointer; C_OpenSession : CK_C_OpenSession; C_CloseSession : CK_C_CloseSession; C_CloseAllSessions : Pointer; C_GetSessionInfo : Pointer; C_GetOperationState : Pointer; C_SetOperationState : Pointer; C_Login : CK_C_Login; C_Logout : CK_C_Logout; C_CreateObject : CK_C_CreateObject; C_CopyObject : Pointer; C_DestroyObject : CK_C_DestroyObject; C_GetObjectSize : Pointer; C_GetAttributeValue : CK_C_GetAttributeValue; C_SetAttributeValue : Pointer; C_FindObjectsInit : CK_C_FindObjectsInit; C_FindObjects : CK_C_FindObjects; C_FindObjectsFinal : CK_C_FindObjectsFinal; C_EncryptInit : Pointer; C_Encrypt : Pointer; C_EncryptUpdate : Pointer; C_EncryptFinal : Pointer; C_DecryptInit : CK_C_DecryptInit; C_Decrypt : CK_C_Decrypt; C_DecryptUpdate : Pointer; C_DecryptFinal : Pointer; C_DigestInit : Pointer; C_Digest : Pointer; C_DigestUpdate : Pointer; C_DigestKey : Pointer; C_DigestFinal : Pointer; C_SignInit : CK_C_SignInit; C_Sign : CK_C_Sign; C_SignUpdate : Pointer; C_SignFinal : Pointer; C_SignRecoverInit : Pointer; C_SignRecover : Pointer; C_VerifyInit : Pointer; C_Verify : Pointer; C_VerifyUpdate : Pointer; C_VerifyFinal : Pointer; C_VerifyRecoverInit : Pointer; C_VerifyRecover : Pointer; C_DigestEncryptUpdate : Pointer; C_DecryptDigestUpdate : Pointer; C_SignEncryptUpdate : Pointer; C_DecryptVerifyUpdate : Pointer; C_GenerateKey : Pointer; C_GenerateKeyPair : CK_C_GenerateKeyPair; C_WrapKey : Pointer; C_UnwrapKey : Pointer; C_DeriveKey : Pointer; C_SeedRandom : Pointer; C_GenerateRandom : CK_C_GenerateRandom; C_GetFunctionStatus : Pointer; C_CancelFunction : Pointer; C_WaitForSlotEvent : Pointer;

classePkcs11Error

inherits from Exception

(no public members)

classtPkcs11Library

Loads a Cryptoki module and resolves its function list. Owns neither the session nor the login state: this class is the transport, and everything above it (key adapter, key storage) is built on FuncList.

Deliberately NOT a TComponent -- a design-time surface belongs on the key storage that consumes this, not on the raw module handle.

constructor Create; destructor Destroy; override; procedure Load(const aModulePath: string);
Loads aModulePath and resolves C_GetFunctionList. Raises ePkcs11Error when the module cannot be loaded or does not export the entry point.
function Initialize: CK_RV;
Calls C_Initialize, first requesting OS locking; if the module answers CKR_CANT_LOCK it retries single-threaded. Check OSLocking afterwards -- a module that refuses OS locking must not be driven from a reactor thread pool without external serialisation.
procedure Unload; property FuncList: pCK_FUNCTION_LIST read fFuncList; property ModulePath: string read fModulePath; property OSLocking: Boolean read fOSLocking;

Types (enumerations, sets, aliases)

typeCK_ULONG

  CK_ULONG = UInt32;

typeCK_LONG

  CK_LONG  = Int32;

typeCK_ULONG

  CK_ULONG = UInt64;

typeCK_LONG

  CK_LONG  = Int64;

typeCK_ULONG

  CK_ULONG = UInt32;

typeCK_LONG

  CK_LONG  = Int32;

typepCK_ULONG

  pCK_ULONG = ^CK_ULONG;

typeCK_BYTE

  CK_BYTE     = Byte;

typeCK_CHAR

  CK_CHAR     = AnsiChar;

typeCK_UTF8CHAR

  CK_UTF8CHAR = AnsiChar;

typeCK_BBOOL

  CK_BBOOL    = Byte;

typepCK_BYTE

  pCK_BYTE    = ^CK_BYTE;

typeCK_FLAGS

  CK_FLAGS            = CK_ULONG;

typeCK_RV

  CK_RV               = CK_ULONG;

typeCK_SLOT_ID

  CK_SLOT_ID          = CK_ULONG;

typeCK_SESSION_HANDLE

  CK_SESSION_HANDLE   = CK_ULONG;

typeCK_OBJECT_HANDLE

  CK_OBJECT_HANDLE    = CK_ULONG;

typeCK_OBJECT_CLASS

  CK_OBJECT_CLASS     = CK_ULONG;

typeCK_KEY_TYPE

  CK_KEY_TYPE         = CK_ULONG;

typeCK_CERTIFICATE_TYPE

  CK_CERTIFICATE_TYPE = CK_ULONG;

typeCK_ATTRIBUTE_TYPE

  CK_ATTRIBUTE_TYPE   = CK_ULONG;

typeCK_MECHANISM_TYPE

  CK_MECHANISM_TYPE   = CK_ULONG;

typeCK_USER_TYPE

  CK_USER_TYPE        = CK_ULONG;

typeCK_STATE

  CK_STATE            = CK_ULONG;

typeCK_NOTIFICATION

  CK_NOTIFICATION     = CK_ULONG;

typepCK_SLOT_ID

  pCK_SLOT_ID        = ^CK_SLOT_ID;

typepCK_MECHANISM_TYPE

  pCK_MECHANISM_TYPE = ^CK_MECHANISM_TYPE;

typepCK_OBJECT_HANDLE

  pCK_OBJECT_HANDLE  = ^CK_OBJECT_HANDLE;

arraytCK_SlotIDArray

  tCK_SlotIDArray        = array of CK_SLOT_ID;

arraytCK_MechanismTypeArray

  tCK_MechanismTypeArray = array of CK_MECHANISM_TYPE;

arraytCK_ObjectHandleArray

  tCK_ObjectHandleArray  = array of CK_OBJECT_HANDLE;

typepCK_ATTRIBUTE

  pCK_ATTRIBUTE = ^CK_ATTRIBUTE;

arraytCK_AttributeArray

  tCK_AttributeArray = array of CK_ATTRIBUTE;

typepCK_MECHANISM

  pCK_MECHANISM = ^CK_MECHANISM;

typepCK_FUNCTION_LIST

  pCK_FUNCTION_LIST = ^CK_FUNCTION_LIST;

procCK_NOTIFY

  CK_NOTIFY = function (hSession    : CK_SESSION_HANDLE;
                        event       : CK_NOTIFICATION;
                        pApplication: Pointer): CK_RV; cdecl;

procCK_C_Initialize

  CK_C_Initialize = function (pInitArgs: Pointer): CK_RV; cdecl;

procCK_C_Finalize

  CK_C_Finalize   = function (pReserved: Pointer): CK_RV; cdecl;

procCK_C_GetInfo

  CK_C_GetInfo    = function (var aInfo: CK_INFO): CK_RV; cdecl;

procCK_C_GetFunctionList

  CK_C_GetFunctionList = function (out aFunctionList: pCK_FUNCTION_LIST): CK_RV; cdecl;

procCK_C_GetSlotList

  CK_C_GetSlotList = function (aTokenPresent: CK_BBOOL;
                               aSlotList    : pCK_SLOT_ID;
                               var aCount   : CK_ULONG): CK_RV; cdecl;

procCK_C_GetSlotInfo

  CK_C_GetSlotInfo  = function (aSlotID: CK_SLOT_ID;
                                var aInfo: CK_SLOT_INFO): CK_RV; cdecl;

procCK_C_GetTokenInfo

  CK_C_GetTokenInfo = function (aSlotID: CK_SLOT_ID;
                                var aInfo: CK_TOKEN_INFO): CK_RV; cdecl;

procCK_C_GetMechanismList

  CK_C_GetMechanismList = function (aSlotID       : CK_SLOT_ID;
                                    aMechanismList: pCK_MECHANISM_TYPE;
                                    var aCount    : CK_ULONG): CK_RV; cdecl;

procCK_C_GetMechanismInfo

  CK_C_GetMechanismInfo = function (aSlotID   : CK_SLOT_ID;
                                    aType     : CK_MECHANISM_TYPE;
                                    var aInfo : CK_MECHANISM_INFO): CK_RV; cdecl;

procCK_C_OpenSession

  CK_C_OpenSession = function (aSlotID      : CK_SLOT_ID;
                               aFlags       : CK_FLAGS;
                               aApplication : Pointer;
                               aNotify      : CK_NOTIFY;
                               var aSession : CK_SESSION_HANDLE): CK_RV; cdecl;

procCK_C_CloseSession

  CK_C_CloseSession = function (aSession: CK_SESSION_HANDLE): CK_RV; cdecl;

procCK_C_Login

  CK_C_Login  = function (aSession : CK_SESSION_HANDLE;
                          aUserType: CK_USER_TYPE;
                          aPin     : pCK_BYTE;
                          aPinLen  : CK_ULONG): CK_RV; cdecl;

procCK_C_Logout

  CK_C_Logout = function (aSession: CK_SESSION_HANDLE): CK_RV; cdecl;

procCK_C_GetAttributeValue

  CK_C_GetAttributeValue = function (aSession : CK_SESSION_HANDLE;
                                     aObject  : CK_OBJECT_HANDLE;
                                     aTemplate: pCK_ATTRIBUTE;
                                     aCount   : CK_ULONG): CK_RV; cdecl;

procCK_C_FindObjectsInit

  CK_C_FindObjectsInit = function (aSession : CK_SESSION_HANDLE;
                                   aTemplate: pCK_ATTRIBUTE;
                                   aCount   : CK_ULONG): CK_RV; cdecl;

procCK_C_FindObjects

  CK_C_FindObjects = function (aSession       : CK_SESSION_HANDLE;
                               aObjects       : pCK_OBJECT_HANDLE;
                               aMaxObjectCount: CK_ULONG;
                               var aObjectCount: CK_ULONG): CK_RV; cdecl;

procCK_C_FindObjectsFinal

  CK_C_FindObjectsFinal = function (aSession: CK_SESSION_HANDLE): CK_RV; cdecl;

procCK_C_SignInit

  CK_C_SignInit = function (aSession  : CK_SESSION_HANDLE;
                            aMechanism: pCK_MECHANISM;
                            aKey      : CK_OBJECT_HANDLE): CK_RV; cdecl;

procCK_C_Sign

  CK_C_Sign = function (aSession        : CK_SESSION_HANDLE;
                        aData           : pCK_BYTE;
                        aDataLen        : CK_ULONG;
                        aSignature      : pCK_BYTE;
                        var aSignatureLen: CK_ULONG): CK_RV; cdecl;

procCK_C_DecryptInit

  CK_C_DecryptInit = function (aSession  : CK_SESSION_HANDLE;
                               aMechanism: pCK_MECHANISM;
                               aKey      : CK_OBJECT_HANDLE): CK_RV; cdecl;

procCK_C_Decrypt

  CK_C_Decrypt = function (aSession    : CK_SESSION_HANDLE;
                           aEncrypted  : pCK_BYTE;
                           aEncryptedLen: CK_ULONG;
                           aData       : pCK_BYTE;
                           var aDataLen: CK_ULONG): CK_RV; cdecl;

procCK_C_GenerateRandom

  CK_C_GenerateRandom = function (aSession   : CK_SESSION_HANDLE;
                                  aRandomData: pCK_BYTE;
                                  aRandomLen : CK_ULONG): CK_RV; cdecl;

procCK_C_CreateObject

  CK_C_CreateObject = function (aSession : CK_SESSION_HANDLE;
                                aTemplate: pCK_ATTRIBUTE;
                                aCount   : CK_ULONG;
                            var aObject  : CK_OBJECT_HANDLE): CK_RV; cdecl;

procCK_C_DestroyObject

  CK_C_DestroyObject = function (aSession: CK_SESSION_HANDLE;
                                 aObject : CK_OBJECT_HANDLE): CK_RV; cdecl;

procCK_C_GenerateKeyPair

  CK_C_GenerateKeyPair = function (aSession           : CK_SESSION_HANDLE;
                                   aMechanism         : pCK_MECHANISM;
                                   aPublicTemplate    : pCK_ATTRIBUTE;
                                   aPublicCount       : CK_ULONG;
                                   aPrivateTemplate   : pCK_ATTRIBUTE;
                                   aPrivateCount      : CK_ULONG;
                                   var aPublicKey     : CK_OBJECT_HANDLE;
                                   var aPrivateKey    : CK_OBJECT_HANDLE): CK_RV; cdecl;

Routines