corePKCS11 v3.5.0
PKCS #11 Cryptoki Library
C_CloseSession

Closes a session.

CK_DECLARE_FUNCTION( CK_RV, C_CloseSession )( CK_SESSION_HANDLE hSession )
{
P11Session_t * pxSession = prvSessionPointerFromHandle( hSession );
CK_RV xResult = CKR_OK;
/* MISRA Ref 10.5.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/corePKCS11/blob/main/MISRA.md#rule-105 */
/* coverity[misra_c_2012_rule_10_5_violation] */
if( xP11Context.xIsInitialized == ( CK_BBOOL ) CK_FALSE )
{
xResult = CKR_CRYPTOKI_NOT_INITIALIZED;
LogError( ( "Could not close a session. PKCS #11 must be initialized "
"before any operations." ) );
}
else if( pxSession == NULL )
{
xResult = CKR_SESSION_HANDLE_INVALID;
LogError( ( "Could not close a session. The PKCS #11 session handle "
"was invalid." ) );
}
/* MISRA Ref 10.5.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/corePKCS11/blob/main/MISRA.md#rule-105 */
/* coverity[misra_c_2012_rule_10_5_violation] */
else if( pxSession->xOpened == ( CK_BBOOL ) CK_TRUE )
{
/*
* Tear down the session.
*/
mbedtls_pk_free( &pxSession->xSignKey );
pxSession->xSignKeyHandle = CK_INVALID_HANDLE;
mbedtls_mutex_free( &pxSession->xSignMutex );
/* Free the public key context if it exists. */
mbedtls_pk_free( &pxSession->xVerifyKey );
pxSession->xVerifyKeyHandle = CK_INVALID_HANDLE;
mbedtls_mutex_free( &pxSession->xVerifyMutex );
mbedtls_sha256_free( &pxSession->xSHA256Context );
/* memset clears the open flag, so there is no need to set it to CK_FALSE */
( void ) memset( pxSession, 0, sizeof( P11Session_t ) );
LogInfo( ( "Successfully closed PKCS #11 session." ) );
}
else
{
/* MISRA */
}
return xResult;
}
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: core_pkcs11.h:77
#define LogInfo(message)
Macro that is called in the corePKCS11 library for logging "Info" level messages.
Definition: core_pkcs11_config_defaults.h:357
#define LogError(message)
Macro that is called in the corePKCS11 library for logging "Error" level messages.
Definition: core_pkcs11_config_defaults.h:317
static P11Struct_t xP11Context
The global PKCS #11 module object. Entropy/randomness and object lists are shared across PKCS #11 ses...
Definition: core_pkcs11_mbedtls.c:326
static P11Session_t * prvSessionPointerFromHandle(CK_SESSION_HANDLE xSession)
Maps an opaque caller session handle into its internal state structure.
Definition: core_pkcs11_mbedtls.c:382
CK_RV C_CloseSession(CK_SESSION_HANDLE hSession)
Closes a session.
Definition: core_pkcs11_mbedtls.c:1953
Session structure.
Definition: core_pkcs11_mbedtls.c:299
CK_OBJECT_HANDLE xSignKeyHandle
Object handle to the signing key.
Definition: core_pkcs11_mbedtls.c:311
mbedtls_threading_mutex_t xVerifyMutex
Protects the verification key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:306
mbedtls_sha256_context xSHA256Context
Context for in progress digest operation.
Definition: core_pkcs11_mbedtls.c:313
mbedtls_pk_context xVerifyKey
Verification key. Set during C_VerifyInit.
Definition: core_pkcs11_mbedtls.c:308
CK_BBOOL xOpened
Set to CK_TRUE upon opening PKCS #11 session.
Definition: core_pkcs11_mbedtls.c:301
CK_OBJECT_HANDLE xVerifyKeyHandle
Object handle to the verification key.
Definition: core_pkcs11_mbedtls.c:307
mbedtls_threading_mutex_t xSignMutex
Protects the signing key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:310
mbedtls_pk_context xSignKey
Signing key. Set during C_SignInit.
Definition: core_pkcs11_mbedtls.c:312
CK_BBOOL xIsInitialized
Indicates whether PKCS #11 module has been initialized with a call to C_Initialize.
Definition: core_pkcs11_mbedtls.c:285
Parameters
[in]hSessionThe session handle to be terminated.
Returns
CKR_OK if successful.