/*----------------------------------------------------------------------- * File: CALLOUTS.H * * Copyright (c) 1995-2000 Intel Corporation. All rights reserved. *----------------------------------------------------------------------- */ /* The following functions can serve as starting points for the any CSP. * Fill in the missing functionality required to manage your specific * service provider. */ /* CSSM Headers */ #define NO_CSSM_EMM_API #include "cssm.h" /* Porting library headers */ #include "cssmport.h" #include "cssmlock.h" /* Service provider specific headers */ /* MAF Core Headers */ #include "maf_collectn.h" #include "maf_config.h" #include "maf_integ.h" #include "maf_interface.h" #include "maf_util.h" /* MAF Utility Headers */ #include "maf_dbg.h" /* MAF-CSM Headers */ #include "csm_sesn.h" #include "csm_cspi.h" /* Macro used to fill in the CSP function table for the CSSM */ #define CSPI_FUNCTION( _table_, _func_ ) \ _table_._func_ = CSM_##_func_ CSSM_RETURN Addin_callout_Initialize(void) { CSSM_RETURN rv; MAF_OutputDebugString( "-----> " ADDIN_NAME " Initialize" ); rv = CSM_KMInit(); if ( rv != CSSM_OK ) { rv = CSSM_ERRCODE_INTERNAL_ERROR; } return rv; } CSSM_RETURN Addin_callout_Terminate(void) { MAF_OutputDebugString( "-----> " ADDIN_NAME " Teminate" ); CSM_KMTerm(); return CSSM_OK; } #define PRI_KEY_FILE "stubcsp.pri" CSSM_RETURN Addin_callout_LoadDataConstruct( ADDIN_MODULE_HANDLE hCssm, ADDIN_LOAD_DATA * pAddinLoadData ) { char FilePathBuf[CSSM_MAX_PATH]; CSSM_RETURN rtn = CSSM_OK; if ( pAddinLoadData == NULL ) { return CSSMERR_CSP_INTERNAL_ERROR; } #if defined (VMS) /* Place the private key file under the user's login directory. */ GetUserDirectory( FilePathBuf, sizeof(FilePathBuf) ); #elif defined (LINUX) GetSystemDirectory( FilePathBuf, sizeof(FilePathBuf) ); #elif defined (__digital__) /* does VMS want to use this? */ { /* XXX Rethink this. */ uint32 len; struct passwd *pw = getpwuid(getuid()); if ((pw == NULL) || (pw->pw_dir == NULL) || (*pw->pw_dir == '\0')) return CSSMERR_CSP_INTERNAL_ERROR; len = strlen(pw->pw_dir); if ((len + 1 + sizeof(PRI_KEY_FILE)) > sizeof FilePathBuf) return CSSMERR_CSP_INTERNAL_ERROR; strcpy(FilePathBuf, pw->pw_dir); } #else /* Place the private key file in the windows directory on the system */ GetWindowsDirectory( FilePathBuf, sizeof(FilePathBuf) ); #endif #ifndef VMS strcat( FilePathBuf, DIRECTORY_SEPARATOR_STRING ); #endif strcat( FilePathBuf, PRI_KEY_FILE ); /* Try to open the private key file */ rtn = CSM_KMOpenKeyFile( FilePathBuf, &(pAddinLoadData->hKeyFile) ); if ( rtn == KMERR_FILE_DOES_NOT_EXIST ) { /* If the file does not exist yet, then try to create it and open it */ rtn = CSM_KMCreateKeyFile( FilePathBuf, NULL ); if ( rtn == CSSM_OK ) { rtn = CSM_KMOpenKeyFile( FilePathBuf, &(pAddinLoadData->hKeyFile) ); } } return rtn; } void Addin_callout_LoadDataDestroy( ADDIN_LOAD_DATA * pAddinLoadData ) { if ( pAddinLoadData ) { CSM_KMCloseKeyFile( pAddinLoadData->hKeyFile ); } } CSSM_RETURN Addin_callout_AttachDataConstruct( ADDIN_ATTACH_DATA* pAddinAttachData ) { CSSM_RETURN rv = CSSM_OK; MAF_OutputDebugString( "-----> " ADDIN_NAME " AttachDataConstruct" ); /* Initialize the CSP session list for this attach */ rv = CSM_SessionListInit( &pAddinAttachData->slSessions ); return rv; } void Addin_callout_AttachDataDestroy( ADDIN_ATTACH_DATA* pAddinAttachData ) { MAF_OutputDebugString( "-----> " ADDIN_NAME " AttachDataDestroy" ); /* Shut down the CSP session list */ CSM_SessionListTerminate( &pAddinAttachData->slSessions ); } CSSM_RETURN Addin_callout_ModuleAttach( MAF_MODULE_LOAD_TRACKER_PTR pLoadTracker, MAF_MODULE_ATTACH_TRACKER_PTR pAttachTracker, CSSM_MODULE_FUNCS_PTR *FuncTbl ) { static CSSM_MODULE_FUNCS CspModuleFuncs; static CSSM_SPI_CSP_FUNCS CspFuncTable; MAF_OutputDebugString( "-----> " ADDIN_NAME " ModuleAttach" ); /* Build the proper SPI function table based on the service type */ if ( pAttachTracker->SubServiceType == CSSM_SERVICE_CSP ) { /* Fill in the module functions */ CspModuleFuncs.ServiceType = CSSM_SERVICE_CSP; CspModuleFuncs.NumberOfServiceFuncs = sizeof(CSSM_SPI_CSP_FUNCS) / sizeof(CSSM_PROC_ADDR); CspModuleFuncs.ServiceFuncs = (CSSM_PROC_ADDR*)&CspFuncTable; /* Fill in the CSP SPI functions */ CSPI_FUNCTION( CspFuncTable, EventNotify ); CSPI_FUNCTION( CspFuncTable, QuerySize ); CSPI_FUNCTION( CspFuncTable, SignData ); CSPI_FUNCTION( CspFuncTable, SignDataInit ); CSPI_FUNCTION( CspFuncTable, SignDataUpdate ); CSPI_FUNCTION( CspFuncTable, SignDataFinal ); CSPI_FUNCTION( CspFuncTable, VerifyData ); CSPI_FUNCTION( CspFuncTable, VerifyDataInit ); CSPI_FUNCTION( CspFuncTable, VerifyDataUpdate ); CSPI_FUNCTION( CspFuncTable, VerifyDataFinal ); CSPI_FUNCTION( CspFuncTable, DigestData ); CSPI_FUNCTION( CspFuncTable, DigestDataInit ); CSPI_FUNCTION( CspFuncTable, DigestDataUpdate ); CSPI_FUNCTION( CspFuncTable, DigestDataClone ); CSPI_FUNCTION( CspFuncTable, DigestDataFinal ); CSPI_FUNCTION( CspFuncTable, GenerateMac ); CSPI_FUNCTION( CspFuncTable, GenerateMacInit ); CSPI_FUNCTION( CspFuncTable, GenerateMacUpdate ); CSPI_FUNCTION( CspFuncTable, GenerateMacFinal ); CSPI_FUNCTION( CspFuncTable, VerifyMac ); CSPI_FUNCTION( CspFuncTable, VerifyMacInit ); CSPI_FUNCTION( CspFuncTable, VerifyMacUpdate ); CSPI_FUNCTION( CspFuncTable, VerifyMacFinal ); CSPI_FUNCTION( CspFuncTable, EncryptData ); CSPI_FUNCTION( CspFuncTable, EncryptDataInit ); CSPI_FUNCTION( CspFuncTable, EncryptDataUpdate ); CSPI_FUNCTION( CspFuncTable, EncryptDataFinal ); CSPI_FUNCTION( CspFuncTable, DecryptData ); CSPI_FUNCTION( CspFuncTable, DecryptDataInit ); CSPI_FUNCTION( CspFuncTable, DecryptDataUpdate ); CSPI_FUNCTION( CspFuncTable, DecryptDataFinal ); CSPI_FUNCTION( CspFuncTable, QueryKeySizeInBits ); CSPI_FUNCTION( CspFuncTable, GenerateKey ); CSPI_FUNCTION( CspFuncTable, GenerateKeyPair ); CSPI_FUNCTION( CspFuncTable, GenerateRandom ); CSPI_FUNCTION( CspFuncTable, GenerateAlgorithmParams ); CSPI_FUNCTION( CspFuncTable, WrapKey ); CSPI_FUNCTION( CspFuncTable, UnwrapKey ); CSPI_FUNCTION( CspFuncTable, DeriveKey ); CSPI_FUNCTION( CspFuncTable, FreeKey ); CSPI_FUNCTION( CspFuncTable, PassThrough ); CSPI_FUNCTION( CspFuncTable, Login ); CSPI_FUNCTION( CspFuncTable, Logout ); CSPI_FUNCTION( CspFuncTable, ChangeLoginAcl ); CSPI_FUNCTION( CspFuncTable, ObtainPrivateKeyFromPublicKey ); CSPI_FUNCTION( CspFuncTable, RetrieveUniqueId ); CSPI_FUNCTION( CspFuncTable, RetrieveCounter ); CSPI_FUNCTION( CspFuncTable, VerifyDevice ); CSPI_FUNCTION( CspFuncTable, GetOperationalStatistics ); CSPI_FUNCTION( CspFuncTable, GetTimeValue ); CSPI_FUNCTION( CspFuncTable, GetLoginAcl ); CSPI_FUNCTION( CspFuncTable, GetKeyAcl ); CSPI_FUNCTION( CspFuncTable, ChangeKeyAcl ); CSPI_FUNCTION( CspFuncTable, GetKeyOwner ); CSPI_FUNCTION( CspFuncTable, ChangeKeyOwner ); CSPI_FUNCTION( CspFuncTable, GetLoginOwner ); CSPI_FUNCTION( CspFuncTable, ChangeLoginOwner ); *FuncTbl = &CspModuleFuncs; } else { return CSSMERR_CSSM_INVALID_SERVICE_MASK; } return CSSM_OK; } CSSM_RETURN Addin_callout_ModuleLoad( MAF_MODULE_LOAD_TRACKER_PTR pLoadTracker, CSSM_SPI_ModuleEventHandler CssmNotifyCallback, const void* CssmNotifyCallbackCtx) { MAF_OutputDebugString( "-----> " ADDIN_NAME " ModuleLoad" ); /* Notify the CSSM that the CSP is available for use */ CssmNotifyCallback( &ADDIN_GUID, (void*)CssmNotifyCallbackCtx, ADDIN_CSP_SUBSERVICE_ID, CSSM_SERVICE_CSP, CSSM_NOTIFY_INSERT ); return CSSM_OK; } CSSM_RETURN Addin_callout_ModuleUnload( MAF_MODULE_LOAD_TRACKER_PTR pLoadTracker, CSSM_SPI_ModuleEventHandler CssmNotifyCallback, const void* CssmNotifyCallbackCtx) { MAF_OutputDebugString( "-----> " ADDIN_NAME " ModuleUnload" ); return CSSM_OK; }