FreeRTOS: PKCS11
PKCS11 Cryptoki Library
Return to main page ↑
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;
/* coverity[misra_c_2012_rule_10_5_violation] */
if( xP11Context.xIsInitialized == ( CK_BBOOL ) CK_FALSE )
{
xResult = CKR_CRYPTOKI_NOT_INITIALIZED;
}
else if( pxSession == NULL )
{
xResult = CKR_SESSION_HANDLE_INVALID;
}
/* 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 );
if( NULL != pxSession->xSignMutex )
{
vSemaphoreDelete( pxSession->xSignMutex );
}
/* Free the public key context if it exists. */
mbedtls_pk_free( &pxSession->xVerifyKey );
if( NULL != pxSession->xVerifyMutex )
{
vSemaphoreDelete( 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 ) );
}
else
{
/* MISRA */
}
return xResult;
}
Parameters
[in]hSessionThe session handle to be terminated.
Returns
CKR_OK if successful. Else, see PKCS #11 specification for more information.
CK_DECLARE_FUNCTION
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: iot_pkcs11.h:66
P11Session_t::xSignKey
mbedtls_pk_context xSignKey
Signing key. Set during C_SignInit.
Definition: iot_pkcs11_mbedtls.c:228
P11Session_t::xVerifyMutex
SemaphoreHandle_t xVerifyMutex
Protects the verification key from being modified while in use.
Definition: iot_pkcs11_mbedtls.c:224
P11Struct_t::xIsInitialized
CK_BBOOL xIsInitialized
Indicates whether PKCS #11 module has been initialized with a call to C_Initialize.
Definition: iot_pkcs11_mbedtls.c:202
P11Session_t::xSHA256Context
mbedtls_sha256_context xSHA256Context
Context for in progress digest operation.
Definition: iot_pkcs11_mbedtls.c:229
C_CloseSession
CK_RV C_CloseSession(CK_SESSION_HANDLE hSession)
Closes a session.
Definition: iot_pkcs11_mbedtls.c:1849
prvSessionPointerFromHandle
static P11Session_t * prvSessionPointerFromHandle(CK_SESSION_HANDLE xSession)
Maps an opaque caller session handle into its internal state structure.
Definition: iot_pkcs11_mbedtls.c:287
P11Session_t::xVerifyKey
mbedtls_pk_context xVerifyKey
Verification key. Set during C_VerifyInit.
Definition: iot_pkcs11_mbedtls.c:225
P11Session_t
Session structure.
Definition: iot_pkcs11_mbedtls.c:217
P11Session_t::xSignMutex
SemaphoreHandle_t xSignMutex
Protects the signing key from being modified while in use.
Definition: iot_pkcs11_mbedtls.c:227
P11Session_t::xOpened
CK_BBOOL xOpened
Set to CK_TRUE upon opening PKCS #11 session.
Definition: iot_pkcs11_mbedtls.c:219
xP11Context
static P11Struct_t xP11Context
The global PKCS #11 module object. Entropy/randomness and object lists are shared across PKCS #11 ses...
Definition: iot_pkcs11_mbedtls.c:238