Opens a connection between an application and a particular token or sets up an application callback for token insertion.
CK_FLAGS flags,
CK_VOID_PTR pApplication,
CK_NOTIFY Notify,
CK_SESSION_HANDLE_PTR phSession )
{
CK_RV xResult = CKR_OK;
uint32_t ulSessionCount = 0;
( void ) ( slotID );
( void ) ( pApplication );
( void ) Notify;
{
xResult = CKR_CRYPTOKI_NOT_INITIALIZED;
LogError( (
"Could not open a session. PKCS #11 must be initialized "
"before any operations." ) );
}
if( NULL == phSession )
{
xResult = CKR_ARGUMENTS_BAD;
LogError( (
"Could not open a session. phSession cannot be a NULL pointer." ) );
}
if( ( CKR_OK == xResult ) && ( 0UL == ( CKF_SERIAL_SESSION & flags ) ) )
{
xResult = CKR_SESSION_PARALLEL_NOT_SUPPORTED;
LogError( (
"Could not open a session. CKR_SESSION_PARALLEL_NOT_SUPPORTED "
"must always be a set flag." ) );
}
if( CKR_OK == xResult )
{
{
{
if(
pxP11Sessions[ ulSessionCount ].xOpened == ( CK_BBOOL ) CK_FALSE )
{
xResult = CKR_OK;
pxSessionObj->
xOpened = ( CK_BBOOL ) CK_TRUE;
break;
}
else
{
xResult = CKR_SESSION_COUNT;
}
}
}
else
{
xResult = CKR_FUNCTION_FAILED;
LogError( (
"Could not open a session. Unsuccessful in taking xSessionMutex." ) );
}
if( CKR_OK == xResult )
{
}
}
if( CKR_OK == xResult )
{
( 0UL != ( flags & CKF_RW_SESSION ) ) ? CKS_RW_PUBLIC_SESSION : CKS_RO_PUBLIC_SESSION;
LogDebug( (
"Assigned a 0x%0lX Type Session.", (
unsigned long int ) pxSessionObj->
ulState ) );
}
if( CKR_OK == xResult )
{
LogDebug( (
"Assigned Mechanisms to no operation in progress." ) );
}
if( xResult == CKR_SESSION_COUNT )
{
LogError( (
"Could not open a session. All sessions have "
"been taken. Consider increasing value of "
"pkcs11configMAX_SESSIONS." ) );
}
if( CKR_OK == xResult )
{
++ulSessionCount;
*phSession = ulSessionCount;
LogDebug( (
"Current session count at %lu", (
unsigned long int ) ( ulSessionCount - 1UL ) ) );
}
return xResult;
}
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: core_pkcs11.h:77
#define LogError(message)
Macro that is called in the corePKCS11 library for logging "Error" level messages.
Definition: core_pkcs11_config_defaults.h:317
#define pkcs11configMAX_SESSIONS
Maximum number of sessions that can be stored by the PKCS #11 module.
Definition: core_pkcs11_config_defaults.h:131
#define LogDebug(message)
Macro that is called in the corePKCS11 library for logging "Debug" level messages.
Definition: core_pkcs11_config_defaults.h:377
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 pxP11Sessions[pkcs11configMAX_SESSIONS]
The global PKCS #11 session list.
Definition: core_pkcs11_mbedtls.c:331
CK_RV C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, CK_NOTIFY Notify, CK_SESSION_HANDLE_PTR phSession)
Opens a connection between an application and a particular token or sets up an application callback f...
Definition: core_pkcs11_mbedtls.c:1814
#define pkcs11NO_OPERATION
Indicates that no PKCS #11 operation is underway for given session.
Definition: core_pkcs11_mbedtls.c:112
Session structure.
Definition: core_pkcs11_mbedtls.c:299
mbedtls_threading_mutex_t xVerifyMutex
Protects the verification key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:306
CK_MECHANISM_TYPE xOperationVerifyMechanism
The mechanism of verify operation in progress. Set during C_VerifyInit.
Definition: core_pkcs11_mbedtls.c:305
CK_BBOOL xOpened
Set to CK_TRUE upon opening PKCS #11 session.
Definition: core_pkcs11_mbedtls.c:301
CK_MECHANISM_TYPE xOperationSignMechanism
Mechanism of the sign operation in progress. Set during C_SignInit.
Definition: core_pkcs11_mbedtls.c:309
CK_ULONG ulState
Stores the session flags.
Definition: core_pkcs11_mbedtls.c:300
mbedtls_threading_mutex_t xSignMutex
Protects the signing key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:310
CK_MECHANISM_TYPE xOperationDigestMechanism
Indicates if a digest operation is in progress.
Definition: core_pkcs11_mbedtls.c:302
CK_BBOOL xIsInitialized
Indicates whether PKCS #11 module has been initialized with a call to C_Initialize.
Definition: core_pkcs11_mbedtls.c:285
mbedtls_threading_mutex_t xSessionMutex
Mutex that protects write operations to the pxSession array.
Definition: core_pkcs11_mbedtls.c:288