1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <pthread.h> 30*7c478bd9Sstevel@tonic-gate #include <security/cryptoki.h> 31*7c478bd9Sstevel@tonic-gate #include "pkcs11Global.h" 32*7c478bd9Sstevel@tonic-gate #include "pkcs11Session.h" 33*7c478bd9Sstevel@tonic-gate #include "pkcs11Slot.h" 34*7c478bd9Sstevel@tonic-gate #include "metaGlobal.h" 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * C_OpenSession will need to create a pseudo session associated 38*7c478bd9Sstevel@tonic-gate * with the session created by the plugged in provider. Only 39*7c478bd9Sstevel@tonic-gate * minimal argument checking is done here, as we rely on the 40*7c478bd9Sstevel@tonic-gate * underlying provider to catch most errors. 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate CK_RV 43*7c478bd9Sstevel@tonic-gate C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, 44*7c478bd9Sstevel@tonic-gate CK_NOTIFY Notify, CK_SESSION_HANDLE_PTR phSession) 45*7c478bd9Sstevel@tonic-gate { 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate CK_RV rv; 48*7c478bd9Sstevel@tonic-gate CK_SLOT_ID true_id; 49*7c478bd9Sstevel@tonic-gate CK_SLOT_ID fw_st_id; /* id for accessing framework's slottable */ 50*7c478bd9Sstevel@tonic-gate CK_SESSION_HANDLE prov_sess; 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 53*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 54*7c478bd9Sstevel@tonic-gate } 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 57*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 58*7c478bd9Sstevel@tonic-gate if (metaslot_enabled) { 59*7c478bd9Sstevel@tonic-gate /* 60*7c478bd9Sstevel@tonic-gate * if metaslot is enabled and we are in fastpath 61*7c478bd9Sstevel@tonic-gate * mode, only one other slot is in the framework 62*7c478bd9Sstevel@tonic-gate * so, need to go to that slot's entry 63*7c478bd9Sstevel@tonic-gate * to look up the true slot ID for the slot 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_OpenSession(TRUEID(slotID+1), 66*7c478bd9Sstevel@tonic-gate flags, pApplication, Notify, phSession)); 67*7c478bd9Sstevel@tonic-gate } else { 68*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_OpenSession(slotID, flags, 69*7c478bd9Sstevel@tonic-gate pApplication, Notify, phSession)); 70*7c478bd9Sstevel@tonic-gate } 71*7c478bd9Sstevel@tonic-gate } 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate if (slotID == METASLOT_FRAMEWORK_ID) { 75*7c478bd9Sstevel@tonic-gate rv = meta_OpenSession(METASLOT_SLOTID, flags, 76*7c478bd9Sstevel@tonic-gate pApplication, Notify, &prov_sess); 77*7c478bd9Sstevel@tonic-gate } else { 78*7c478bd9Sstevel@tonic-gate /* Check that slotID is valid */ 79*7c478bd9Sstevel@tonic-gate if (pkcs11_validate_and_convert_slotid(slotID, &fw_st_id) 80*7c478bd9Sstevel@tonic-gate != CKR_OK) { 81*7c478bd9Sstevel@tonic-gate return (CKR_SLOT_ID_INVALID); 82*7c478bd9Sstevel@tonic-gate } 83*7c478bd9Sstevel@tonic-gate true_id = TRUEID(fw_st_id); 84*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(fw_st_id)->C_OpenSession(true_id, flags, 85*7c478bd9Sstevel@tonic-gate pApplication, Notify, &prov_sess); 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate /* Present consistent interface for framework */ 89*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 90*7c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED); 91*7c478bd9Sstevel@tonic-gate } else if (rv != CKR_OK) { 92*7c478bd9Sstevel@tonic-gate /* could not create session with provider, return now */ 93*7c478bd9Sstevel@tonic-gate return (rv); 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate /* Provider was successful, now create session in framework */ 97*7c478bd9Sstevel@tonic-gate if (slotID == METASLOT_FRAMEWORK_ID) { 98*7c478bd9Sstevel@tonic-gate rv = pkcs11_session_add( 99*7c478bd9Sstevel@tonic-gate slottable->st_slots[METASLOT_FRAMEWORK_ID], 100*7c478bd9Sstevel@tonic-gate METASLOT_FRAMEWORK_ID, phSession, prov_sess); 101*7c478bd9Sstevel@tonic-gate } else { 102*7c478bd9Sstevel@tonic-gate rv = pkcs11_session_add(slottable->st_slots[fw_st_id], 103*7c478bd9Sstevel@tonic-gate fw_st_id, phSession, prov_sess); 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 107*7c478bd9Sstevel@tonic-gate /* Trouble in the framework, clean up provider session */ 108*7c478bd9Sstevel@tonic-gate FUNCLIST(slotID)->C_CloseSession(prov_sess); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate return (rv); 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate /* 114*7c478bd9Sstevel@tonic-gate * C_CloseSession will close a session with the underlying provider, 115*7c478bd9Sstevel@tonic-gate * and if that's successful will close it in the framework. 116*7c478bd9Sstevel@tonic-gate */ 117*7c478bd9Sstevel@tonic-gate CK_RV 118*7c478bd9Sstevel@tonic-gate C_CloseSession(CK_SESSION_HANDLE hSession) 119*7c478bd9Sstevel@tonic-gate { 120*7c478bd9Sstevel@tonic-gate CK_RV rv; 121*7c478bd9Sstevel@tonic-gate pkcs11_session_t *sessp; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 124*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 125*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_CloseSession(hSession)); 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 129*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* Obtain the session pointer */ 133*7c478bd9Sstevel@tonic-gate HANDLE2SESSION(hSession, sessp, rv); 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 136*7c478bd9Sstevel@tonic-gate return (rv); 137*7c478bd9Sstevel@tonic-gate } 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate /* Delete the session with the provider */ 140*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(sessp->se_slotid)->C_CloseSession(sessp->se_handle); 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate /* Present consistent interface for framework */ 143*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 144*7c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED); 145*7c478bd9Sstevel@tonic-gate } else if (rv != CKR_OK) { 146*7c478bd9Sstevel@tonic-gate /* could not delete session with provider, return now */ 147*7c478bd9Sstevel@tonic-gate return (rv); 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate /* Delete session from the framework */ 151*7c478bd9Sstevel@tonic-gate pkcs11_session_delete(slottable->st_slots[sessp->se_slotid], sessp); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate return (rv); 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate /* 157*7c478bd9Sstevel@tonic-gate * C_CloseAllSessions will close all sessions associated with this 158*7c478bd9Sstevel@tonic-gate * slot with the underlying provider. If that is successful, will 159*7c478bd9Sstevel@tonic-gate * close the associated sessions in the framework. If the provider 160*7c478bd9Sstevel@tonic-gate * has not implemented C_CloseAllSessions, then we will loop through 161*7c478bd9Sstevel@tonic-gate * the list of sessions and individually call C_CloseSession. 162*7c478bd9Sstevel@tonic-gate */ 163*7c478bd9Sstevel@tonic-gate CK_RV 164*7c478bd9Sstevel@tonic-gate C_CloseAllSessions(CK_SLOT_ID slotID) 165*7c478bd9Sstevel@tonic-gate { 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate CK_RV rv, rv1; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate CK_SLOT_ID true_id; 170*7c478bd9Sstevel@tonic-gate CK_SLOT_ID fw_st_id; /* id for accessing framework's slottable */ 171*7c478bd9Sstevel@tonic-gate pkcs11_session_t *sessp, *sess_nextp; 172*7c478bd9Sstevel@tonic-gate pkcs11_slot_t *slotp; 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 175*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 179*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 180*7c478bd9Sstevel@tonic-gate if (metaslot_enabled) { 181*7c478bd9Sstevel@tonic-gate /* 182*7c478bd9Sstevel@tonic-gate * if metaslot is enabled and we are in fastpath 183*7c478bd9Sstevel@tonic-gate * mode, only one other slot is in the framework 184*7c478bd9Sstevel@tonic-gate * so, need to go to that slot's entry 185*7c478bd9Sstevel@tonic-gate * to look up the true slot ID for the slot 186*7c478bd9Sstevel@tonic-gate */ 187*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_CloseAllSessions( 188*7c478bd9Sstevel@tonic-gate TRUEID(slotID+1))); 189*7c478bd9Sstevel@tonic-gate } else { 190*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_CloseAllSessions(slotID)); 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate /* Check that slotID is valid */ 195*7c478bd9Sstevel@tonic-gate if (pkcs11_validate_and_convert_slotid(slotID, &fw_st_id) != CKR_OK) { 196*7c478bd9Sstevel@tonic-gate return (CKR_SLOT_ID_INVALID); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate slotp = slottable->st_slots[fw_st_id]; 200*7c478bd9Sstevel@tonic-gate true_id = TRUEID(fw_st_id); 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(fw_st_id)->C_CloseAllSessions(true_id); 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate /* Present consistent interface for framework */ 205*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 206*7c478bd9Sstevel@tonic-gate /* Need to attempt to individually delete sessions */ 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate /* reset rv */ 209*7c478bd9Sstevel@tonic-gate rv = CKR_OK; 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&slotp->sl_mutex); 212*7c478bd9Sstevel@tonic-gate sessp = slotp->sl_sess_list; 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate while (sessp) { 215*7c478bd9Sstevel@tonic-gate sess_nextp = sessp->se_next; 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate rv1 = FUNCLIST(fw_st_id)-> 218*7c478bd9Sstevel@tonic-gate C_CloseSession(sessp->se_handle); 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate /* Record the first error encountered */ 221*7c478bd9Sstevel@tonic-gate if ((rv == CKR_OK) && (rv1 != CKR_OK)) { 222*7c478bd9Sstevel@tonic-gate rv = rv1; 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate sessp = sess_nextp; 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&slotp->sl_mutex); 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 232*7c478bd9Sstevel@tonic-gate /* could not delete sessionlist with provider, return now */ 233*7c478bd9Sstevel@tonic-gate return (rv); 234*7c478bd9Sstevel@tonic-gate } 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate /* Delete sessions from the framework */ 237*7c478bd9Sstevel@tonic-gate pkcs11_sessionlist_delete(slotp); 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate return (rv); 240*7c478bd9Sstevel@tonic-gate } 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate /* 243*7c478bd9Sstevel@tonic-gate * C_GetSessionInfo is a pure wrapper to the underlying provider. 244*7c478bd9Sstevel@tonic-gate * The only argument checked is whether or not hSession is valid. 245*7c478bd9Sstevel@tonic-gate */ 246*7c478bd9Sstevel@tonic-gate CK_RV 247*7c478bd9Sstevel@tonic-gate C_GetSessionInfo(CK_SESSION_HANDLE hSession, CK_SESSION_INFO_PTR pInfo) 248*7c478bd9Sstevel@tonic-gate { 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate CK_RV rv; 251*7c478bd9Sstevel@tonic-gate CK_SLOT_ID slot_id; 252*7c478bd9Sstevel@tonic-gate pkcs11_session_t *sessp; 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 255*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 256*7c478bd9Sstevel@tonic-gate rv = fast_funcs->C_GetSessionInfo(hSession, pInfo); 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate /* 259*7c478bd9Sstevel@tonic-gate * If metaslot is enabled, and we are here, that 260*7c478bd9Sstevel@tonic-gate * that means there's only 1 other slot in the 261*7c478bd9Sstevel@tonic-gate * framework, and that slot should be hidden. 262*7c478bd9Sstevel@tonic-gate * so, override value of slot id to be metaslot's 263*7c478bd9Sstevel@tonic-gate * slot id. 264*7c478bd9Sstevel@tonic-gate */ 265*7c478bd9Sstevel@tonic-gate if (metaslot_enabled) { 266*7c478bd9Sstevel@tonic-gate pInfo->slotID = METASLOT_FRAMEWORK_ID; 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate return (rv); 269*7c478bd9Sstevel@tonic-gate } 270*7c478bd9Sstevel@tonic-gate 271*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 272*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate /* Obtain the session pointer */ 276*7c478bd9Sstevel@tonic-gate HANDLE2SESSION(hSession, sessp, rv); 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 279*7c478bd9Sstevel@tonic-gate return (rv); 280*7c478bd9Sstevel@tonic-gate } 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate /* Find the slot id for the framework */ 283*7c478bd9Sstevel@tonic-gate slot_id = sessp->se_slotid; 284*7c478bd9Sstevel@tonic-gate 285*7c478bd9Sstevel@tonic-gate /* Get session info from the provider */ 286*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(slot_id)-> 287*7c478bd9Sstevel@tonic-gate C_GetSessionInfo(sessp->se_handle, pInfo); 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate /* Present consistent interface to the application */ 290*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 291*7c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED); 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate /* Override value of slot id to framework's */ 295*7c478bd9Sstevel@tonic-gate pInfo->slotID = slot_id; 296*7c478bd9Sstevel@tonic-gate 297*7c478bd9Sstevel@tonic-gate return (rv); 298*7c478bd9Sstevel@tonic-gate } 299*7c478bd9Sstevel@tonic-gate 300*7c478bd9Sstevel@tonic-gate /* 301*7c478bd9Sstevel@tonic-gate * C_GetOperationState is a pure wrapper to the underlying provider. 302*7c478bd9Sstevel@tonic-gate * The only argument checked is whether or not hSession is valid. 303*7c478bd9Sstevel@tonic-gate */ 304*7c478bd9Sstevel@tonic-gate CK_RV 305*7c478bd9Sstevel@tonic-gate C_GetOperationState(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pOperationState, 306*7c478bd9Sstevel@tonic-gate CK_ULONG_PTR pulOperationStateLen) 307*7c478bd9Sstevel@tonic-gate { 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate CK_RV rv; 310*7c478bd9Sstevel@tonic-gate pkcs11_session_t *sessp; 311*7c478bd9Sstevel@tonic-gate 312*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 313*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 314*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_GetOperationState(hSession, 315*7c478bd9Sstevel@tonic-gate pOperationState, pulOperationStateLen)); 316*7c478bd9Sstevel@tonic-gate } 317*7c478bd9Sstevel@tonic-gate 318*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 319*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 320*7c478bd9Sstevel@tonic-gate } 321*7c478bd9Sstevel@tonic-gate 322*7c478bd9Sstevel@tonic-gate /* Obtain the session pointer */ 323*7c478bd9Sstevel@tonic-gate HANDLE2SESSION(hSession, sessp, rv); 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 326*7c478bd9Sstevel@tonic-gate return (rv); 327*7c478bd9Sstevel@tonic-gate } 328*7c478bd9Sstevel@tonic-gate 329*7c478bd9Sstevel@tonic-gate /* Get the operation state with the provider */ 330*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(sessp->se_slotid)->C_GetOperationState(sessp->se_handle, 331*7c478bd9Sstevel@tonic-gate pOperationState, pulOperationStateLen); 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate /* Present consistent interface to the application */ 334*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 335*7c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED); 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate return (rv); 339*7c478bd9Sstevel@tonic-gate } 340*7c478bd9Sstevel@tonic-gate 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate /* 343*7c478bd9Sstevel@tonic-gate * C_SetOperationState is a pure wrapper to the underlying provider. 344*7c478bd9Sstevel@tonic-gate * The only argument checked is whether or not hSession is valid. 345*7c478bd9Sstevel@tonic-gate */ 346*7c478bd9Sstevel@tonic-gate CK_RV 347*7c478bd9Sstevel@tonic-gate C_SetOperationState(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pOperationState, 348*7c478bd9Sstevel@tonic-gate CK_ULONG ulOperationStateLen, CK_OBJECT_HANDLE hEncryptionKey, 349*7c478bd9Sstevel@tonic-gate CK_OBJECT_HANDLE hAuthenticationKey) 350*7c478bd9Sstevel@tonic-gate { 351*7c478bd9Sstevel@tonic-gate CK_RV rv; 352*7c478bd9Sstevel@tonic-gate pkcs11_session_t *sessp; 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 355*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 356*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_SetOperationState(hSession, 357*7c478bd9Sstevel@tonic-gate pOperationState, ulOperationStateLen, 358*7c478bd9Sstevel@tonic-gate hEncryptionKey, hAuthenticationKey)); 359*7c478bd9Sstevel@tonic-gate } 360*7c478bd9Sstevel@tonic-gate 361*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 362*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 363*7c478bd9Sstevel@tonic-gate } 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate /* Obtain the session pointer */ 366*7c478bd9Sstevel@tonic-gate HANDLE2SESSION(hSession, sessp, rv); 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 369*7c478bd9Sstevel@tonic-gate return (rv); 370*7c478bd9Sstevel@tonic-gate } 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate /* Set the operation state with the provider */ 373*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(sessp->se_slotid)->C_SetOperationState(sessp->se_handle, 374*7c478bd9Sstevel@tonic-gate pOperationState, ulOperationStateLen, hEncryptionKey, 375*7c478bd9Sstevel@tonic-gate hAuthenticationKey); 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate /* Present consistent interface to the application */ 378*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 379*7c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED); 380*7c478bd9Sstevel@tonic-gate } 381*7c478bd9Sstevel@tonic-gate 382*7c478bd9Sstevel@tonic-gate return (rv); 383*7c478bd9Sstevel@tonic-gate } 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate /* 387*7c478bd9Sstevel@tonic-gate * C_Login is a pure wrapper to the underlying provider. 388*7c478bd9Sstevel@tonic-gate * The only argument checked is whether or not hSession is valid. 389*7c478bd9Sstevel@tonic-gate */ 390*7c478bd9Sstevel@tonic-gate CK_RV 391*7c478bd9Sstevel@tonic-gate C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, 392*7c478bd9Sstevel@tonic-gate CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) 393*7c478bd9Sstevel@tonic-gate { 394*7c478bd9Sstevel@tonic-gate CK_RV rv; 395*7c478bd9Sstevel@tonic-gate pkcs11_session_t *sessp; 396*7c478bd9Sstevel@tonic-gate 397*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 398*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 399*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_Login(hSession, userType, pPin, 400*7c478bd9Sstevel@tonic-gate ulPinLen)); 401*7c478bd9Sstevel@tonic-gate } 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 404*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 405*7c478bd9Sstevel@tonic-gate } 406*7c478bd9Sstevel@tonic-gate 407*7c478bd9Sstevel@tonic-gate /* Obtain the session pointer */ 408*7c478bd9Sstevel@tonic-gate HANDLE2SESSION(hSession, sessp, rv); 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 411*7c478bd9Sstevel@tonic-gate return (rv); 412*7c478bd9Sstevel@tonic-gate } 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate /* Login with the provider */ 415*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(sessp->se_slotid)->C_Login(sessp->se_handle, 416*7c478bd9Sstevel@tonic-gate userType, pPin, ulPinLen); 417*7c478bd9Sstevel@tonic-gate 418*7c478bd9Sstevel@tonic-gate /* Present consistent interface to the application */ 419*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 420*7c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED); 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate 423*7c478bd9Sstevel@tonic-gate return (rv); 424*7c478bd9Sstevel@tonic-gate } 425*7c478bd9Sstevel@tonic-gate 426*7c478bd9Sstevel@tonic-gate /* 427*7c478bd9Sstevel@tonic-gate * C_Logout is a pure wrapper to the underlying provider. 428*7c478bd9Sstevel@tonic-gate * The only argument checked is whether or not hSession is valid. 429*7c478bd9Sstevel@tonic-gate */ 430*7c478bd9Sstevel@tonic-gate CK_RV 431*7c478bd9Sstevel@tonic-gate C_Logout(CK_SESSION_HANDLE hSession) 432*7c478bd9Sstevel@tonic-gate { 433*7c478bd9Sstevel@tonic-gate CK_RV rv; 434*7c478bd9Sstevel@tonic-gate pkcs11_session_t *sessp; 435*7c478bd9Sstevel@tonic-gate 436*7c478bd9Sstevel@tonic-gate /* Check for a fastpath */ 437*7c478bd9Sstevel@tonic-gate if (purefastpath || policyfastpath) { 438*7c478bd9Sstevel@tonic-gate return (fast_funcs->C_Logout(hSession)); 439*7c478bd9Sstevel@tonic-gate } 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate if (!pkcs11_initialized) { 442*7c478bd9Sstevel@tonic-gate return (CKR_CRYPTOKI_NOT_INITIALIZED); 443*7c478bd9Sstevel@tonic-gate } 444*7c478bd9Sstevel@tonic-gate 445*7c478bd9Sstevel@tonic-gate /* Obtain the session pointer */ 446*7c478bd9Sstevel@tonic-gate HANDLE2SESSION(hSession, sessp, rv); 447*7c478bd9Sstevel@tonic-gate 448*7c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 449*7c478bd9Sstevel@tonic-gate return (rv); 450*7c478bd9Sstevel@tonic-gate } 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate rv = FUNCLIST(sessp->se_slotid)->C_Logout(sessp->se_handle); 453*7c478bd9Sstevel@tonic-gate 454*7c478bd9Sstevel@tonic-gate /* Present consistent interface to the application */ 455*7c478bd9Sstevel@tonic-gate if (rv == CKR_FUNCTION_NOT_SUPPORTED) { 456*7c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED); 457*7c478bd9Sstevel@tonic-gate } 458*7c478bd9Sstevel@tonic-gate 459*7c478bd9Sstevel@tonic-gate return (rv); 460*7c478bd9Sstevel@tonic-gate } 461