/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <pthread.h>
#include <errno.h>
#include <security/cryptoki.h>
#include "kernelGlobal.h"
#include "kernelSession.h"
#include "kernelSlot.h"
#include "kernelEmulate.h"
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* For legacy reasons, the CKF_SERIAL_SESSION bit must always
* be set.
*/
if (!(flags & CKF_SERIAL_SESSION))
return (CKR_SESSION_PARALLEL_NOT_SUPPORTED);
return (CKR_ARGUMENTS_BAD);
if (slotID >= slot_count) {
return (CKR_SLOT_ID_INVALID);
}
/*
* Acquire the slot lock to protect sl_state and sl_sess_list.
* These two fields need to be protected atomically, even though
* "sl_sess_list" is updated in kernel_add_session().
*/
/* If SO is logged in the slot, only the RW session is allowed. */
return (CKR_SESSION_READ_WRITE_SO_EXISTS);
}
/* Create a new session */
return (rv);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/*
* Set SESSION_IS_CLOSING flag so any access to this
* session will be rejected.
*/
return (CKR_SESSION_CLOSED);
}
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
/*
* Delete a session by calling kernel_delete_session() with
* a session pointer and two boolean arguments. The 3rd argument
* boolean value FALSE indicates that the caller does not
* hold the slot lock. The 4th argument boolean value B_FALSE
* indicates that we want to delete all the objects completely.
*
* kernel_delete_session() will reset SESSION_IS_CLOSING
* flag after it is done.
*/
B_FALSE);
return (rv);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Delete all the sessions and release the allocated resources */
return (CKR_OK);
}
/*
* Utility routine to get CK_STATE value for a session.
* The caller should not be holding the session lock.
* Return (CK_STATE)-1 if pslot->sl_state is invalid.
*/
static CK_STATE
{
} else { /* invalid */
}
return (state);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_ARGUMENTS_BAD);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Provide information for the specified session */
pInfo->ulDeviceError = 0;
}
/*
* Decrement the session reference count.
*/
return (rv);
}
/*
* Save the state in pOperationState. The data format is:
* 1. Total length (including this field)
* 2. session state
* 3. crypto_active_op_t structure
* 4. digest_buf_t's data buffer contents
*/
static CK_RV
{
int op_data_len = 0;
/*
* Return CKR_OPERATION_NOT_INITIALIZED if the slot
* is capable of C_GetOperationState(). Return
* CKR_FUNCTION_NOT_SUPPORTED otherwise.
*
* We return these codes because some clients
* check the return code to determine if C_GetOperationState()
* is supported.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
else
return (CKR_FUNCTION_NOT_SUPPORTED);
}
/*
* XXX Need to support this case in future.
* This is the case where we exceeded SLOT_HASH_MAX_INDATA_LEN and
* hence started using libmd. SLOT_HASH_MAX_INDATA_LEN is at least
* 64K for current crypto framework providers and web servers
* do not need to clone digests that big for SSL operations.
*/
return (CKR_STATE_UNSAVEABLE);
}
/* Check to see if this is an unsupported operation. */
return (CKR_STATE_UNSAVEABLE);
}
/* Check to see if digest operation is active. */
return (CKR_OPERATION_NOT_INITIALIZED);
}
op_data_len = sizeof (int);
op_data_len += sizeof (CK_STATE);
op_data_len += sizeof (crypto_active_op_t);
if (pOperationState == NULL_PTR) {
return (CKR_OK);
} else {
if (*pulOperationStateLen < op_data_len) {
return (CKR_BUFFER_TOO_SMALL);
}
}
/* Save total length */
dst += sizeof (int);
/* Save session state */
/* Save crypto_active_op_t */
dst += sizeof (crypto_active_op_t);
/* Save the data buffer */
return (CKR_OK);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
if (pulOperationStateLen == NULL_PTR)
return (CKR_ARGUMENTS_BAD);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
return (CKR_ARGUMENTS_BAD);
}
return (rv);
}
/*
* Restore the state from pOperationState. The data format is:
* 1. Total length (including this field)
* 2. session state
* 3. crypto_active_op_t structure
* 4. digest_buf_t's data buffer contents
*/
static CK_RV
{
if ((hAuthenticationKey != 0) || (hEncryptionKey != 0))
return (CKR_KEY_NOT_NEEDED);
/* Get total length field */
if (ulOperationStateLen < expected_len)
return (CKR_SAVED_STATE_INVALID);
/* compute the data buffer length */
indata_len = expected_len - sizeof (int) -
sizeof (CK_STATE) - sizeof (crypto_active_op_t);
return (CKR_SAVED_STATE_INVALID);
src += sizeof (int);
/* Get session state */
if (ses_state != src_ses_state)
return (CKR_SAVED_STATE_INVALID);
/*
* Restore crypto_active_op_t. We need to use a temporary
* buffer to avoid modifying the source session's buffer.
*/
return (CKR_SAVED_STATE_INVALID);
src += sizeof (crypto_active_op_t);
/* This routine reuses the session's existing buffer if possible */
return (rv);
/* Restore the data buffer */
return (CKR_OK);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
if ((pOperationState == NULL_PTR) ||
(ulOperationStateLen == 0))
return (CKR_ARGUMENTS_BAD);
return (rv);
return (CKR_ARGUMENTS_BAD);
}
return (rv);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_USER_TYPE_INVALID);
}
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Acquire the slot lock */
/* Check if the slot is logged in already */
goto clean_exit;
}
/* To login as SO, every session in this slot needs to be R/W */
while (sp) {
/*
* Need not to lock individual sessions before
* accessing their "ses_RO" and "next" fields,
* because they are always accessed under the
* slot's mutex protection.
*/
break;
}
}
if (found) {
goto clean_exit;
}
}
/* Now make the ioctl call; no need to acquire the session lock. */
break;
}
if (r < 0) {
} else {
}
/* Set the slot's session state. */
}
return (rv);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Acquire the slot lock. */
/* Check if the user or SO was logged in */
goto clean_exit;
}
/* Now make the ioctl call. No need to acquire the session lock. */
break;
}
if (r < 0) {
} else {
}
goto clean_exit;
}
/*
* If this slot was logged in as USER previously, we need to clean up
* all private object wrappers in library for this slot.
*/
/* Reset the slot's session state. */
}
return (rv);
}