corePKCS11  v3.2.0
PKCS #11 Cryptoki Library
C_FindObjects

Initializes an object search operation.

CK_DECLARE_FUNCTION( CK_RV, C_FindObjects )( CK_SESSION_HANDLE hSession,
CK_OBJECT_HANDLE_PTR phObject,
CK_ULONG ulMaxObjectCount,
CK_ULONG_PTR pulObjectCount )
{
P11Session_t * pxSession = prvSessionPointerFromHandle( hSession );
CK_RV xResult = prvCheckValidSessionAndModule( pxSession );
/* See explanation in prvCheckValidSessionAndModule for this exception. */
/* coverity[misra_c_2012_rule_10_5_violation] */
CK_OBJECT_HANDLE xPalHandle = CK_INVALID_HANDLE;
/*
* Check parameters.
*/
if( ( NULL == phObject ) ||
( NULL == pulObjectCount ) )
{
LogError( ( "Failed to find objects. The object handle or the object "
"count pointer was NULL." ) );
xResult = CKR_ARGUMENTS_BAD;
}
if( xResult == CKR_OK )
{
if( pxSession->pxFindObjectLabel == NULL )
{
LogError( ( "Failed to find objects. The PKCS #11 stack must be "
"initialized before any operations." ) );
xResult = CKR_OPERATION_NOT_INITIALIZED;
}
if( 1u != ulMaxObjectCount )
{
xResult = CKR_ARGUMENTS_BAD;
LogError( ( "Failed to find objects. Searching for anything other "
"than 1 object at a time is not supported." ) );
}
}
if( xResult == CKR_OK )
{
/* Try to find the object in module's list first. */
prvFindObjectInListByLabel( pxSession->pxFindObjectLabel, pxSession->xFindObjectLabelLen, &xPalHandle, phObject );
/* Check with the PAL if the object was previously stored. */
if( *phObject == CK_INVALID_HANDLE )
{
LogDebug( ( "Could not find the object handle in the list. "
"Trying to search PKCS #11 PAL for object." ) );
xPalHandle = PKCS11_PAL_FindObject( pxSession->pxFindObjectLabel, pxSession->xFindObjectLabelLen );
}
if( xPalHandle != CK_INVALID_HANDLE )
{
LogDebug( ( "Found object in PAL. Adding object handle to list." ) );
xResult = prvAddObjectToList( xPalHandle, phObject, pxSession->pxFindObjectLabel, pxSession->xFindObjectLabelLen );
*pulObjectCount = 1;
}
else
{
/* Note: Objects living in header files are not destroyed. */
/* According to the PKCS #11 standard, not finding an object results in a CKR_OK return value with an object count of 0. */
*pulObjectCount = 0;
}
}
/* Clean up memory if there was an error finding the object. */
if( xResult != CKR_OK )
{
if( pxSession != NULL )
{
mbedtls_free( pxSession->pxFindObjectLabel );
pxSession->pxFindObjectLabel = NULL;
pxSession->xFindObjectLabelLen = 0;
}
}
return xResult;
}
See also
C_FindObjectsInit() which must be called before calling C_FindObjects() and C_FindObjectsFinal(), which must be called after.
Note
FindObjects parameters are shared by a session. Calling C_FindObjectsInit(), C_FindObjects(), and C_FindObjectsFinal() with the same session across different tasks may lead to unexpected results.
Parameters
[in]hSessionHandle of a valid PKCS #11 session.
[out]phObjectPoints to the handle of the object to be found.
[in]ulMaxObjectCountThe size of the phObject object handle array. In this port, this value should always be set to 1, as searching for multiple objects is not supported.
[out]pulObjectCountThe actual number of objects that are found. In this port, if an object is found this value will be 1, otherwise if the object is not found, it will be set to 0.
Note
In the event that an object does not exist, CKR_OK will be returned, but pulObjectCount will be set to 0.
Returns
CKR_OK if successful.
C_FindObjects
CK_RV C_FindObjects(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, CK_ULONG ulMaxObjectCount, CK_ULONG_PTR pulObjectCount)
Initializes an object search operation.
Definition: core_pkcs11_mbedtls.c:3397
LogDebug
#define LogDebug(message)
Macro that is called in the corePKCS11 library for logging "Debug" level messages.
Definition: core_pkcs11_config_defaults.h:375
P11Session_t::xFindObjectLabelLen
CK_ULONG xFindObjectLabelLen
Size of current search label.
Definition: core_pkcs11_mbedtls.c:291
prvFindObjectInListByLabel
static void prvFindObjectInListByLabel(const CK_BYTE *pcLabel, CK_ULONG xLabelLength, CK_OBJECT_HANDLE_PTR pxPalHandle, CK_OBJECT_HANDLE_PTR pxAppHandle)
Parses attribute values for a private EC Key.
Definition: core_pkcs11_mbedtls.c:1039
prvCheckValidSessionAndModule
static CK_RV prvCheckValidSessionAndModule(const P11Session_t *pxSession)
Helper to check if the current session is initialized and valid.
Definition: core_pkcs11_mbedtls.c:323
PKCS11_PAL_FindObject
CK_OBJECT_HANDLE PKCS11_PAL_FindObject(CK_BYTE_PTR pxLabel, CK_ULONG usLength)
Translates a PKCS #11 label into an object handle.
CK_DECLARE_FUNCTION
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: core_pkcs11.h:75
prvSessionPointerFromHandle
static P11Session_t * prvSessionPointerFromHandle(CK_SESSION_HANDLE xSession)
Maps an opaque caller session handle into its internal state structure.
Definition: core_pkcs11_mbedtls.c:365
prvAddObjectToList
static CK_RV prvAddObjectToList(CK_OBJECT_HANDLE xPalHandle, CK_OBJECT_HANDLE_PTR pxAppHandle, const CK_BYTE *pcLabel, CK_ULONG xLabelLength)
Add an object that exists in NVM to the application object array.
Definition: core_pkcs11_mbedtls.c:1141
P11Session_t
Session structure.
Definition: core_pkcs11_mbedtls.c:286
P11Session_t::pxFindObjectLabel
CK_BYTE * pxFindObjectLabel
Pointer to the label for the search in progress. Should be NULL if no search in progress.
Definition: core_pkcs11_mbedtls.c:290
LogError
#define LogError(message)
Macro that is called in the corePKCS11 library for logging "Error" level messages.
Definition: core_pkcs11_config_defaults.h:315