/*
* 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 <security/cryptoki.h>
#include "softGlobal.h"
#include "softSession.h"
#include "softObject.h"
#include "softKeystore.h"
#include "softKeystoreUtil.h"
{
if (!softtoken_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);
if (slotID != SOFTTOKEN_SLOTID)
return (CKR_SLOT_ID_INVALID);
return (CKR_ARGUMENTS_BAD);
/*
* softtoken has no limit on the number of concurrent sessions
* that the token allows. No need to check to see if the
* token has too many sessions already open.
*/
/* Create a new session */
return (rv);
}
{
if (!softtoken_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 SES_REFRELE()
* will release the session lock for us.
*/
/*
* Delete a session by calling soft_delete_session() with
* a session pointer and a boolean arguments. Boolean
* value FALSE is used to indicate that the caller does not
* hold the lock on the global session list and also that
* this is not a forced session close but an explicit request.
*
* soft_delete_session() will reset SESSION_IS_CLOSING
* flag after it is done.
*/
if (soft_session_cnt == 0) {
/* Clean up private token objects from the token object list */
/*
* Invalidate public token object handles instead of
* deleting them.
*/
(void) pthread_mutex_lock(&soft_giant_mutex);
soft_slot.authenticated = 0;
(void) pthread_mutex_unlock(&soft_giant_mutex);
}
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
if (slotID != SOFTTOKEN_SLOTID)
return (CKR_SLOT_ID_INVALID);
/* Acquire the global session list lock */
(void) pthread_mutex_lock(&soft_sessionlist_mutex);
/*
* Set all_sessions_closing flag so any access to any
* existing sessions will be rejected.
*/
all_sessions_closing = 1;
(void) pthread_mutex_unlock(&soft_sessionlist_mutex);
/* Delete all the sessions and release the allocated resources */
/* Clean up private token objects from the token object list */
/* Invalidate public token object handles instead of deleting them */
(void) pthread_mutex_lock(&soft_giant_mutex);
soft_slot.authenticated = 0;
(void) pthread_mutex_unlock(&soft_giant_mutex);
(void) pthread_mutex_lock(&soft_sessionlist_mutex);
/* Reset all_sessions_closing flag. */
all_sessions_closing = 0;
(void) pthread_mutex_unlock(&soft_sessionlist_mutex);
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
goto clean_exit;
}
/* Provide information for the specified session */
pInfo->ulDeviceError = 0;
/*
* Decrement the session reference count.
* We hold the session lock, and SES_REFRELE()
* will release the session lock for us.
*/
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/*
* Only check if pulOperationStateLen is NULL_PTR.
* No need to check if pOperationState is NULL_PTR because
* application might just ask for the length of buffer to hold
* the OperationState.
*/
if (pulOperationStateLen == NULL_PTR) {
goto clean_exit;
}
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
if ((pOperationState == NULL_PTR) ||
(ulOperationStateLen == 0)) {
goto clean_exit;
}
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Check the load status of keystore */
if (!soft_keystore_status(KEYSTORE_LOAD)) {
return (CKR_DEVICE_REMOVED);
}
return (CKR_USER_TYPE_INVALID);
}
return (CKR_PIN_LEN_RANGE);
}
/*
* We don't support CKF_PROTECTED_AUTHENTICATION_PATH
*/
return (CKR_ARGUMENTS_BAD);
}
(void) pthread_mutex_lock(&soft_giant_mutex);
if (soft_slot.authenticated) {
(void) pthread_mutex_unlock(&soft_giant_mutex);
return (CKR_USER_ALREADY_LOGGED_IN);
}
if (soft_slot.userpin_change_needed) {
/*
* This is the special case when the PIN is never
* initialized in the keystore, which will always
* return CKR_OK with "userpin_change_needed" set.
*/
(void) pthread_mutex_unlock(&soft_giant_mutex);
return (rv);
}
(void) pthread_mutex_unlock(&soft_giant_mutex);
} else {
(void) pthread_mutex_unlock(&soft_giant_mutex);
return (rv);
}
/*
* Load all the private token objects from keystore.
*/
return (rv);
}
/* Acquire the global session list lock */
(void) pthread_mutex_lock(&soft_sessionlist_mutex);
while (sp) {
} else {
}
}
(void) pthread_mutex_unlock(&soft_sessionlist_mutex);
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
(void) pthread_mutex_lock(&soft_giant_mutex);
if (!soft_slot.authenticated) {
if (!soft_slot.userpin_change_needed) {
/*
* Only if the PIN has been initialized in the keystore.
*/
(void) pthread_mutex_unlock(&soft_giant_mutex);
return (CKR_USER_NOT_LOGGED_IN);
} else {
(void) pthread_mutex_unlock(&soft_giant_mutex);
return (CKR_OK);
}
}
soft_logout();
soft_slot.authenticated = 0;
(void) pthread_mutex_unlock(&soft_giant_mutex);
/* Acquire the global session list lock */
(void) pthread_mutex_lock(&soft_sessionlist_mutex);
while (sp) {
} else {
}
}
(void) pthread_mutex_unlock(&soft_sessionlist_mutex);
return (rv);
}