corePKCS11
v3.2.0
PKCS #11 Cryptoki Library
|
|
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;
}
- Note
- PKCS #11 module must have been previously initialized with a call to C_Initialize() before calling C_OpenSession().
- Parameters
-
[in] | slotID | This parameter is unused in this port. |
[in] | flags | Session flags - CKF_SERIAL_SESSION is a mandatory flag. |
[in] | pApplication | This parameter is unused in this port. |
[in] | Notify | This parameter is unused in this port. |
[in] | phSession | Pointer to the location that the created session's handle will be placed. |
- Returns
- CKR_OK if successful.
CK_MECHANISM_TYPE xOperationVerifyMechanism
The mechanism of verify operation in progress. Set during C_VerifyInit.
Definition: core_pkcs11_mbedtls.c:292
CK_MECHANISM_TYPE xOperationDigestMechanism
Indicates if a digest operation is in progress.
Definition: core_pkcs11_mbedtls.c:289
CK_MECHANISM_TYPE xOperationSignMechanism
Mechanism of the sign operation in progress. Set during C_SignInit.
Definition: core_pkcs11_mbedtls.c:296
mbedtls_threading_mutex_t xVerifyMutex
Protects the verification key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:293
CK_BBOOL xIsInitialized
Indicates whether PKCS #11 module has been initialized with a call to C_Initialize.
Definition: core_pkcs11_mbedtls.c:272
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
#define LogDebug(message)
Macro that is called in the corePKCS11 library for logging "Debug" level messages.
Definition: core_pkcs11_config_defaults.h:375
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:1762
mbedtls_threading_mutex_t xSessionMutex
Mutex that protects write operations to the pxSession array.
Definition: core_pkcs11_mbedtls.c:275
mbedtls_threading_mutex_t xSignMutex
Protects the signing key from being modified while in use.
Definition: core_pkcs11_mbedtls.c:297
static P11Session_t pxP11Sessions[pkcs11configMAX_SESSIONS]
The global PKCS #11 session list.
Definition: core_pkcs11_mbedtls.c:318
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: core_pkcs11.h:75
#define pkcs11configMAX_SESSIONS
Maximum number of sessions that can be stored by the PKCS #11 module.
Definition: core_pkcs11_config_defaults.h:129
Session structure.
Definition: core_pkcs11_mbedtls.c:286
CK_ULONG ulState
Stores the session flags.
Definition: core_pkcs11_mbedtls.c:287
CK_BBOOL xOpened
Set to CK_TRUE upon opening PKCS #11 session.
Definition: core_pkcs11_mbedtls.c:288
#define pkcs11NO_OPERATION
Indicates that no PKCS #11 operation is underway for given session.
Definition: core_pkcs11_mbedtls.c:106
#define LogError(message)
Macro that is called in the corePKCS11 library for logging "Error" level messages.
Definition: core_pkcs11_config_defaults.h:315