/*
* The Initial Developer of the Original Code is International
* Business Machines Corporation. Portions created by IBM
* Corporation are Copyright (C) 2005 International Business
* Machines Corporation. All Rights Reserved.
*
* it under the terms of the Common Public License as published by
* IBM Corporation; either version 1 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Common Public License for more details.
*
* You should have received a copy of the Common Public License
* along with this program; if not, a copy can be viewed at
*/
/* (C) COPYRIGHT International Business Machines Corp. 2001, 2002, 2005 */
/*
*/
#include <pwd.h>
#include <grp.h>
#include "tpmtok_int.h"
#include "tpmtok_defs.h"
extern pthread_rwlock_t obj_list_rw_mutex;
void SC_SetFunctionList(void);
int debugfile = 0;
extern void stlogterm();
extern void stloginit();
{
}
void
Fork_Initializer(void)
{
stlogterm();
stloginit(); // Initialize Logging so we can capture EVERYTHING
// Force logout. This cleans out the private session and list
// and cleans out the private object map
(void) session_mgr_logout_all();
// Clean out the public object map
// First parm is no longer used..
// This should clear the entire session list out
(void) session_mgr_close_all_sessions();
next_session_handle = 1;
next_object_handle = 1;
while (priv_token_obj_list) {
}
while (publ_token_obj_list) {
}
}
#define SESS_SET \
static CK_RV
{
CK_ULONG i;
for (i = 0; i < mech_list_len; i++) {
return (CKR_OK);
}
}
return (CKR_MECHANISM_INVALID);
}
#define VALID_MECH(p) \
if (validate_mechanism(p) != CKR_OK) { \
rc = CKR_MECHANISM_INVALID; \
goto done; \
}
unsigned char *Correlator)
{
stlogterm();
stloginit();
if (st_Initialized() == TRUE) {
return (CKR_OK);
}
// assume that the upper API prevents multiple calls of initialize
// since that only happens on C_Initialize and that is the
// responsibility of the upper layer..
initialized = FALSE;
// check for other completing this before creating mutexes...
// make sure that the same process tried to to the init...
// thread issues should be caught up above...
if (st_Initialized() == TRUE) {
goto done;
}
if (st_Initialized() == FALSE) {
goto done;
initialized = TRUE;
(*flist) = function_list;
/* Always call the token_specific_init function.... */
&hContext);
if (rc != 0) {
/*
* The token could not be initialized, return OK, but
* present no slots.
*/
goto done;
} else {
/* Mark the token as available */
}
}
goto done;
}
goto done;
(void) XProcUnLock(xproclock);
done:
if (hContext)
return (rc);
}
/*ARGSUSED*/
{
if (st_Initialized() == FALSE) {
return (CKR_CRYPTOKI_NOT_INITIALIZED);
}
return (rc);
}
//
// If somebody else has taken care of things, leave...
//
if (st_Initialized() == FALSE) {
(void) pthread_mutex_unlock(&pkcs_mutex);
return (CKR_CRYPTOKI_NOT_INITIALIZED);
}
if (open_tss_context(&hContext) == 0) {
(void) session_mgr_close_all_sessions();
(void) object_mgr_purge_token_objects(hContext);
(void) Tspi_Context_Close(hContext);
}
(void) detach_shm();
initialized = FALSE;
return (rc);
}
return (CKR_OK);
}
/*ARGSUSED*/
{
if (st_Initialized() == FALSE)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_FUNCTION_FAILED);
if (sid != TPM_SLOTID)
return (CKR_SLOT_ID_INVALID);
sizeof (CK_TOKEN_INFO));
return (rc);
}
/*ARGSUSED*/
{
CK_ULONG i;
if (st_Initialized() == FALSE) {
goto done;
}
goto done;
}
if (sid != TPM_SLOTID) {
goto done;
}
*count = mech_list_len;
goto done;
}
if (*count < mech_list_len) {
*count = mech_list_len;
goto done;
}
for (i = 0; i < mech_list_len; i++)
*count = mech_list_len;
done:
if (debugfile) {
"% - 25s: rc = 0x%08x, # mechanisms: %d\n",
}
return (rc);
}
/*ARGSUSED*/
{
CK_ULONG i;
if (st_Initialized() == FALSE) {
goto done;
}
goto done;
}
if (sid != TPM_SLOTID) {
goto done;
}
for (i = 0; i < mech_list_len; i++) {
sizeof (CK_MECHANISM_INFO));
goto done;
}
}
done:
if (debugfile) {
"rc = 0x%08x, mech type = 0x%08x\n",
}
return (rc);
}
/*ARGSUSED*/
{
if (st_Initialized() == FALSE) {
goto done;
}
if (sid != TPM_SLOTID) {
goto done;
}
goto done;
}
if (open_tss_context(&hContext)) {
goto done;
}
goto done;
}
rc = CKR_PIN_LOCKED;
goto done;
}
goto done;
}
/*
* Before we reconstruct all the data, we should delete the
* token objects from the filesystem.
*
* Construct a string to delete the token objects.
*/
(void) object_mgr_destroy_token_objects(hContext);
(void) init_slot_info(&newtoken);
/* change the label */
done:
if (hContext)
(void) Tspi_Context_Close(hContext);
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pPin) {
goto done;
}
if (! sess) {
goto done;
}
rc = CKR_PIN_LOCKED;
goto done;
}
goto done;
}
*flags &= ~(CKF_USER_PIN_LOCKED |
goto done;
}
}
done:
if (debugfile) {
}
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
rc = CKR_PIN_LOCKED;
goto done;
}
done:
if (debugfile) {
}
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if ((flags & CKF_RW_SESSION) == 0) {
if (session_mgr_so_session_exists()) {
return (CKR_SESSION_READ_WRITE_SO_EXISTS);
}
}
if (sid != TPM_SLOTID) {
goto done;
}
if (open_tss_context(&hContext)) {
goto done;
}
(void) pthread_mutex_unlock(&pkcs_mutex);
goto done;
}
(void) pthread_mutex_unlock(&pkcs_mutex);
goto done;
}
/* Open a new context for each session */
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (!sess) {
goto done;
}
}
done:
return (rc);
}
/*ARGSUSED*/
{
if (st_Initialized() == FALSE)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
if (sid != TPM_SLOTID)
return (CKR_SLOT_ID_INVALID);
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pInfo) {
goto done;
}
if (! sess) {
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pulOperationStateLen) {
goto done;
}
if (! pOperationState)
length_only = TRUE;
if (! sess) {
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
return (CKR_CRYPTOKI_NOT_INITIALIZED);
}
if (!pOperationState || (ulOperationStateLen == 0)) {
return (CKR_ARGUMENTS_BAD);
}
if (! sess) {
return (CKR_SESSION_HANDLE_INVALID);
}
return (rc);
}
{
// In v2.11, logins should be exclusive, since token
// specific flags may need to be set for a bad login. - KEY
return (CKR_FUNCTION_FAILED);
}
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
/*
* PKCS #11 v2.01 requires that all sessions have the same login status:
* --> all sessions are public, all are SO or all are USER
*/
if (session_mgr_so_session_exists()) {
}
if (session_mgr_user_session_exists()) {
}
if (session_mgr_user_session_exists()) {
}
if (session_mgr_so_session_exists()) {
}
if (session_mgr_readonly_exists()) {
}
} else {
}
goto done;
} else {
}
rc = CKR_PIN_LOCKED;
goto done;
}
/* call the pluggable login function here */
} else if (rc == CKR_PIN_INCORRECT) {
goto done;
} else {
goto done;
}
done:
(void) pthread_mutex_unlock(&login_mutex);
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
// all sessions have the same state so we just have to check one
//
if (session_mgr_public_session_exists()) {
goto done;
}
(void) session_mgr_logout_all();
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! phObject || ! pulObjectCount) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
count * sizeof (CK_OBJECT_HANDLE));
*pulObjectCount = count;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
pMechanism, hKey);
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
if (! pData || ! pulEncryptedDataLen) {
goto done;
}
goto done;
}
if (! pEncryptedData)
length_only = TRUE;
done:
return (rc);
}
#if 0
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pPart || ! pulEncryptedPartLen) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
if (! pEncryptedPart)
length_only = TRUE;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pulLastEncryptedPartLen) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
if (! pLastEncryptedPart)
length_only = TRUE;
done:
return (rc);
}
#endif
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
if (! pEncryptedData || ! pulDataLen) {
goto done;
}
goto done;
}
if (! pData)
length_only = TRUE;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
if (! pData || ! pulDigestLen) {
goto done;
}
goto done;
}
if (! pDigest)
length_only = TRUE;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
if (pPart) {
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pulDigestLen) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
if (! pDigest)
length_only = TRUE;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
if (!pData || !pulSignatureLen) {
goto done;
}
goto done;
}
if (! pSignature)
length_only = TRUE;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pPart) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pulSignatureLen) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
if (! pSignature)
length_only = TRUE;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
if (!pData || !pulSignatureLen) {
goto done;
}
goto done;
}
if (! pSignature)
length_only = TRUE;
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
if (! pData || ! pSignature) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pPart) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pSignature) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! sess) {
goto done;
}
if (!pSignature || !pulDataLen) {
goto done;
}
goto done;
}
if (! pData)
length_only = TRUE;
pData, pulDataLen);
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
(! pPublicKeyTemplate && (ulPublicKeyAttributeCount != 0)) ||
(! pPrivateKeyTemplate && (ulPrivateKeyAttributeCount != 0))) {
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism || ! pulWrappedKeyLen) {
goto done;
}
if (! pWrappedKey)
length_only = TRUE;
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pMechanism || ! pWrappedKey ||
goto done;
}
if (! sess) {
goto done;
}
goto done;
}
done:
return (rc);
}
/*ARGSUSED*/
{
if (st_Initialized() == FALSE) {
return (CKR_CRYPTOKI_NOT_INITIALIZED);
}
return (CKR_ARGUMENTS_BAD);
return (CKR_OK);
}
{
if (st_Initialized() == FALSE) {
goto done;
}
if (! pRandomData && ulRandomLen != 0) {
goto done;
}
if (! sess) {
goto done;
}
done:
return (rc);
}
void
SC_SetFunctionList(void) {
}