corePKCS11  v3.2.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;
/* 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." ) );
}
/* 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;
}
Parameters
[in]hSessionThe session handle to be terminated.
Returns
CKR_OK if successful.
P11Session_t::xSignKey
mbedtls_pk_context xSignKey
Signing key. Set during C_SignInit.
Definition: core_pkcs11_mbedtls.c:299
P11Session_t::xVerifyMutex
mbedtls_threading_mutex_t xVerifyMutex
Protects the verification key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:293
P11Struct_t::xIsInitialized
CK_BBOOL xIsInitialized
Indicates whether PKCS #11 module has been initialized with a call to C_Initialize.
Definition: core_pkcs11_mbedtls.c:272
xP11Context
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:313
P11Session_t::xSHA256Context
mbedtls_sha256_context xSHA256Context
Context for in progress digest operation.
Definition: core_pkcs11_mbedtls.c:300
LogInfo
#define LogInfo(message)
Macro that is called in the corePKCS11 library for logging "Info" level messages.
Definition: core_pkcs11_config_defaults.h:355
P11Session_t::xVerifyKeyHandle
CK_OBJECT_HANDLE xVerifyKeyHandle
Object handle to the verification key.
Definition: core_pkcs11_mbedtls.c:294
P11Session_t::xSignMutex
mbedtls_threading_mutex_t xSignMutex
Protects the signing key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:297
P11Session_t::xVerifyKey
mbedtls_pk_context xVerifyKey
Verification key. Set during C_VerifyInit.
Definition: core_pkcs11_mbedtls.c:295
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
P11Session_t::xSignKeyHandle
CK_OBJECT_HANDLE xSignKeyHandle
Object handle to the signing key.
Definition: core_pkcs11_mbedtls.c:298
C_CloseSession
CK_RV C_CloseSession(CK_SESSION_HANDLE hSession)
Closes a session.
Definition: core_pkcs11_mbedtls.c:1895
P11Session_t
Session structure.
Definition: core_pkcs11_mbedtls.c:286
P11Session_t::xOpened
CK_BBOOL xOpened
Set to CK_TRUE upon opening PKCS #11 session.
Definition: core_pkcs11_mbedtls.c:288
LogError
#define LogError(message)
Macro that is called in the corePKCS11 library for logging "Error" level messages.
Definition: core_pkcs11_config_defaults.h:315