/*
* 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
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <pthread.h>
#include <stdlib.h>
#include <security/cryptoki.h>
#include "softGlobal.h"
#include "softObject.h"
#include "softSession.h"
#include "softKeystore.h"
#include "softKeystoreUtil.h"
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
goto clean_exit;
}
/* Create a new object. */
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
{
ulong_t i;
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Check arguments */
(phNewObject == NULL)) {
goto clean_exit;
}
/* Obtain the object pointer. */
goto clean_exit;
}
/*
* Copy the old object to a new object.
* The 3rd argument with SOFT_COPY_OBJ value indicates that
* everything in the object will be duplicated for C_CopyObject.
* The 4th argument has the session pointer that will be
* saved in the new copy of the session object.
*/
/* Most likely we ran out of space. */
goto clean_exit1;
}
/* No need to hold the lock on the old object. */
/* Modifiy the objects if requested */
for (i = 0; i < ulCount; i++) {
/* Set the requested attribute into the new object. */
goto fail;
}
}
goto fail;
}
/*
* Does the new object violate the creation rule or access rule?
*/
goto fail;
}
/*
* If the new object is a token object, it will be added
* to token object list and write to disk.
*/
if (IS_TOKEN_OBJECT(new_object)) {
/*
* Write to the keystore file.
*/
goto fail;
}
/*
* Add the newly created token object to the global
* token object list in the slot struct.
*/
return (CKR_OK);
}
/* Insert new object into this session's object list */
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
/* set handle of the new object */
return (rv);
fail:
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* The reason that we don't call handle2session is because
* the argument hSession may not be the creating_session of
* the object to be destroyed, and we want to avoid the lock
* contention. The handle2session will be called later for
* the creating_session.
*/
return (CKR_SESSION_HANDLE_INVALID);
}
/* Obtain the object pointer. */
return (rv);
}
/* Obtain the session handle which object belongs to. */
if (creating_session == NULL) {
/*
* This is a token object to be deleted.
* For token object, there is no creating session concept,
* therefore, creating_session is always NULL.
*/
return (rv);
}
/* Obtain the session pointer just for validity check. */
return (rv);
}
return (rv);
}
/*
* Set OBJECT_IS_DELETING flag so any access to this
* object will be rejected.
*/
return (CKR_OBJECT_HANDLE_INVALID);
}
/*
* Delete a token object by calling soft_delete_token_object()
* with the second argument B_TRUE indicating to delete the
* object from keystore and the third argument B_FALSE
* indicating that the caller does not hold the slot mutex.
*/
return (CKR_OK);
}
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
}
/*
* Set OBJECT_IS_DELETING flag so any access to this
* object will be rejected.
*/
return (CKR_OBJECT_HANDLE_INVALID);
}
/*
* Delete an object by calling soft_delete_object()
* with a FALSE boolean argument indicating that
* the caller does not hold the session lock.
*/
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
{
ulong_t i;
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (CKR_ARGUMENTS_BAD);
}
/* Obtain the object pointer. */
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
if (IS_TOKEN_OBJECT(object_p)) {
return (rv);
}
}
/* Acquire the lock on the object. */
for (i = 0; i < ulCount; i++) {
/*
* Get the value of each attribute in the template.
* (We must process EVERY attribute in the template.)
*/
/* At least we catch some type of error. */
}
/* Release the object lock */
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
{
ulong_t i;
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (CKR_ARGUMENTS_BAD);
}
/* Obtain the object pointer. */
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
goto fail_1;
}
/*
* Start working on the object, so we need to set the write lock so that
* no one can write to it but still can read it.
*/
if (IS_TOKEN_OBJECT(object_p)) {
goto fail_1;
}
}
/*
* Copy the old object to a new object. We work on the copied
* version because in case of error we still keep the old one
* intact.
* The 3rd argument with SOFT_SET_ATTR_VALUE value indicates that
* not everything will be duplicated for C_SetAttributeValue.
* Information not duplicated are those attributes that are not
* modifiable.
*/
/* Most likely we ran out of space. */
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
goto fail_1;
}
/*
* No need to hold the lock on the old object, because we
* will be working on the new scratch object.
*/
goto fail;
}
for (i = 0; i < ulCount; i++) {
/* Set the requested attribute into the new object. */
goto fail;
}
}
/*
* We've successfully set all the requested attributes.
* Merge the new object with the old object, then destory
* the new one. The reason to do the merging is because we
* have to keep the original object handle (address of object).
*/
/*
* The object has been modified, so we write it back to keystore.
*/
if (IS_TOKEN_OBJECT(object_p)) {
}
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
fail:
return (rv);
}
/*ARGSUSED*/
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_FUNCTION_NOT_SUPPORTED);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Check the arguments */
/* decrement the session count, we do not hold the lock */
return (CKR_ARGUMENTS_BAD);
}
/* Acquire the session lock */
/* Check to see if find operation is already active */
/* decrement the session count, and unlock the mutex */
return (CKR_OPERATION_ACTIVE);
} else {
/*
* This active flag will remain ON until application calls
* C_FindObjectsFinal.
*/
}
}
/* decrement the session count, and unlock the mutex */
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* check for invalid arguments */
(pulObjectCount == NULL)) {
/* decrement the session count, we do not hold the lock */
return (CKR_ARGUMENTS_BAD);
}
if (ulMaxObjectCount == 0) {
/* don't need to do anything, just return */
*pulObjectCount = 0;
/* decrement the session count, we do not hold the lock */
return (CKR_OK);
}
/* Acquire the session lock */
/* Check to see if find operation is active */
return (CKR_OPERATION_NOT_INITIALIZED);
}
/* decrement the session count, and release the lock */
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Acquire the session lock */
/* Check to see if find operation is active */
return (CKR_OPERATION_NOT_INITIALIZED);
}
/* decrement the session count, and release the lock */
return (rv);
}