corePKCS11  V3.0.0
PKCS #11 Cryptoki Library
C_CloseSession
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;
}
CK_DECLARE_FUNCTION
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: core_pkcs11.h:72