Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* |
michael@0 | 6 | * instance.c |
michael@0 | 7 | * |
michael@0 | 8 | * This file implements the NSSCKFWInstance type and methods. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef CK_T |
michael@0 | 12 | #include "ck.h" |
michael@0 | 13 | #endif /* CK_T */ |
michael@0 | 14 | |
michael@0 | 15 | /* |
michael@0 | 16 | * NSSCKFWInstance |
michael@0 | 17 | * |
michael@0 | 18 | * -- create/destroy -- |
michael@0 | 19 | * nssCKFWInstance_Create |
michael@0 | 20 | * nssCKFWInstance_Destroy |
michael@0 | 21 | * |
michael@0 | 22 | * -- public accessors -- |
michael@0 | 23 | * NSSCKFWInstance_GetMDInstance |
michael@0 | 24 | * NSSCKFWInstance_GetArena |
michael@0 | 25 | * NSSCKFWInstance_MayCreatePthreads |
michael@0 | 26 | * NSSCKFWInstance_CreateMutex |
michael@0 | 27 | * NSSCKFWInstance_GetConfigurationData |
michael@0 | 28 | * NSSCKFWInstance_GetInitArgs |
michael@0 | 29 | * |
michael@0 | 30 | * -- implement public accessors -- |
michael@0 | 31 | * nssCKFWInstance_GetMDInstance |
michael@0 | 32 | * nssCKFWInstance_GetArena |
michael@0 | 33 | * nssCKFWInstance_MayCreatePthreads |
michael@0 | 34 | * nssCKFWInstance_CreateMutex |
michael@0 | 35 | * nssCKFWInstance_GetConfigurationData |
michael@0 | 36 | * nssCKFWInstance_GetInitArgs |
michael@0 | 37 | * |
michael@0 | 38 | * -- private accessors -- |
michael@0 | 39 | * nssCKFWInstance_CreateSessionHandle |
michael@0 | 40 | * nssCKFWInstance_ResolveSessionHandle |
michael@0 | 41 | * nssCKFWInstance_DestroySessionHandle |
michael@0 | 42 | * nssCKFWInstance_FindSessionHandle |
michael@0 | 43 | * nssCKFWInstance_CreateObjectHandle |
michael@0 | 44 | * nssCKFWInstance_ResolveObjectHandle |
michael@0 | 45 | * nssCKFWInstance_DestroyObjectHandle |
michael@0 | 46 | * |
michael@0 | 47 | * -- module fronts -- |
michael@0 | 48 | * nssCKFWInstance_GetNSlots |
michael@0 | 49 | * nssCKFWInstance_GetCryptokiVersion |
michael@0 | 50 | * nssCKFWInstance_GetManufacturerID |
michael@0 | 51 | * nssCKFWInstance_GetFlags |
michael@0 | 52 | * nssCKFWInstance_GetLibraryDescription |
michael@0 | 53 | * nssCKFWInstance_GetLibraryVersion |
michael@0 | 54 | * nssCKFWInstance_GetModuleHandlesSessionObjects |
michael@0 | 55 | * nssCKFWInstance_GetSlots |
michael@0 | 56 | * nssCKFWInstance_WaitForSlotEvent |
michael@0 | 57 | * |
michael@0 | 58 | * -- debugging versions only -- |
michael@0 | 59 | * nssCKFWInstance_verifyPointer |
michael@0 | 60 | */ |
michael@0 | 61 | |
michael@0 | 62 | struct NSSCKFWInstanceStr { |
michael@0 | 63 | NSSCKFWMutex *mutex; |
michael@0 | 64 | NSSArena *arena; |
michael@0 | 65 | NSSCKMDInstance *mdInstance; |
michael@0 | 66 | CK_C_INITIALIZE_ARGS_PTR pInitArgs; |
michael@0 | 67 | CK_C_INITIALIZE_ARGS initArgs; |
michael@0 | 68 | CryptokiLockingState LockingState; |
michael@0 | 69 | CK_BBOOL mayCreatePthreads; |
michael@0 | 70 | NSSUTF8 *configurationData; |
michael@0 | 71 | CK_ULONG nSlots; |
michael@0 | 72 | NSSCKFWSlot **fwSlotList; |
michael@0 | 73 | NSSCKMDSlot **mdSlotList; |
michael@0 | 74 | CK_BBOOL moduleHandlesSessionObjects; |
michael@0 | 75 | |
michael@0 | 76 | /* |
michael@0 | 77 | * Everything above is set at creation time, and then not modified. |
michael@0 | 78 | * The invariants the mutex protects are: |
michael@0 | 79 | * |
michael@0 | 80 | * 1) Each of the cached descriptions (versions, etc.) are in an |
michael@0 | 81 | * internally consistant state. |
michael@0 | 82 | * |
michael@0 | 83 | * 2) The session handle hashes and count are consistant |
michael@0 | 84 | * |
michael@0 | 85 | * 3) The object handle hashes and count are consistant. |
michael@0 | 86 | * |
michael@0 | 87 | * I could use multiple locks, but let's wait to see if that's |
michael@0 | 88 | * really necessary. |
michael@0 | 89 | * |
michael@0 | 90 | * Note that the calls accessing the cached descriptions will |
michael@0 | 91 | * call the NSSCKMDInstance methods with the mutex locked. Those |
michael@0 | 92 | * methods may then call the public NSSCKFWInstance routines. |
michael@0 | 93 | * Those public routines only access the constant data above, so |
michael@0 | 94 | * there's no problem. But be careful if you add to this object; |
michael@0 | 95 | * mutexes are in general not reentrant, so don't create deadlock |
michael@0 | 96 | * situations. |
michael@0 | 97 | */ |
michael@0 | 98 | |
michael@0 | 99 | CK_VERSION cryptokiVersion; |
michael@0 | 100 | NSSUTF8 *manufacturerID; |
michael@0 | 101 | NSSUTF8 *libraryDescription; |
michael@0 | 102 | CK_VERSION libraryVersion; |
michael@0 | 103 | |
michael@0 | 104 | CK_ULONG lastSessionHandle; |
michael@0 | 105 | nssCKFWHash *sessionHandleHash; |
michael@0 | 106 | |
michael@0 | 107 | CK_ULONG lastObjectHandle; |
michael@0 | 108 | nssCKFWHash *objectHandleHash; |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | #ifdef DEBUG |
michael@0 | 112 | /* |
michael@0 | 113 | * But first, the pointer-tracking stuff. |
michael@0 | 114 | * |
michael@0 | 115 | * NOTE: the pointer-tracking support in NSS/base currently relies |
michael@0 | 116 | * upon NSPR's CallOnce support. That, however, relies upon NSPR's |
michael@0 | 117 | * locking, which is tied into the runtime. We need a pointer-tracker |
michael@0 | 118 | * implementation that uses the locks supplied through C_Initialize. |
michael@0 | 119 | * That support, however, can be filled in later. So for now, I'll |
michael@0 | 120 | * just do this routines as no-ops. |
michael@0 | 121 | */ |
michael@0 | 122 | |
michael@0 | 123 | static CK_RV |
michael@0 | 124 | instance_add_pointer |
michael@0 | 125 | ( |
michael@0 | 126 | const NSSCKFWInstance *fwInstance |
michael@0 | 127 | ) |
michael@0 | 128 | { |
michael@0 | 129 | return CKR_OK; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | static CK_RV |
michael@0 | 133 | instance_remove_pointer |
michael@0 | 134 | ( |
michael@0 | 135 | const NSSCKFWInstance *fwInstance |
michael@0 | 136 | ) |
michael@0 | 137 | { |
michael@0 | 138 | return CKR_OK; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | NSS_IMPLEMENT CK_RV |
michael@0 | 142 | nssCKFWInstance_verifyPointer |
michael@0 | 143 | ( |
michael@0 | 144 | const NSSCKFWInstance *fwInstance |
michael@0 | 145 | ) |
michael@0 | 146 | { |
michael@0 | 147 | return CKR_OK; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | #endif /* DEBUG */ |
michael@0 | 151 | |
michael@0 | 152 | /* |
michael@0 | 153 | * nssCKFWInstance_Create |
michael@0 | 154 | * |
michael@0 | 155 | */ |
michael@0 | 156 | NSS_IMPLEMENT NSSCKFWInstance * |
michael@0 | 157 | nssCKFWInstance_Create |
michael@0 | 158 | ( |
michael@0 | 159 | CK_C_INITIALIZE_ARGS_PTR pInitArgs, |
michael@0 | 160 | CryptokiLockingState LockingState, |
michael@0 | 161 | NSSCKMDInstance *mdInstance, |
michael@0 | 162 | CK_RV *pError |
michael@0 | 163 | ) |
michael@0 | 164 | { |
michael@0 | 165 | NSSCKFWInstance *fwInstance; |
michael@0 | 166 | NSSArena *arena = (NSSArena *)NULL; |
michael@0 | 167 | CK_ULONG i; |
michael@0 | 168 | CK_BBOOL called_Initialize = CK_FALSE; |
michael@0 | 169 | |
michael@0 | 170 | #ifdef NSSDEBUG |
michael@0 | 171 | if( (CK_RV)NULL == pError ) { |
michael@0 | 172 | return (NSSCKFWInstance *)NULL; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | if (!mdInstance) { |
michael@0 | 176 | *pError = CKR_ARGUMENTS_BAD; |
michael@0 | 177 | return (NSSCKFWInstance *)NULL; |
michael@0 | 178 | } |
michael@0 | 179 | #endif /* NSSDEBUG */ |
michael@0 | 180 | |
michael@0 | 181 | arena = NSSArena_Create(); |
michael@0 | 182 | if (!arena) { |
michael@0 | 183 | *pError = CKR_HOST_MEMORY; |
michael@0 | 184 | return (NSSCKFWInstance *)NULL; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | fwInstance = nss_ZNEW(arena, NSSCKFWInstance); |
michael@0 | 188 | if (!fwInstance) { |
michael@0 | 189 | goto nomem; |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | fwInstance->arena = arena; |
michael@0 | 193 | fwInstance->mdInstance = mdInstance; |
michael@0 | 194 | |
michael@0 | 195 | fwInstance->LockingState = LockingState; |
michael@0 | 196 | if( (CK_C_INITIALIZE_ARGS_PTR)NULL != pInitArgs ) { |
michael@0 | 197 | fwInstance->initArgs = *pInitArgs; |
michael@0 | 198 | fwInstance->pInitArgs = &fwInstance->initArgs; |
michael@0 | 199 | if( pInitArgs->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS ) { |
michael@0 | 200 | fwInstance->mayCreatePthreads = CK_FALSE; |
michael@0 | 201 | } else { |
michael@0 | 202 | fwInstance->mayCreatePthreads = CK_TRUE; |
michael@0 | 203 | } |
michael@0 | 204 | fwInstance->configurationData = (NSSUTF8 *)(pInitArgs->pReserved); |
michael@0 | 205 | } else { |
michael@0 | 206 | fwInstance->mayCreatePthreads = CK_TRUE; |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | fwInstance->mutex = nssCKFWMutex_Create(pInitArgs, LockingState, arena, |
michael@0 | 210 | pError); |
michael@0 | 211 | if (!fwInstance->mutex) { |
michael@0 | 212 | if( CKR_OK == *pError ) { |
michael@0 | 213 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 214 | } |
michael@0 | 215 | goto loser; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | if (mdInstance->Initialize) { |
michael@0 | 219 | *pError = mdInstance->Initialize(mdInstance, fwInstance, fwInstance->configurationData); |
michael@0 | 220 | if( CKR_OK != *pError ) { |
michael@0 | 221 | goto loser; |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | called_Initialize = CK_TRUE; |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | if (mdInstance->ModuleHandlesSessionObjects) { |
michael@0 | 228 | fwInstance->moduleHandlesSessionObjects = |
michael@0 | 229 | mdInstance->ModuleHandlesSessionObjects(mdInstance, fwInstance); |
michael@0 | 230 | } else { |
michael@0 | 231 | fwInstance->moduleHandlesSessionObjects = CK_FALSE; |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | if (!mdInstance->GetNSlots) { |
michael@0 | 235 | /* That routine is required */ |
michael@0 | 236 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 237 | goto loser; |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | fwInstance->nSlots = mdInstance->GetNSlots(mdInstance, fwInstance, pError); |
michael@0 | 241 | if( (CK_ULONG)0 == fwInstance->nSlots ) { |
michael@0 | 242 | if( CKR_OK == *pError ) { |
michael@0 | 243 | /* Zero is not a legitimate answer */ |
michael@0 | 244 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 245 | } |
michael@0 | 246 | goto loser; |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | fwInstance->fwSlotList = nss_ZNEWARRAY(arena, NSSCKFWSlot *, fwInstance->nSlots); |
michael@0 | 250 | if( (NSSCKFWSlot **)NULL == fwInstance->fwSlotList ) { |
michael@0 | 251 | goto nomem; |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | fwInstance->mdSlotList = nss_ZNEWARRAY(arena, NSSCKMDSlot *, fwInstance->nSlots); |
michael@0 | 255 | if( (NSSCKMDSlot **)NULL == fwInstance->mdSlotList ) { |
michael@0 | 256 | goto nomem; |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | fwInstance->sessionHandleHash = nssCKFWHash_Create(fwInstance, |
michael@0 | 260 | fwInstance->arena, pError); |
michael@0 | 261 | if (!fwInstance->sessionHandleHash) { |
michael@0 | 262 | goto loser; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | fwInstance->objectHandleHash = nssCKFWHash_Create(fwInstance, |
michael@0 | 266 | fwInstance->arena, pError); |
michael@0 | 267 | if (!fwInstance->objectHandleHash) { |
michael@0 | 268 | goto loser; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | if (!mdInstance->GetSlots) { |
michael@0 | 272 | /* That routine is required */ |
michael@0 | 273 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 274 | goto loser; |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | *pError = mdInstance->GetSlots(mdInstance, fwInstance, fwInstance->mdSlotList); |
michael@0 | 278 | if( CKR_OK != *pError ) { |
michael@0 | 279 | goto loser; |
michael@0 | 280 | } |
michael@0 | 281 | |
michael@0 | 282 | for( i = 0; i < fwInstance->nSlots; i++ ) { |
michael@0 | 283 | NSSCKMDSlot *mdSlot = fwInstance->mdSlotList[i]; |
michael@0 | 284 | |
michael@0 | 285 | if (!mdSlot) { |
michael@0 | 286 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 287 | goto loser; |
michael@0 | 288 | } |
michael@0 | 289 | |
michael@0 | 290 | fwInstance->fwSlotList[i] = nssCKFWSlot_Create(fwInstance, mdSlot, i, pError); |
michael@0 | 291 | if( CKR_OK != *pError ) { |
michael@0 | 292 | CK_ULONG j; |
michael@0 | 293 | |
michael@0 | 294 | for( j = 0; j < i; j++ ) { |
michael@0 | 295 | (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[j]); |
michael@0 | 296 | } |
michael@0 | 297 | |
michael@0 | 298 | for( j = i; j < fwInstance->nSlots; j++ ) { |
michael@0 | 299 | NSSCKMDSlot *mds = fwInstance->mdSlotList[j]; |
michael@0 | 300 | if (mds->Destroy) { |
michael@0 | 301 | mds->Destroy(mds, (NSSCKFWSlot *)NULL, mdInstance, fwInstance); |
michael@0 | 302 | } |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | goto loser; |
michael@0 | 306 | } |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | #ifdef DEBUG |
michael@0 | 310 | *pError = instance_add_pointer(fwInstance); |
michael@0 | 311 | if( CKR_OK != *pError ) { |
michael@0 | 312 | for( i = 0; i < fwInstance->nSlots; i++ ) { |
michael@0 | 313 | (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]); |
michael@0 | 314 | } |
michael@0 | 315 | |
michael@0 | 316 | goto loser; |
michael@0 | 317 | } |
michael@0 | 318 | #endif /* DEBUG */ |
michael@0 | 319 | |
michael@0 | 320 | *pError = CKR_OK; |
michael@0 | 321 | return fwInstance; |
michael@0 | 322 | |
michael@0 | 323 | nomem: |
michael@0 | 324 | *pError = CKR_HOST_MEMORY; |
michael@0 | 325 | /*FALLTHROUGH*/ |
michael@0 | 326 | loser: |
michael@0 | 327 | |
michael@0 | 328 | if( CK_TRUE == called_Initialize ) { |
michael@0 | 329 | if (mdInstance->Finalize) { |
michael@0 | 330 | mdInstance->Finalize(mdInstance, fwInstance); |
michael@0 | 331 | } |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | if (fwInstance && fwInstance->mutex) { |
michael@0 | 335 | nssCKFWMutex_Destroy(fwInstance->mutex); |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | if (arena) { |
michael@0 | 339 | (void)NSSArena_Destroy(arena); |
michael@0 | 340 | } |
michael@0 | 341 | return (NSSCKFWInstance *)NULL; |
michael@0 | 342 | } |
michael@0 | 343 | |
michael@0 | 344 | /* |
michael@0 | 345 | * nssCKFWInstance_Destroy |
michael@0 | 346 | * |
michael@0 | 347 | */ |
michael@0 | 348 | NSS_IMPLEMENT CK_RV |
michael@0 | 349 | nssCKFWInstance_Destroy |
michael@0 | 350 | ( |
michael@0 | 351 | NSSCKFWInstance *fwInstance |
michael@0 | 352 | ) |
michael@0 | 353 | { |
michael@0 | 354 | #ifdef NSSDEBUG |
michael@0 | 355 | CK_RV error = CKR_OK; |
michael@0 | 356 | #endif /* NSSDEBUG */ |
michael@0 | 357 | CK_ULONG i; |
michael@0 | 358 | |
michael@0 | 359 | #ifdef NSSDEBUG |
michael@0 | 360 | error = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 361 | if( CKR_OK != error ) { |
michael@0 | 362 | return error; |
michael@0 | 363 | } |
michael@0 | 364 | #endif /* NSSDEBUG */ |
michael@0 | 365 | |
michael@0 | 366 | nssCKFWMutex_Destroy(fwInstance->mutex); |
michael@0 | 367 | |
michael@0 | 368 | for( i = 0; i < fwInstance->nSlots; i++ ) { |
michael@0 | 369 | (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]); |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | if (fwInstance->mdInstance->Finalize) { |
michael@0 | 373 | fwInstance->mdInstance->Finalize(fwInstance->mdInstance, fwInstance); |
michael@0 | 374 | } |
michael@0 | 375 | |
michael@0 | 376 | if (fwInstance->sessionHandleHash) { |
michael@0 | 377 | nssCKFWHash_Destroy(fwInstance->sessionHandleHash); |
michael@0 | 378 | } |
michael@0 | 379 | |
michael@0 | 380 | if (fwInstance->objectHandleHash) { |
michael@0 | 381 | nssCKFWHash_Destroy(fwInstance->objectHandleHash); |
michael@0 | 382 | } |
michael@0 | 383 | |
michael@0 | 384 | #ifdef DEBUG |
michael@0 | 385 | (void)instance_remove_pointer(fwInstance); |
michael@0 | 386 | #endif /* DEBUG */ |
michael@0 | 387 | |
michael@0 | 388 | (void)NSSArena_Destroy(fwInstance->arena); |
michael@0 | 389 | return CKR_OK; |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | /* |
michael@0 | 393 | * nssCKFWInstance_GetMDInstance |
michael@0 | 394 | * |
michael@0 | 395 | */ |
michael@0 | 396 | NSS_IMPLEMENT NSSCKMDInstance * |
michael@0 | 397 | nssCKFWInstance_GetMDInstance |
michael@0 | 398 | ( |
michael@0 | 399 | NSSCKFWInstance *fwInstance |
michael@0 | 400 | ) |
michael@0 | 401 | { |
michael@0 | 402 | #ifdef NSSDEBUG |
michael@0 | 403 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 404 | return (NSSCKMDInstance *)NULL; |
michael@0 | 405 | } |
michael@0 | 406 | #endif /* NSSDEBUG */ |
michael@0 | 407 | |
michael@0 | 408 | return fwInstance->mdInstance; |
michael@0 | 409 | } |
michael@0 | 410 | |
michael@0 | 411 | /* |
michael@0 | 412 | * nssCKFWInstance_GetArena |
michael@0 | 413 | * |
michael@0 | 414 | */ |
michael@0 | 415 | NSS_IMPLEMENT NSSArena * |
michael@0 | 416 | nssCKFWInstance_GetArena |
michael@0 | 417 | ( |
michael@0 | 418 | NSSCKFWInstance *fwInstance, |
michael@0 | 419 | CK_RV *pError |
michael@0 | 420 | ) |
michael@0 | 421 | { |
michael@0 | 422 | #ifdef NSSDEBUG |
michael@0 | 423 | if (!pError) { |
michael@0 | 424 | return (NSSArena *)NULL; |
michael@0 | 425 | } |
michael@0 | 426 | |
michael@0 | 427 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 428 | if( CKR_OK != *pError ) { |
michael@0 | 429 | return (NSSArena *)NULL; |
michael@0 | 430 | } |
michael@0 | 431 | #endif /* NSSDEBUG */ |
michael@0 | 432 | |
michael@0 | 433 | *pError = CKR_OK; |
michael@0 | 434 | return fwInstance->arena; |
michael@0 | 435 | } |
michael@0 | 436 | |
michael@0 | 437 | /* |
michael@0 | 438 | * nssCKFWInstance_MayCreatePthreads |
michael@0 | 439 | * |
michael@0 | 440 | */ |
michael@0 | 441 | NSS_IMPLEMENT CK_BBOOL |
michael@0 | 442 | nssCKFWInstance_MayCreatePthreads |
michael@0 | 443 | ( |
michael@0 | 444 | NSSCKFWInstance *fwInstance |
michael@0 | 445 | ) |
michael@0 | 446 | { |
michael@0 | 447 | #ifdef NSSDEBUG |
michael@0 | 448 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 449 | return CK_FALSE; |
michael@0 | 450 | } |
michael@0 | 451 | #endif /* NSSDEBUG */ |
michael@0 | 452 | |
michael@0 | 453 | return fwInstance->mayCreatePthreads; |
michael@0 | 454 | } |
michael@0 | 455 | |
michael@0 | 456 | /* |
michael@0 | 457 | * nssCKFWInstance_CreateMutex |
michael@0 | 458 | * |
michael@0 | 459 | */ |
michael@0 | 460 | NSS_IMPLEMENT NSSCKFWMutex * |
michael@0 | 461 | nssCKFWInstance_CreateMutex |
michael@0 | 462 | ( |
michael@0 | 463 | NSSCKFWInstance *fwInstance, |
michael@0 | 464 | NSSArena *arena, |
michael@0 | 465 | CK_RV *pError |
michael@0 | 466 | ) |
michael@0 | 467 | { |
michael@0 | 468 | NSSCKFWMutex *mutex; |
michael@0 | 469 | |
michael@0 | 470 | #ifdef NSSDEBUG |
michael@0 | 471 | if (!pError) { |
michael@0 | 472 | return (NSSCKFWMutex *)NULL; |
michael@0 | 473 | } |
michael@0 | 474 | |
michael@0 | 475 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 476 | if( CKR_OK != *pError ) { |
michael@0 | 477 | return (NSSCKFWMutex *)NULL; |
michael@0 | 478 | } |
michael@0 | 479 | #endif /* NSSDEBUG */ |
michael@0 | 480 | |
michael@0 | 481 | mutex = nssCKFWMutex_Create(fwInstance->pInitArgs, fwInstance->LockingState, |
michael@0 | 482 | arena, pError); |
michael@0 | 483 | if (!mutex) { |
michael@0 | 484 | if( CKR_OK == *pError ) { |
michael@0 | 485 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 486 | } |
michael@0 | 487 | |
michael@0 | 488 | return (NSSCKFWMutex *)NULL; |
michael@0 | 489 | } |
michael@0 | 490 | |
michael@0 | 491 | return mutex; |
michael@0 | 492 | } |
michael@0 | 493 | |
michael@0 | 494 | /* |
michael@0 | 495 | * nssCKFWInstance_GetConfigurationData |
michael@0 | 496 | * |
michael@0 | 497 | */ |
michael@0 | 498 | NSS_IMPLEMENT NSSUTF8 * |
michael@0 | 499 | nssCKFWInstance_GetConfigurationData |
michael@0 | 500 | ( |
michael@0 | 501 | NSSCKFWInstance *fwInstance |
michael@0 | 502 | ) |
michael@0 | 503 | { |
michael@0 | 504 | #ifdef NSSDEBUG |
michael@0 | 505 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 506 | return (NSSUTF8 *)NULL; |
michael@0 | 507 | } |
michael@0 | 508 | #endif /* NSSDEBUG */ |
michael@0 | 509 | |
michael@0 | 510 | return fwInstance->configurationData; |
michael@0 | 511 | } |
michael@0 | 512 | |
michael@0 | 513 | /* |
michael@0 | 514 | * nssCKFWInstance_GetInitArgs |
michael@0 | 515 | * |
michael@0 | 516 | */ |
michael@0 | 517 | CK_C_INITIALIZE_ARGS_PTR |
michael@0 | 518 | nssCKFWInstance_GetInitArgs |
michael@0 | 519 | ( |
michael@0 | 520 | NSSCKFWInstance *fwInstance |
michael@0 | 521 | ) |
michael@0 | 522 | { |
michael@0 | 523 | #ifdef NSSDEBUG |
michael@0 | 524 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 525 | return (CK_C_INITIALIZE_ARGS_PTR)NULL; |
michael@0 | 526 | } |
michael@0 | 527 | #endif /* NSSDEBUG */ |
michael@0 | 528 | |
michael@0 | 529 | return fwInstance->pInitArgs; |
michael@0 | 530 | } |
michael@0 | 531 | |
michael@0 | 532 | /* |
michael@0 | 533 | * nssCKFWInstance_CreateSessionHandle |
michael@0 | 534 | * |
michael@0 | 535 | */ |
michael@0 | 536 | NSS_IMPLEMENT CK_SESSION_HANDLE |
michael@0 | 537 | nssCKFWInstance_CreateSessionHandle |
michael@0 | 538 | ( |
michael@0 | 539 | NSSCKFWInstance *fwInstance, |
michael@0 | 540 | NSSCKFWSession *fwSession, |
michael@0 | 541 | CK_RV *pError |
michael@0 | 542 | ) |
michael@0 | 543 | { |
michael@0 | 544 | CK_SESSION_HANDLE hSession; |
michael@0 | 545 | |
michael@0 | 546 | #ifdef NSSDEBUG |
michael@0 | 547 | if (!pError) { |
michael@0 | 548 | return (CK_SESSION_HANDLE)0; |
michael@0 | 549 | } |
michael@0 | 550 | |
michael@0 | 551 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 552 | if( CKR_OK != *pError ) { |
michael@0 | 553 | return (CK_SESSION_HANDLE)0; |
michael@0 | 554 | } |
michael@0 | 555 | #endif /* NSSDEBUG */ |
michael@0 | 556 | |
michael@0 | 557 | *pError = nssCKFWMutex_Lock(fwInstance->mutex); |
michael@0 | 558 | if( CKR_OK != *pError ) { |
michael@0 | 559 | return (CK_SESSION_HANDLE)0; |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | hSession = ++(fwInstance->lastSessionHandle); |
michael@0 | 563 | |
michael@0 | 564 | /* Alan would say I should unlock for this call. */ |
michael@0 | 565 | |
michael@0 | 566 | *pError = nssCKFWSession_SetHandle(fwSession, hSession); |
michael@0 | 567 | if( CKR_OK != *pError ) { |
michael@0 | 568 | goto done; |
michael@0 | 569 | } |
michael@0 | 570 | |
michael@0 | 571 | *pError = nssCKFWHash_Add(fwInstance->sessionHandleHash, |
michael@0 | 572 | (const void *)hSession, (const void *)fwSession); |
michael@0 | 573 | if( CKR_OK != *pError ) { |
michael@0 | 574 | hSession = (CK_SESSION_HANDLE)0; |
michael@0 | 575 | goto done; |
michael@0 | 576 | } |
michael@0 | 577 | |
michael@0 | 578 | done: |
michael@0 | 579 | nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 580 | return hSession; |
michael@0 | 581 | } |
michael@0 | 582 | |
michael@0 | 583 | /* |
michael@0 | 584 | * nssCKFWInstance_ResolveSessionHandle |
michael@0 | 585 | * |
michael@0 | 586 | */ |
michael@0 | 587 | NSS_IMPLEMENT NSSCKFWSession * |
michael@0 | 588 | nssCKFWInstance_ResolveSessionHandle |
michael@0 | 589 | ( |
michael@0 | 590 | NSSCKFWInstance *fwInstance, |
michael@0 | 591 | CK_SESSION_HANDLE hSession |
michael@0 | 592 | ) |
michael@0 | 593 | { |
michael@0 | 594 | NSSCKFWSession *fwSession; |
michael@0 | 595 | |
michael@0 | 596 | #ifdef NSSDEBUG |
michael@0 | 597 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 598 | return (NSSCKFWSession *)NULL; |
michael@0 | 599 | } |
michael@0 | 600 | #endif /* NSSDEBUG */ |
michael@0 | 601 | |
michael@0 | 602 | if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { |
michael@0 | 603 | return (NSSCKFWSession *)NULL; |
michael@0 | 604 | } |
michael@0 | 605 | |
michael@0 | 606 | fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup( |
michael@0 | 607 | fwInstance->sessionHandleHash, (const void *)hSession); |
michael@0 | 608 | |
michael@0 | 609 | /* Assert(hSession == nssCKFWSession_GetHandle(fwSession)) */ |
michael@0 | 610 | |
michael@0 | 611 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 612 | |
michael@0 | 613 | return fwSession; |
michael@0 | 614 | } |
michael@0 | 615 | |
michael@0 | 616 | /* |
michael@0 | 617 | * nssCKFWInstance_DestroySessionHandle |
michael@0 | 618 | * |
michael@0 | 619 | */ |
michael@0 | 620 | NSS_IMPLEMENT void |
michael@0 | 621 | nssCKFWInstance_DestroySessionHandle |
michael@0 | 622 | ( |
michael@0 | 623 | NSSCKFWInstance *fwInstance, |
michael@0 | 624 | CK_SESSION_HANDLE hSession |
michael@0 | 625 | ) |
michael@0 | 626 | { |
michael@0 | 627 | NSSCKFWSession *fwSession; |
michael@0 | 628 | |
michael@0 | 629 | #ifdef NSSDEBUG |
michael@0 | 630 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 631 | return; |
michael@0 | 632 | } |
michael@0 | 633 | #endif /* NSSDEBUG */ |
michael@0 | 634 | |
michael@0 | 635 | if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { |
michael@0 | 636 | return; |
michael@0 | 637 | } |
michael@0 | 638 | |
michael@0 | 639 | fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup( |
michael@0 | 640 | fwInstance->sessionHandleHash, (const void *)hSession); |
michael@0 | 641 | if (fwSession) { |
michael@0 | 642 | nssCKFWHash_Remove(fwInstance->sessionHandleHash, (const void *)hSession); |
michael@0 | 643 | nssCKFWSession_SetHandle(fwSession, (CK_SESSION_HANDLE)0); |
michael@0 | 644 | } |
michael@0 | 645 | |
michael@0 | 646 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 647 | |
michael@0 | 648 | return; |
michael@0 | 649 | } |
michael@0 | 650 | |
michael@0 | 651 | /* |
michael@0 | 652 | * nssCKFWInstance_FindSessionHandle |
michael@0 | 653 | * |
michael@0 | 654 | */ |
michael@0 | 655 | NSS_IMPLEMENT CK_SESSION_HANDLE |
michael@0 | 656 | nssCKFWInstance_FindSessionHandle |
michael@0 | 657 | ( |
michael@0 | 658 | NSSCKFWInstance *fwInstance, |
michael@0 | 659 | NSSCKFWSession *fwSession |
michael@0 | 660 | ) |
michael@0 | 661 | { |
michael@0 | 662 | #ifdef NSSDEBUG |
michael@0 | 663 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 664 | return (CK_SESSION_HANDLE)0; |
michael@0 | 665 | } |
michael@0 | 666 | |
michael@0 | 667 | if( CKR_OK != nssCKFWSession_verifyPointer(fwSession) ) { |
michael@0 | 668 | return (CK_SESSION_HANDLE)0; |
michael@0 | 669 | } |
michael@0 | 670 | #endif /* NSSDEBUG */ |
michael@0 | 671 | |
michael@0 | 672 | return nssCKFWSession_GetHandle(fwSession); |
michael@0 | 673 | /* look it up and assert? */ |
michael@0 | 674 | } |
michael@0 | 675 | |
michael@0 | 676 | /* |
michael@0 | 677 | * nssCKFWInstance_CreateObjectHandle |
michael@0 | 678 | * |
michael@0 | 679 | */ |
michael@0 | 680 | NSS_IMPLEMENT CK_OBJECT_HANDLE |
michael@0 | 681 | nssCKFWInstance_CreateObjectHandle |
michael@0 | 682 | ( |
michael@0 | 683 | NSSCKFWInstance *fwInstance, |
michael@0 | 684 | NSSCKFWObject *fwObject, |
michael@0 | 685 | CK_RV *pError |
michael@0 | 686 | ) |
michael@0 | 687 | { |
michael@0 | 688 | CK_OBJECT_HANDLE hObject; |
michael@0 | 689 | |
michael@0 | 690 | #ifdef NSSDEBUG |
michael@0 | 691 | if (!pError) { |
michael@0 | 692 | return (CK_OBJECT_HANDLE)0; |
michael@0 | 693 | } |
michael@0 | 694 | |
michael@0 | 695 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 696 | if( CKR_OK != *pError ) { |
michael@0 | 697 | return (CK_OBJECT_HANDLE)0; |
michael@0 | 698 | } |
michael@0 | 699 | #endif /* NSSDEBUG */ |
michael@0 | 700 | |
michael@0 | 701 | *pError = nssCKFWMutex_Lock(fwInstance->mutex); |
michael@0 | 702 | if( CKR_OK != *pError ) { |
michael@0 | 703 | return (CK_OBJECT_HANDLE)0; |
michael@0 | 704 | } |
michael@0 | 705 | |
michael@0 | 706 | hObject = ++(fwInstance->lastObjectHandle); |
michael@0 | 707 | |
michael@0 | 708 | *pError = nssCKFWObject_SetHandle(fwObject, hObject); |
michael@0 | 709 | if( CKR_OK != *pError ) { |
michael@0 | 710 | hObject = (CK_OBJECT_HANDLE)0; |
michael@0 | 711 | goto done; |
michael@0 | 712 | } |
michael@0 | 713 | |
michael@0 | 714 | *pError = nssCKFWHash_Add(fwInstance->objectHandleHash, |
michael@0 | 715 | (const void *)hObject, (const void *)fwObject); |
michael@0 | 716 | if( CKR_OK != *pError ) { |
michael@0 | 717 | hObject = (CK_OBJECT_HANDLE)0; |
michael@0 | 718 | goto done; |
michael@0 | 719 | } |
michael@0 | 720 | |
michael@0 | 721 | done: |
michael@0 | 722 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 723 | return hObject; |
michael@0 | 724 | } |
michael@0 | 725 | |
michael@0 | 726 | /* |
michael@0 | 727 | * nssCKFWInstance_ResolveObjectHandle |
michael@0 | 728 | * |
michael@0 | 729 | */ |
michael@0 | 730 | NSS_IMPLEMENT NSSCKFWObject * |
michael@0 | 731 | nssCKFWInstance_ResolveObjectHandle |
michael@0 | 732 | ( |
michael@0 | 733 | NSSCKFWInstance *fwInstance, |
michael@0 | 734 | CK_OBJECT_HANDLE hObject |
michael@0 | 735 | ) |
michael@0 | 736 | { |
michael@0 | 737 | NSSCKFWObject *fwObject; |
michael@0 | 738 | |
michael@0 | 739 | #ifdef NSSDEBUG |
michael@0 | 740 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 741 | return (NSSCKFWObject *)NULL; |
michael@0 | 742 | } |
michael@0 | 743 | #endif /* NSSDEBUG */ |
michael@0 | 744 | |
michael@0 | 745 | if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { |
michael@0 | 746 | return (NSSCKFWObject *)NULL; |
michael@0 | 747 | } |
michael@0 | 748 | |
michael@0 | 749 | fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup( |
michael@0 | 750 | fwInstance->objectHandleHash, (const void *)hObject); |
michael@0 | 751 | |
michael@0 | 752 | /* Assert(hObject == nssCKFWObject_GetHandle(fwObject)) */ |
michael@0 | 753 | |
michael@0 | 754 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 755 | return fwObject; |
michael@0 | 756 | } |
michael@0 | 757 | |
michael@0 | 758 | /* |
michael@0 | 759 | * nssCKFWInstance_ReassignObjectHandle |
michael@0 | 760 | * |
michael@0 | 761 | */ |
michael@0 | 762 | NSS_IMPLEMENT CK_RV |
michael@0 | 763 | nssCKFWInstance_ReassignObjectHandle |
michael@0 | 764 | ( |
michael@0 | 765 | NSSCKFWInstance *fwInstance, |
michael@0 | 766 | CK_OBJECT_HANDLE hObject, |
michael@0 | 767 | NSSCKFWObject *fwObject |
michael@0 | 768 | ) |
michael@0 | 769 | { |
michael@0 | 770 | CK_RV error = CKR_OK; |
michael@0 | 771 | NSSCKFWObject *oldObject; |
michael@0 | 772 | |
michael@0 | 773 | #ifdef NSSDEBUG |
michael@0 | 774 | error = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 775 | if( CKR_OK != error ) { |
michael@0 | 776 | return error; |
michael@0 | 777 | } |
michael@0 | 778 | #endif /* NSSDEBUG */ |
michael@0 | 779 | |
michael@0 | 780 | error = nssCKFWMutex_Lock(fwInstance->mutex); |
michael@0 | 781 | if( CKR_OK != error ) { |
michael@0 | 782 | return error; |
michael@0 | 783 | } |
michael@0 | 784 | |
michael@0 | 785 | oldObject = (NSSCKFWObject *)nssCKFWHash_Lookup( |
michael@0 | 786 | fwInstance->objectHandleHash, (const void *)hObject); |
michael@0 | 787 | if(oldObject) { |
michael@0 | 788 | /* Assert(hObject == nssCKFWObject_GetHandle(oldObject) */ |
michael@0 | 789 | (void)nssCKFWObject_SetHandle(oldObject, (CK_SESSION_HANDLE)0); |
michael@0 | 790 | nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject); |
michael@0 | 791 | } |
michael@0 | 792 | |
michael@0 | 793 | error = nssCKFWObject_SetHandle(fwObject, hObject); |
michael@0 | 794 | if( CKR_OK != error ) { |
michael@0 | 795 | goto done; |
michael@0 | 796 | } |
michael@0 | 797 | error = nssCKFWHash_Add(fwInstance->objectHandleHash, |
michael@0 | 798 | (const void *)hObject, (const void *)fwObject); |
michael@0 | 799 | |
michael@0 | 800 | done: |
michael@0 | 801 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 802 | return error; |
michael@0 | 803 | } |
michael@0 | 804 | |
michael@0 | 805 | /* |
michael@0 | 806 | * nssCKFWInstance_DestroyObjectHandle |
michael@0 | 807 | * |
michael@0 | 808 | */ |
michael@0 | 809 | NSS_IMPLEMENT void |
michael@0 | 810 | nssCKFWInstance_DestroyObjectHandle |
michael@0 | 811 | ( |
michael@0 | 812 | NSSCKFWInstance *fwInstance, |
michael@0 | 813 | CK_OBJECT_HANDLE hObject |
michael@0 | 814 | ) |
michael@0 | 815 | { |
michael@0 | 816 | NSSCKFWObject *fwObject; |
michael@0 | 817 | |
michael@0 | 818 | #ifdef NSSDEBUG |
michael@0 | 819 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 820 | return; |
michael@0 | 821 | } |
michael@0 | 822 | #endif /* NSSDEBUG */ |
michael@0 | 823 | |
michael@0 | 824 | if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { |
michael@0 | 825 | return; |
michael@0 | 826 | } |
michael@0 | 827 | |
michael@0 | 828 | fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup( |
michael@0 | 829 | fwInstance->objectHandleHash, (const void *)hObject); |
michael@0 | 830 | if (fwObject) { |
michael@0 | 831 | /* Assert(hObject = nssCKFWObject_GetHandle(fwObject)) */ |
michael@0 | 832 | nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject); |
michael@0 | 833 | (void)nssCKFWObject_SetHandle(fwObject, (CK_SESSION_HANDLE)0); |
michael@0 | 834 | } |
michael@0 | 835 | |
michael@0 | 836 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 837 | return; |
michael@0 | 838 | } |
michael@0 | 839 | |
michael@0 | 840 | /* |
michael@0 | 841 | * nssCKFWInstance_FindObjectHandle |
michael@0 | 842 | * |
michael@0 | 843 | */ |
michael@0 | 844 | NSS_IMPLEMENT CK_OBJECT_HANDLE |
michael@0 | 845 | nssCKFWInstance_FindObjectHandle |
michael@0 | 846 | ( |
michael@0 | 847 | NSSCKFWInstance *fwInstance, |
michael@0 | 848 | NSSCKFWObject *fwObject |
michael@0 | 849 | ) |
michael@0 | 850 | { |
michael@0 | 851 | #ifdef NSSDEBUG |
michael@0 | 852 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 853 | return (CK_OBJECT_HANDLE)0; |
michael@0 | 854 | } |
michael@0 | 855 | |
michael@0 | 856 | if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) { |
michael@0 | 857 | return (CK_OBJECT_HANDLE)0; |
michael@0 | 858 | } |
michael@0 | 859 | #endif /* NSSDEBUG */ |
michael@0 | 860 | |
michael@0 | 861 | return nssCKFWObject_GetHandle(fwObject); |
michael@0 | 862 | } |
michael@0 | 863 | |
michael@0 | 864 | /* |
michael@0 | 865 | * nssCKFWInstance_GetNSlots |
michael@0 | 866 | * |
michael@0 | 867 | */ |
michael@0 | 868 | NSS_IMPLEMENT CK_ULONG |
michael@0 | 869 | nssCKFWInstance_GetNSlots |
michael@0 | 870 | ( |
michael@0 | 871 | NSSCKFWInstance *fwInstance, |
michael@0 | 872 | CK_RV *pError |
michael@0 | 873 | ) |
michael@0 | 874 | { |
michael@0 | 875 | #ifdef NSSDEBUG |
michael@0 | 876 | if (!pError) { |
michael@0 | 877 | return (CK_ULONG)0; |
michael@0 | 878 | } |
michael@0 | 879 | |
michael@0 | 880 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 881 | if( CKR_OK != *pError ) { |
michael@0 | 882 | return (CK_ULONG)0; |
michael@0 | 883 | } |
michael@0 | 884 | #endif /* NSSDEBUG */ |
michael@0 | 885 | |
michael@0 | 886 | *pError = CKR_OK; |
michael@0 | 887 | return fwInstance->nSlots; |
michael@0 | 888 | } |
michael@0 | 889 | |
michael@0 | 890 | /* |
michael@0 | 891 | * nssCKFWInstance_GetCryptokiVersion |
michael@0 | 892 | * |
michael@0 | 893 | */ |
michael@0 | 894 | NSS_IMPLEMENT CK_VERSION |
michael@0 | 895 | nssCKFWInstance_GetCryptokiVersion |
michael@0 | 896 | ( |
michael@0 | 897 | NSSCKFWInstance *fwInstance |
michael@0 | 898 | ) |
michael@0 | 899 | { |
michael@0 | 900 | CK_VERSION rv; |
michael@0 | 901 | |
michael@0 | 902 | #ifdef NSSDEBUG |
michael@0 | 903 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 904 | rv.major = rv.minor = 0; |
michael@0 | 905 | return rv; |
michael@0 | 906 | } |
michael@0 | 907 | #endif /* NSSDEBUG */ |
michael@0 | 908 | |
michael@0 | 909 | if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { |
michael@0 | 910 | rv.major = rv.minor = 0; |
michael@0 | 911 | return rv; |
michael@0 | 912 | } |
michael@0 | 913 | |
michael@0 | 914 | if( (0 != fwInstance->cryptokiVersion.major) || |
michael@0 | 915 | (0 != fwInstance->cryptokiVersion.minor) ) { |
michael@0 | 916 | rv = fwInstance->cryptokiVersion; |
michael@0 | 917 | goto done; |
michael@0 | 918 | } |
michael@0 | 919 | |
michael@0 | 920 | if (fwInstance->mdInstance->GetCryptokiVersion) { |
michael@0 | 921 | fwInstance->cryptokiVersion = fwInstance->mdInstance->GetCryptokiVersion( |
michael@0 | 922 | fwInstance->mdInstance, fwInstance); |
michael@0 | 923 | } else { |
michael@0 | 924 | fwInstance->cryptokiVersion.major = 2; |
michael@0 | 925 | fwInstance->cryptokiVersion.minor = 1; |
michael@0 | 926 | } |
michael@0 | 927 | |
michael@0 | 928 | rv = fwInstance->cryptokiVersion; |
michael@0 | 929 | |
michael@0 | 930 | done: |
michael@0 | 931 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 932 | return rv; |
michael@0 | 933 | } |
michael@0 | 934 | |
michael@0 | 935 | /* |
michael@0 | 936 | * nssCKFWInstance_GetManufacturerID |
michael@0 | 937 | * |
michael@0 | 938 | */ |
michael@0 | 939 | NSS_IMPLEMENT CK_RV |
michael@0 | 940 | nssCKFWInstance_GetManufacturerID |
michael@0 | 941 | ( |
michael@0 | 942 | NSSCKFWInstance *fwInstance, |
michael@0 | 943 | CK_CHAR manufacturerID[32] |
michael@0 | 944 | ) |
michael@0 | 945 | { |
michael@0 | 946 | CK_RV error = CKR_OK; |
michael@0 | 947 | |
michael@0 | 948 | #ifdef NSSDEBUG |
michael@0 | 949 | if( (CK_CHAR_PTR)NULL == manufacturerID ) { |
michael@0 | 950 | return CKR_ARGUMENTS_BAD; |
michael@0 | 951 | } |
michael@0 | 952 | |
michael@0 | 953 | error = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 954 | if( CKR_OK != error ) { |
michael@0 | 955 | return error; |
michael@0 | 956 | } |
michael@0 | 957 | #endif /* NSSDEBUG */ |
michael@0 | 958 | |
michael@0 | 959 | error = nssCKFWMutex_Lock(fwInstance->mutex); |
michael@0 | 960 | if( CKR_OK != error ) { |
michael@0 | 961 | return error; |
michael@0 | 962 | } |
michael@0 | 963 | |
michael@0 | 964 | if (!fwInstance->manufacturerID) { |
michael@0 | 965 | if (fwInstance->mdInstance->GetManufacturerID) { |
michael@0 | 966 | fwInstance->manufacturerID = fwInstance->mdInstance->GetManufacturerID( |
michael@0 | 967 | fwInstance->mdInstance, fwInstance, &error); |
michael@0 | 968 | if ((!fwInstance->manufacturerID) && (CKR_OK != error)) { |
michael@0 | 969 | goto done; |
michael@0 | 970 | } |
michael@0 | 971 | } else { |
michael@0 | 972 | fwInstance->manufacturerID = (NSSUTF8 *) ""; |
michael@0 | 973 | } |
michael@0 | 974 | } |
michael@0 | 975 | |
michael@0 | 976 | (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->manufacturerID, (char *)manufacturerID, 32, ' '); |
michael@0 | 977 | error = CKR_OK; |
michael@0 | 978 | |
michael@0 | 979 | done: |
michael@0 | 980 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 981 | return error; |
michael@0 | 982 | } |
michael@0 | 983 | |
michael@0 | 984 | /* |
michael@0 | 985 | * nssCKFWInstance_GetFlags |
michael@0 | 986 | * |
michael@0 | 987 | */ |
michael@0 | 988 | NSS_IMPLEMENT CK_ULONG |
michael@0 | 989 | nssCKFWInstance_GetFlags |
michael@0 | 990 | ( |
michael@0 | 991 | NSSCKFWInstance *fwInstance |
michael@0 | 992 | ) |
michael@0 | 993 | { |
michael@0 | 994 | #ifdef NSSDEBUG |
michael@0 | 995 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 996 | return (CK_ULONG)0; |
michael@0 | 997 | } |
michael@0 | 998 | #endif /* NSSDEBUG */ |
michael@0 | 999 | |
michael@0 | 1000 | /* No "instance flags" are yet defined by Cryptoki. */ |
michael@0 | 1001 | return (CK_ULONG)0; |
michael@0 | 1002 | } |
michael@0 | 1003 | |
michael@0 | 1004 | /* |
michael@0 | 1005 | * nssCKFWInstance_GetLibraryDescription |
michael@0 | 1006 | * |
michael@0 | 1007 | */ |
michael@0 | 1008 | NSS_IMPLEMENT CK_RV |
michael@0 | 1009 | nssCKFWInstance_GetLibraryDescription |
michael@0 | 1010 | ( |
michael@0 | 1011 | NSSCKFWInstance *fwInstance, |
michael@0 | 1012 | CK_CHAR libraryDescription[32] |
michael@0 | 1013 | ) |
michael@0 | 1014 | { |
michael@0 | 1015 | CK_RV error = CKR_OK; |
michael@0 | 1016 | |
michael@0 | 1017 | #ifdef NSSDEBUG |
michael@0 | 1018 | if( (CK_CHAR_PTR)NULL == libraryDescription ) { |
michael@0 | 1019 | return CKR_ARGUMENTS_BAD; |
michael@0 | 1020 | } |
michael@0 | 1021 | |
michael@0 | 1022 | error = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 1023 | if( CKR_OK != error ) { |
michael@0 | 1024 | return error; |
michael@0 | 1025 | } |
michael@0 | 1026 | #endif /* NSSDEBUG */ |
michael@0 | 1027 | |
michael@0 | 1028 | error = nssCKFWMutex_Lock(fwInstance->mutex); |
michael@0 | 1029 | if( CKR_OK != error ) { |
michael@0 | 1030 | return error; |
michael@0 | 1031 | } |
michael@0 | 1032 | |
michael@0 | 1033 | if (!fwInstance->libraryDescription) { |
michael@0 | 1034 | if (fwInstance->mdInstance->GetLibraryDescription) { |
michael@0 | 1035 | fwInstance->libraryDescription = fwInstance->mdInstance->GetLibraryDescription( |
michael@0 | 1036 | fwInstance->mdInstance, fwInstance, &error); |
michael@0 | 1037 | if ((!fwInstance->libraryDescription) && (CKR_OK != error)) { |
michael@0 | 1038 | goto done; |
michael@0 | 1039 | } |
michael@0 | 1040 | } else { |
michael@0 | 1041 | fwInstance->libraryDescription = (NSSUTF8 *) ""; |
michael@0 | 1042 | } |
michael@0 | 1043 | } |
michael@0 | 1044 | |
michael@0 | 1045 | (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->libraryDescription, (char *)libraryDescription, 32, ' '); |
michael@0 | 1046 | error = CKR_OK; |
michael@0 | 1047 | |
michael@0 | 1048 | done: |
michael@0 | 1049 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 1050 | return error; |
michael@0 | 1051 | } |
michael@0 | 1052 | |
michael@0 | 1053 | /* |
michael@0 | 1054 | * nssCKFWInstance_GetLibraryVersion |
michael@0 | 1055 | * |
michael@0 | 1056 | */ |
michael@0 | 1057 | NSS_IMPLEMENT CK_VERSION |
michael@0 | 1058 | nssCKFWInstance_GetLibraryVersion |
michael@0 | 1059 | ( |
michael@0 | 1060 | NSSCKFWInstance *fwInstance |
michael@0 | 1061 | ) |
michael@0 | 1062 | { |
michael@0 | 1063 | CK_VERSION rv; |
michael@0 | 1064 | |
michael@0 | 1065 | #ifdef NSSDEBUG |
michael@0 | 1066 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 1067 | rv.major = rv.minor = 0; |
michael@0 | 1068 | return rv; |
michael@0 | 1069 | } |
michael@0 | 1070 | #endif /* NSSDEBUG */ |
michael@0 | 1071 | |
michael@0 | 1072 | if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { |
michael@0 | 1073 | rv.major = rv.minor = 0; |
michael@0 | 1074 | return rv; |
michael@0 | 1075 | } |
michael@0 | 1076 | |
michael@0 | 1077 | if( (0 != fwInstance->libraryVersion.major) || |
michael@0 | 1078 | (0 != fwInstance->libraryVersion.minor) ) { |
michael@0 | 1079 | rv = fwInstance->libraryVersion; |
michael@0 | 1080 | goto done; |
michael@0 | 1081 | } |
michael@0 | 1082 | |
michael@0 | 1083 | if (fwInstance->mdInstance->GetLibraryVersion) { |
michael@0 | 1084 | fwInstance->libraryVersion = fwInstance->mdInstance->GetLibraryVersion( |
michael@0 | 1085 | fwInstance->mdInstance, fwInstance); |
michael@0 | 1086 | } else { |
michael@0 | 1087 | fwInstance->libraryVersion.major = 0; |
michael@0 | 1088 | fwInstance->libraryVersion.minor = 3; |
michael@0 | 1089 | } |
michael@0 | 1090 | |
michael@0 | 1091 | rv = fwInstance->libraryVersion; |
michael@0 | 1092 | done: |
michael@0 | 1093 | (void)nssCKFWMutex_Unlock(fwInstance->mutex); |
michael@0 | 1094 | return rv; |
michael@0 | 1095 | } |
michael@0 | 1096 | |
michael@0 | 1097 | /* |
michael@0 | 1098 | * nssCKFWInstance_GetModuleHandlesSessionObjects |
michael@0 | 1099 | * |
michael@0 | 1100 | */ |
michael@0 | 1101 | NSS_IMPLEMENT CK_BBOOL |
michael@0 | 1102 | nssCKFWInstance_GetModuleHandlesSessionObjects |
michael@0 | 1103 | ( |
michael@0 | 1104 | NSSCKFWInstance *fwInstance |
michael@0 | 1105 | ) |
michael@0 | 1106 | { |
michael@0 | 1107 | #ifdef NSSDEBUG |
michael@0 | 1108 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 1109 | return CK_FALSE; |
michael@0 | 1110 | } |
michael@0 | 1111 | #endif /* NSSDEBUG */ |
michael@0 | 1112 | |
michael@0 | 1113 | return fwInstance->moduleHandlesSessionObjects; |
michael@0 | 1114 | } |
michael@0 | 1115 | |
michael@0 | 1116 | /* |
michael@0 | 1117 | * nssCKFWInstance_GetSlots |
michael@0 | 1118 | * |
michael@0 | 1119 | */ |
michael@0 | 1120 | NSS_IMPLEMENT NSSCKFWSlot ** |
michael@0 | 1121 | nssCKFWInstance_GetSlots |
michael@0 | 1122 | ( |
michael@0 | 1123 | NSSCKFWInstance *fwInstance, |
michael@0 | 1124 | CK_RV *pError |
michael@0 | 1125 | ) |
michael@0 | 1126 | { |
michael@0 | 1127 | #ifdef NSSDEBUG |
michael@0 | 1128 | if (!pError) { |
michael@0 | 1129 | return (NSSCKFWSlot **)NULL; |
michael@0 | 1130 | } |
michael@0 | 1131 | |
michael@0 | 1132 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 1133 | if( CKR_OK != *pError ) { |
michael@0 | 1134 | return (NSSCKFWSlot **)NULL; |
michael@0 | 1135 | } |
michael@0 | 1136 | #endif /* NSSDEBUG */ |
michael@0 | 1137 | |
michael@0 | 1138 | return fwInstance->fwSlotList; |
michael@0 | 1139 | } |
michael@0 | 1140 | |
michael@0 | 1141 | /* |
michael@0 | 1142 | * nssCKFWInstance_WaitForSlotEvent |
michael@0 | 1143 | * |
michael@0 | 1144 | */ |
michael@0 | 1145 | NSS_IMPLEMENT NSSCKFWSlot * |
michael@0 | 1146 | nssCKFWInstance_WaitForSlotEvent |
michael@0 | 1147 | ( |
michael@0 | 1148 | NSSCKFWInstance *fwInstance, |
michael@0 | 1149 | CK_BBOOL block, |
michael@0 | 1150 | CK_RV *pError |
michael@0 | 1151 | ) |
michael@0 | 1152 | { |
michael@0 | 1153 | NSSCKFWSlot *fwSlot = (NSSCKFWSlot *)NULL; |
michael@0 | 1154 | NSSCKMDSlot *mdSlot; |
michael@0 | 1155 | CK_ULONG i, n; |
michael@0 | 1156 | |
michael@0 | 1157 | #ifdef NSSDEBUG |
michael@0 | 1158 | if (!pError) { |
michael@0 | 1159 | return (NSSCKFWSlot *)NULL; |
michael@0 | 1160 | } |
michael@0 | 1161 | |
michael@0 | 1162 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 1163 | if( CKR_OK != *pError ) { |
michael@0 | 1164 | return (NSSCKFWSlot *)NULL; |
michael@0 | 1165 | } |
michael@0 | 1166 | |
michael@0 | 1167 | switch( block ) { |
michael@0 | 1168 | case CK_TRUE: |
michael@0 | 1169 | case CK_FALSE: |
michael@0 | 1170 | break; |
michael@0 | 1171 | default: |
michael@0 | 1172 | *pError = CKR_ARGUMENTS_BAD; |
michael@0 | 1173 | return (NSSCKFWSlot *)NULL; |
michael@0 | 1174 | } |
michael@0 | 1175 | #endif /* NSSDEBUG */ |
michael@0 | 1176 | |
michael@0 | 1177 | if (!fwInstance->mdInstance->WaitForSlotEvent) { |
michael@0 | 1178 | *pError = CKR_NO_EVENT; |
michael@0 | 1179 | return (NSSCKFWSlot *)NULL; |
michael@0 | 1180 | } |
michael@0 | 1181 | |
michael@0 | 1182 | mdSlot = fwInstance->mdInstance->WaitForSlotEvent( |
michael@0 | 1183 | fwInstance->mdInstance, |
michael@0 | 1184 | fwInstance, |
michael@0 | 1185 | block, |
michael@0 | 1186 | pError |
michael@0 | 1187 | ); |
michael@0 | 1188 | |
michael@0 | 1189 | if (!mdSlot) { |
michael@0 | 1190 | return (NSSCKFWSlot *)NULL; |
michael@0 | 1191 | } |
michael@0 | 1192 | |
michael@0 | 1193 | n = nssCKFWInstance_GetNSlots(fwInstance, pError); |
michael@0 | 1194 | if( ((CK_ULONG)0 == n) && (CKR_OK != *pError) ) { |
michael@0 | 1195 | return (NSSCKFWSlot *)NULL; |
michael@0 | 1196 | } |
michael@0 | 1197 | |
michael@0 | 1198 | for( i = 0; i < n; i++ ) { |
michael@0 | 1199 | if( fwInstance->mdSlotList[i] == mdSlot ) { |
michael@0 | 1200 | fwSlot = fwInstance->fwSlotList[i]; |
michael@0 | 1201 | break; |
michael@0 | 1202 | } |
michael@0 | 1203 | } |
michael@0 | 1204 | |
michael@0 | 1205 | if (!fwSlot) { |
michael@0 | 1206 | /* Internal error */ |
michael@0 | 1207 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 1208 | return (NSSCKFWSlot *)NULL; |
michael@0 | 1209 | } |
michael@0 | 1210 | |
michael@0 | 1211 | return fwSlot; |
michael@0 | 1212 | } |
michael@0 | 1213 | |
michael@0 | 1214 | /* |
michael@0 | 1215 | * NSSCKFWInstance_GetMDInstance |
michael@0 | 1216 | * |
michael@0 | 1217 | */ |
michael@0 | 1218 | NSS_IMPLEMENT NSSCKMDInstance * |
michael@0 | 1219 | NSSCKFWInstance_GetMDInstance |
michael@0 | 1220 | ( |
michael@0 | 1221 | NSSCKFWInstance *fwInstance |
michael@0 | 1222 | ) |
michael@0 | 1223 | { |
michael@0 | 1224 | #ifdef DEBUG |
michael@0 | 1225 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 1226 | return (NSSCKMDInstance *)NULL; |
michael@0 | 1227 | } |
michael@0 | 1228 | #endif /* DEBUG */ |
michael@0 | 1229 | |
michael@0 | 1230 | return nssCKFWInstance_GetMDInstance(fwInstance); |
michael@0 | 1231 | } |
michael@0 | 1232 | |
michael@0 | 1233 | /* |
michael@0 | 1234 | * NSSCKFWInstance_GetArena |
michael@0 | 1235 | * |
michael@0 | 1236 | */ |
michael@0 | 1237 | NSS_IMPLEMENT NSSArena * |
michael@0 | 1238 | NSSCKFWInstance_GetArena |
michael@0 | 1239 | ( |
michael@0 | 1240 | NSSCKFWInstance *fwInstance, |
michael@0 | 1241 | CK_RV *pError |
michael@0 | 1242 | ) |
michael@0 | 1243 | { |
michael@0 | 1244 | #ifdef DEBUG |
michael@0 | 1245 | if (!pError) { |
michael@0 | 1246 | return (NSSArena *)NULL; |
michael@0 | 1247 | } |
michael@0 | 1248 | |
michael@0 | 1249 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 1250 | if( CKR_OK != *pError ) { |
michael@0 | 1251 | return (NSSArena *)NULL; |
michael@0 | 1252 | } |
michael@0 | 1253 | #endif /* DEBUG */ |
michael@0 | 1254 | |
michael@0 | 1255 | return nssCKFWInstance_GetArena(fwInstance, pError); |
michael@0 | 1256 | } |
michael@0 | 1257 | |
michael@0 | 1258 | /* |
michael@0 | 1259 | * NSSCKFWInstance_MayCreatePthreads |
michael@0 | 1260 | * |
michael@0 | 1261 | */ |
michael@0 | 1262 | NSS_IMPLEMENT CK_BBOOL |
michael@0 | 1263 | NSSCKFWInstance_MayCreatePthreads |
michael@0 | 1264 | ( |
michael@0 | 1265 | NSSCKFWInstance *fwInstance |
michael@0 | 1266 | ) |
michael@0 | 1267 | { |
michael@0 | 1268 | #ifdef DEBUG |
michael@0 | 1269 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 1270 | return CK_FALSE; |
michael@0 | 1271 | } |
michael@0 | 1272 | #endif /* DEBUG */ |
michael@0 | 1273 | |
michael@0 | 1274 | return nssCKFWInstance_MayCreatePthreads(fwInstance); |
michael@0 | 1275 | } |
michael@0 | 1276 | |
michael@0 | 1277 | /* |
michael@0 | 1278 | * NSSCKFWInstance_CreateMutex |
michael@0 | 1279 | * |
michael@0 | 1280 | */ |
michael@0 | 1281 | NSS_IMPLEMENT NSSCKFWMutex * |
michael@0 | 1282 | NSSCKFWInstance_CreateMutex |
michael@0 | 1283 | ( |
michael@0 | 1284 | NSSCKFWInstance *fwInstance, |
michael@0 | 1285 | NSSArena *arena, |
michael@0 | 1286 | CK_RV *pError |
michael@0 | 1287 | ) |
michael@0 | 1288 | { |
michael@0 | 1289 | #ifdef DEBUG |
michael@0 | 1290 | if (!pError) { |
michael@0 | 1291 | return (NSSCKFWMutex *)NULL; |
michael@0 | 1292 | } |
michael@0 | 1293 | |
michael@0 | 1294 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 1295 | if( CKR_OK != *pError ) { |
michael@0 | 1296 | return (NSSCKFWMutex *)NULL; |
michael@0 | 1297 | } |
michael@0 | 1298 | #endif /* DEBUG */ |
michael@0 | 1299 | |
michael@0 | 1300 | return nssCKFWInstance_CreateMutex(fwInstance, arena, pError); |
michael@0 | 1301 | } |
michael@0 | 1302 | |
michael@0 | 1303 | /* |
michael@0 | 1304 | * NSSCKFWInstance_GetConfigurationData |
michael@0 | 1305 | * |
michael@0 | 1306 | */ |
michael@0 | 1307 | NSS_IMPLEMENT NSSUTF8 * |
michael@0 | 1308 | NSSCKFWInstance_GetConfigurationData |
michael@0 | 1309 | ( |
michael@0 | 1310 | NSSCKFWInstance *fwInstance |
michael@0 | 1311 | ) |
michael@0 | 1312 | { |
michael@0 | 1313 | #ifdef DEBUG |
michael@0 | 1314 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 1315 | return (NSSUTF8 *)NULL; |
michael@0 | 1316 | } |
michael@0 | 1317 | #endif /* DEBUG */ |
michael@0 | 1318 | |
michael@0 | 1319 | return nssCKFWInstance_GetConfigurationData(fwInstance); |
michael@0 | 1320 | } |
michael@0 | 1321 | |
michael@0 | 1322 | /* |
michael@0 | 1323 | * NSSCKFWInstance_GetInitArgs |
michael@0 | 1324 | * |
michael@0 | 1325 | */ |
michael@0 | 1326 | NSS_IMPLEMENT CK_C_INITIALIZE_ARGS_PTR |
michael@0 | 1327 | NSSCKFWInstance_GetInitArgs |
michael@0 | 1328 | ( |
michael@0 | 1329 | NSSCKFWInstance *fwInstance |
michael@0 | 1330 | ) |
michael@0 | 1331 | { |
michael@0 | 1332 | #ifdef DEBUG |
michael@0 | 1333 | if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { |
michael@0 | 1334 | return (CK_C_INITIALIZE_ARGS_PTR)NULL; |
michael@0 | 1335 | } |
michael@0 | 1336 | #endif /* DEBUG */ |
michael@0 | 1337 | |
michael@0 | 1338 | return nssCKFWInstance_GetInitArgs(fwInstance); |
michael@0 | 1339 | } |
michael@0 | 1340 |