1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
* This file implements the NSSCKFWInstance type and methods.
18
* -- create/destroy --
19
* nssCKFWInstance_Create
20
* nssCKFWInstance_Destroy
22
* -- public accessors --
23
* NSSCKFWInstance_GetMDInstance
24
* NSSCKFWInstance_GetArena
25
* NSSCKFWInstance_MayCreatePthreads
26
* NSSCKFWInstance_CreateMutex
27
* NSSCKFWInstance_GetConfigurationData
28
* NSSCKFWInstance_GetInitArgs
30
* -- implement public accessors --
31
* nssCKFWInstance_GetMDInstance
32
* nssCKFWInstance_GetArena
33
* nssCKFWInstance_MayCreatePthreads
34
* nssCKFWInstance_CreateMutex
35
* nssCKFWInstance_GetConfigurationData
36
* nssCKFWInstance_GetInitArgs
38
* -- private accessors --
39
* nssCKFWInstance_CreateSessionHandle
40
* nssCKFWInstance_ResolveSessionHandle
41
* nssCKFWInstance_DestroySessionHandle
42
* nssCKFWInstance_FindSessionHandle
43
* nssCKFWInstance_CreateObjectHandle
44
* nssCKFWInstance_ResolveObjectHandle
45
* nssCKFWInstance_DestroyObjectHandle
48
* nssCKFWInstance_GetNSlots
49
* nssCKFWInstance_GetCryptokiVersion
50
* nssCKFWInstance_GetManufacturerID
51
* nssCKFWInstance_GetFlags
52
* nssCKFWInstance_GetLibraryDescription
53
* nssCKFWInstance_GetLibraryVersion
54
* nssCKFWInstance_GetModuleHandlesSessionObjects
55
* nssCKFWInstance_GetSlots
56
* nssCKFWInstance_WaitForSlotEvent
58
* -- debugging versions only --
59
* nssCKFWInstance_verifyPointer
62
struct NSSCKFWInstanceStr {
65
NSSCKMDInstance *mdInstance;
66
CK_C_INITIALIZE_ARGS_PTR pInitArgs;
67
CK_C_INITIALIZE_ARGS initArgs;
68
CryptokiLockingState LockingState;
69
CK_BBOOL mayCreatePthreads;
70
NSSUTF8 *configurationData;
72
NSSCKFWSlot **fwSlotList;
73
NSSCKMDSlot **mdSlotList;
74
CK_BBOOL moduleHandlesSessionObjects;
77
* Everything above is set at creation time, and then not modified.
78
* The invariants the mutex protects are:
80
* 1) Each of the cached descriptions (versions, etc.) are in an
81
* internally consistant state.
83
* 2) The session handle hashes and count are consistant
85
* 3) The object handle hashes and count are consistant.
87
* I could use multiple locks, but let's wait to see if that's
90
* Note that the calls accessing the cached descriptions will
91
* call the NSSCKMDInstance methods with the mutex locked. Those
92
* methods may then call the public NSSCKFWInstance routines.
93
* Those public routines only access the constant data above, so
94
* there's no problem. But be careful if you add to this object;
95
* mutexes are in general not reentrant, so don't create deadlock
99
CK_VERSION cryptokiVersion;
100
NSSUTF8 *manufacturerID;
101
NSSUTF8 *libraryDescription;
102
CK_VERSION libraryVersion;
104
CK_ULONG lastSessionHandle;
105
nssCKFWHash *sessionHandleHash;
107
CK_ULONG lastObjectHandle;
108
nssCKFWHash *objectHandleHash;
113
* But first, the pointer-tracking stuff.
115
* NOTE: the pointer-tracking support in NSS/base currently relies
116
* upon NSPR's CallOnce support. That, however, relies upon NSPR's
117
* locking, which is tied into the runtime. We need a pointer-tracker
118
* implementation that uses the locks supplied through C_Initialize.
119
* That support, however, can be filled in later. So for now, I'll
120
* just do this routines as no-ops.
126
const NSSCKFWInstance *fwInstance
133
instance_remove_pointer
135
const NSSCKFWInstance *fwInstance
142
nssCKFWInstance_verifyPointer
144
const NSSCKFWInstance *fwInstance
153
* nssCKFWInstance_Create
156
NSS_IMPLEMENT NSSCKFWInstance *
157
nssCKFWInstance_Create
159
CK_C_INITIALIZE_ARGS_PTR pInitArgs,
160
CryptokiLockingState LockingState,
161
NSSCKMDInstance *mdInstance,
165
NSSCKFWInstance *fwInstance;
166
NSSArena *arena = (NSSArena *)NULL;
168
CK_BBOOL called_Initialize = CK_FALSE;
171
if( (CK_RV)NULL == pError ) {
172
return (NSSCKFWInstance *)NULL;
176
*pError = CKR_ARGUMENTS_BAD;
177
return (NSSCKFWInstance *)NULL;
179
#endif /* NSSDEBUG */
181
arena = NSSArena_Create();
183
*pError = CKR_HOST_MEMORY;
184
return (NSSCKFWInstance *)NULL;
187
fwInstance = nss_ZNEW(arena, NSSCKFWInstance);
192
fwInstance->arena = arena;
193
fwInstance->mdInstance = mdInstance;
195
fwInstance->LockingState = LockingState;
196
if( (CK_C_INITIALIZE_ARGS_PTR)NULL != pInitArgs ) {
197
fwInstance->initArgs = *pInitArgs;
198
fwInstance->pInitArgs = &fwInstance->initArgs;
199
if( pInitArgs->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS ) {
200
fwInstance->mayCreatePthreads = CK_FALSE;
202
fwInstance->mayCreatePthreads = CK_TRUE;
204
fwInstance->configurationData = (NSSUTF8 *)(pInitArgs->pReserved);
206
fwInstance->mayCreatePthreads = CK_TRUE;
209
fwInstance->mutex = nssCKFWMutex_Create(pInitArgs, LockingState, arena,
211
if (!fwInstance->mutex) {
212
if( CKR_OK == *pError ) {
213
*pError = CKR_GENERAL_ERROR;
218
if (mdInstance->Initialize) {
219
*pError = mdInstance->Initialize(mdInstance, fwInstance, fwInstance->configurationData);
220
if( CKR_OK != *pError ) {
224
called_Initialize = CK_TRUE;
227
if (mdInstance->ModuleHandlesSessionObjects) {
228
fwInstance->moduleHandlesSessionObjects =
229
mdInstance->ModuleHandlesSessionObjects(mdInstance, fwInstance);
231
fwInstance->moduleHandlesSessionObjects = CK_FALSE;
234
if (!mdInstance->GetNSlots) {
235
/* That routine is required */
236
*pError = CKR_GENERAL_ERROR;
240
fwInstance->nSlots = mdInstance->GetNSlots(mdInstance, fwInstance, pError);
241
if( (CK_ULONG)0 == fwInstance->nSlots ) {
242
if( CKR_OK == *pError ) {
243
/* Zero is not a legitimate answer */
244
*pError = CKR_GENERAL_ERROR;
249
fwInstance->fwSlotList = nss_ZNEWARRAY(arena, NSSCKFWSlot *, fwInstance->nSlots);
250
if( (NSSCKFWSlot **)NULL == fwInstance->fwSlotList ) {
254
fwInstance->mdSlotList = nss_ZNEWARRAY(arena, NSSCKMDSlot *, fwInstance->nSlots);
255
if( (NSSCKMDSlot **)NULL == fwInstance->mdSlotList ) {
259
fwInstance->sessionHandleHash = nssCKFWHash_Create(fwInstance,
260
fwInstance->arena, pError);
261
if (!fwInstance->sessionHandleHash) {
265
fwInstance->objectHandleHash = nssCKFWHash_Create(fwInstance,
266
fwInstance->arena, pError);
267
if (!fwInstance->objectHandleHash) {
271
if (!mdInstance->GetSlots) {
272
/* That routine is required */
273
*pError = CKR_GENERAL_ERROR;
277
*pError = mdInstance->GetSlots(mdInstance, fwInstance, fwInstance->mdSlotList);
278
if( CKR_OK != *pError ) {
282
for( i = 0; i < fwInstance->nSlots; i++ ) {
283
NSSCKMDSlot *mdSlot = fwInstance->mdSlotList[i];
286
*pError = CKR_GENERAL_ERROR;
290
fwInstance->fwSlotList[i] = nssCKFWSlot_Create(fwInstance, mdSlot, i, pError);
291
if( CKR_OK != *pError ) {
294
for( j = 0; j < i; j++ ) {
295
(void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[j]);
298
for( j = i; j < fwInstance->nSlots; j++ ) {
299
NSSCKMDSlot *mds = fwInstance->mdSlotList[j];
301
mds->Destroy(mds, (NSSCKFWSlot *)NULL, mdInstance, fwInstance);
310
*pError = instance_add_pointer(fwInstance);
311
if( CKR_OK != *pError ) {
312
for( i = 0; i < fwInstance->nSlots; i++ ) {
313
(void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]);
324
*pError = CKR_HOST_MEMORY;
328
if( CK_TRUE == called_Initialize ) {
329
if (mdInstance->Finalize) {
330
mdInstance->Finalize(mdInstance, fwInstance);
334
if (fwInstance && fwInstance->mutex) {
335
nssCKFWMutex_Destroy(fwInstance->mutex);
339
(void)NSSArena_Destroy(arena);
341
return (NSSCKFWInstance *)NULL;
345
* nssCKFWInstance_Destroy
349
nssCKFWInstance_Destroy
351
NSSCKFWInstance *fwInstance
355
CK_RV error = CKR_OK;
356
#endif /* NSSDEBUG */
360
error = nssCKFWInstance_verifyPointer(fwInstance);
361
if( CKR_OK != error ) {
364
#endif /* NSSDEBUG */
366
nssCKFWMutex_Destroy(fwInstance->mutex);
368
for( i = 0; i < fwInstance->nSlots; i++ ) {
369
(void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]);
372
if (fwInstance->mdInstance->Finalize) {
373
fwInstance->mdInstance->Finalize(fwInstance->mdInstance, fwInstance);
376
if (fwInstance->sessionHandleHash) {
377
nssCKFWHash_Destroy(fwInstance->sessionHandleHash);
380
if (fwInstance->objectHandleHash) {
381
nssCKFWHash_Destroy(fwInstance->objectHandleHash);
385
(void)instance_remove_pointer(fwInstance);
388
(void)NSSArena_Destroy(fwInstance->arena);
393
* nssCKFWInstance_GetMDInstance
396
NSS_IMPLEMENT NSSCKMDInstance *
397
nssCKFWInstance_GetMDInstance
399
NSSCKFWInstance *fwInstance
403
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
404
return (NSSCKMDInstance *)NULL;
406
#endif /* NSSDEBUG */
408
return fwInstance->mdInstance;
412
* nssCKFWInstance_GetArena
415
NSS_IMPLEMENT NSSArena *
416
nssCKFWInstance_GetArena
418
NSSCKFWInstance *fwInstance,
424
return (NSSArena *)NULL;
427
*pError = nssCKFWInstance_verifyPointer(fwInstance);
428
if( CKR_OK != *pError ) {
429
return (NSSArena *)NULL;
431
#endif /* NSSDEBUG */
434
return fwInstance->arena;
438
* nssCKFWInstance_MayCreatePthreads
441
NSS_IMPLEMENT CK_BBOOL
442
nssCKFWInstance_MayCreatePthreads
444
NSSCKFWInstance *fwInstance
448
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
451
#endif /* NSSDEBUG */
453
return fwInstance->mayCreatePthreads;
457
* nssCKFWInstance_CreateMutex
460
NSS_IMPLEMENT NSSCKFWMutex *
461
nssCKFWInstance_CreateMutex
463
NSSCKFWInstance *fwInstance,
472
return (NSSCKFWMutex *)NULL;
475
*pError = nssCKFWInstance_verifyPointer(fwInstance);
476
if( CKR_OK != *pError ) {
477
return (NSSCKFWMutex *)NULL;
479
#endif /* NSSDEBUG */
481
mutex = nssCKFWMutex_Create(fwInstance->pInitArgs, fwInstance->LockingState,
484
if( CKR_OK == *pError ) {
485
*pError = CKR_GENERAL_ERROR;
488
return (NSSCKFWMutex *)NULL;
495
* nssCKFWInstance_GetConfigurationData
498
NSS_IMPLEMENT NSSUTF8 *
499
nssCKFWInstance_GetConfigurationData
501
NSSCKFWInstance *fwInstance
505
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
506
return (NSSUTF8 *)NULL;
508
#endif /* NSSDEBUG */
510
return fwInstance->configurationData;
514
* nssCKFWInstance_GetInitArgs
517
CK_C_INITIALIZE_ARGS_PTR
518
nssCKFWInstance_GetInitArgs
520
NSSCKFWInstance *fwInstance
524
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
525
return (CK_C_INITIALIZE_ARGS_PTR)NULL;
527
#endif /* NSSDEBUG */
529
return fwInstance->pInitArgs;
533
* nssCKFWInstance_CreateSessionHandle
536
NSS_IMPLEMENT CK_SESSION_HANDLE
537
nssCKFWInstance_CreateSessionHandle
539
NSSCKFWInstance *fwInstance,
540
NSSCKFWSession *fwSession,
544
CK_SESSION_HANDLE hSession;
548
return (CK_SESSION_HANDLE)0;
551
*pError = nssCKFWInstance_verifyPointer(fwInstance);
552
if( CKR_OK != *pError ) {
553
return (CK_SESSION_HANDLE)0;
555
#endif /* NSSDEBUG */
557
*pError = nssCKFWMutex_Lock(fwInstance->mutex);
558
if( CKR_OK != *pError ) {
559
return (CK_SESSION_HANDLE)0;
562
hSession = ++(fwInstance->lastSessionHandle);
564
/* Alan would say I should unlock for this call. */
566
*pError = nssCKFWSession_SetHandle(fwSession, hSession);
567
if( CKR_OK != *pError ) {
571
*pError = nssCKFWHash_Add(fwInstance->sessionHandleHash,
572
(const void *)hSession, (const void *)fwSession);
573
if( CKR_OK != *pError ) {
574
hSession = (CK_SESSION_HANDLE)0;
579
nssCKFWMutex_Unlock(fwInstance->mutex);
584
* nssCKFWInstance_ResolveSessionHandle
587
NSS_IMPLEMENT NSSCKFWSession *
588
nssCKFWInstance_ResolveSessionHandle
590
NSSCKFWInstance *fwInstance,
591
CK_SESSION_HANDLE hSession
594
NSSCKFWSession *fwSession;
597
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
598
return (NSSCKFWSession *)NULL;
600
#endif /* NSSDEBUG */
602
if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
603
return (NSSCKFWSession *)NULL;
606
fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup(
607
fwInstance->sessionHandleHash, (const void *)hSession);
609
/* Assert(hSession == nssCKFWSession_GetHandle(fwSession)) */
611
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
617
* nssCKFWInstance_DestroySessionHandle
621
nssCKFWInstance_DestroySessionHandle
623
NSSCKFWInstance *fwInstance,
624
CK_SESSION_HANDLE hSession
627
NSSCKFWSession *fwSession;
630
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
633
#endif /* NSSDEBUG */
635
if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
639
fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup(
640
fwInstance->sessionHandleHash, (const void *)hSession);
642
nssCKFWHash_Remove(fwInstance->sessionHandleHash, (const void *)hSession);
643
nssCKFWSession_SetHandle(fwSession, (CK_SESSION_HANDLE)0);
646
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
652
* nssCKFWInstance_FindSessionHandle
655
NSS_IMPLEMENT CK_SESSION_HANDLE
656
nssCKFWInstance_FindSessionHandle
658
NSSCKFWInstance *fwInstance,
659
NSSCKFWSession *fwSession
663
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
664
return (CK_SESSION_HANDLE)0;
667
if( CKR_OK != nssCKFWSession_verifyPointer(fwSession) ) {
668
return (CK_SESSION_HANDLE)0;
670
#endif /* NSSDEBUG */
672
return nssCKFWSession_GetHandle(fwSession);
673
/* look it up and assert? */
677
* nssCKFWInstance_CreateObjectHandle
680
NSS_IMPLEMENT CK_OBJECT_HANDLE
681
nssCKFWInstance_CreateObjectHandle
683
NSSCKFWInstance *fwInstance,
684
NSSCKFWObject *fwObject,
688
CK_OBJECT_HANDLE hObject;
692
return (CK_OBJECT_HANDLE)0;
695
*pError = nssCKFWInstance_verifyPointer(fwInstance);
696
if( CKR_OK != *pError ) {
697
return (CK_OBJECT_HANDLE)0;
699
#endif /* NSSDEBUG */
701
*pError = nssCKFWMutex_Lock(fwInstance->mutex);
702
if( CKR_OK != *pError ) {
703
return (CK_OBJECT_HANDLE)0;
706
hObject = ++(fwInstance->lastObjectHandle);
708
*pError = nssCKFWObject_SetHandle(fwObject, hObject);
709
if( CKR_OK != *pError ) {
710
hObject = (CK_OBJECT_HANDLE)0;
714
*pError = nssCKFWHash_Add(fwInstance->objectHandleHash,
715
(const void *)hObject, (const void *)fwObject);
716
if( CKR_OK != *pError ) {
717
hObject = (CK_OBJECT_HANDLE)0;
722
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
727
* nssCKFWInstance_ResolveObjectHandle
730
NSS_IMPLEMENT NSSCKFWObject *
731
nssCKFWInstance_ResolveObjectHandle
733
NSSCKFWInstance *fwInstance,
734
CK_OBJECT_HANDLE hObject
737
NSSCKFWObject *fwObject;
740
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
741
return (NSSCKFWObject *)NULL;
743
#endif /* NSSDEBUG */
745
if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
746
return (NSSCKFWObject *)NULL;
749
fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
750
fwInstance->objectHandleHash, (const void *)hObject);
752
/* Assert(hObject == nssCKFWObject_GetHandle(fwObject)) */
754
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
759
* nssCKFWInstance_ReassignObjectHandle
763
nssCKFWInstance_ReassignObjectHandle
765
NSSCKFWInstance *fwInstance,
766
CK_OBJECT_HANDLE hObject,
767
NSSCKFWObject *fwObject
770
CK_RV error = CKR_OK;
771
NSSCKFWObject *oldObject;
774
error = nssCKFWInstance_verifyPointer(fwInstance);
775
if( CKR_OK != error ) {
778
#endif /* NSSDEBUG */
780
error = nssCKFWMutex_Lock(fwInstance->mutex);
781
if( CKR_OK != error ) {
785
oldObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
786
fwInstance->objectHandleHash, (const void *)hObject);
788
/* Assert(hObject == nssCKFWObject_GetHandle(oldObject) */
789
(void)nssCKFWObject_SetHandle(oldObject, (CK_SESSION_HANDLE)0);
790
nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);
793
error = nssCKFWObject_SetHandle(fwObject, hObject);
794
if( CKR_OK != error ) {
797
error = nssCKFWHash_Add(fwInstance->objectHandleHash,
798
(const void *)hObject, (const void *)fwObject);
801
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
806
* nssCKFWInstance_DestroyObjectHandle
810
nssCKFWInstance_DestroyObjectHandle
812
NSSCKFWInstance *fwInstance,
813
CK_OBJECT_HANDLE hObject
816
NSSCKFWObject *fwObject;
819
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
822
#endif /* NSSDEBUG */
824
if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
828
fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
829
fwInstance->objectHandleHash, (const void *)hObject);
831
/* Assert(hObject = nssCKFWObject_GetHandle(fwObject)) */
832
nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);
833
(void)nssCKFWObject_SetHandle(fwObject, (CK_SESSION_HANDLE)0);
836
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
841
* nssCKFWInstance_FindObjectHandle
844
NSS_IMPLEMENT CK_OBJECT_HANDLE
845
nssCKFWInstance_FindObjectHandle
847
NSSCKFWInstance *fwInstance,
848
NSSCKFWObject *fwObject
852
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
853
return (CK_OBJECT_HANDLE)0;
856
if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
857
return (CK_OBJECT_HANDLE)0;
859
#endif /* NSSDEBUG */
861
return nssCKFWObject_GetHandle(fwObject);
865
* nssCKFWInstance_GetNSlots
868
NSS_IMPLEMENT CK_ULONG
869
nssCKFWInstance_GetNSlots
871
NSSCKFWInstance *fwInstance,
880
*pError = nssCKFWInstance_verifyPointer(fwInstance);
881
if( CKR_OK != *pError ) {
884
#endif /* NSSDEBUG */
887
return fwInstance->nSlots;
891
* nssCKFWInstance_GetCryptokiVersion
894
NSS_IMPLEMENT CK_VERSION
895
nssCKFWInstance_GetCryptokiVersion
897
NSSCKFWInstance *fwInstance
903
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
904
rv.major = rv.minor = 0;
907
#endif /* NSSDEBUG */
909
if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
910
rv.major = rv.minor = 0;
914
if( (0 != fwInstance->cryptokiVersion.major) ||
915
(0 != fwInstance->cryptokiVersion.minor) ) {
916
rv = fwInstance->cryptokiVersion;
920
if (fwInstance->mdInstance->GetCryptokiVersion) {
921
fwInstance->cryptokiVersion = fwInstance->mdInstance->GetCryptokiVersion(
922
fwInstance->mdInstance, fwInstance);
924
fwInstance->cryptokiVersion.major = 2;
925
fwInstance->cryptokiVersion.minor = 1;
928
rv = fwInstance->cryptokiVersion;
931
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
936
* nssCKFWInstance_GetManufacturerID
940
nssCKFWInstance_GetManufacturerID
942
NSSCKFWInstance *fwInstance,
943
CK_CHAR manufacturerID[32]
946
CK_RV error = CKR_OK;
949
if( (CK_CHAR_PTR)NULL == manufacturerID ) {
950
return CKR_ARGUMENTS_BAD;
953
error = nssCKFWInstance_verifyPointer(fwInstance);
954
if( CKR_OK != error ) {
957
#endif /* NSSDEBUG */
959
error = nssCKFWMutex_Lock(fwInstance->mutex);
960
if( CKR_OK != error ) {
964
if (!fwInstance->manufacturerID) {
965
if (fwInstance->mdInstance->GetManufacturerID) {
966
fwInstance->manufacturerID = fwInstance->mdInstance->GetManufacturerID(
967
fwInstance->mdInstance, fwInstance, &error);
968
if ((!fwInstance->manufacturerID) && (CKR_OK != error)) {
972
fwInstance->manufacturerID = (NSSUTF8 *) "";
976
(void)nssUTF8_CopyIntoFixedBuffer(fwInstance->manufacturerID, (char *)manufacturerID, 32, ' ');
980
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
985
* nssCKFWInstance_GetFlags
988
NSS_IMPLEMENT CK_ULONG
989
nssCKFWInstance_GetFlags
991
NSSCKFWInstance *fwInstance
995
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
998
#endif /* NSSDEBUG */
1000
/* No "instance flags" are yet defined by Cryptoki. */
1005
* nssCKFWInstance_GetLibraryDescription
1009
nssCKFWInstance_GetLibraryDescription
1011
NSSCKFWInstance *fwInstance,
1012
CK_CHAR libraryDescription[32]
1015
CK_RV error = CKR_OK;
1018
if( (CK_CHAR_PTR)NULL == libraryDescription ) {
1019
return CKR_ARGUMENTS_BAD;
1022
error = nssCKFWInstance_verifyPointer(fwInstance);
1023
if( CKR_OK != error ) {
1026
#endif /* NSSDEBUG */
1028
error = nssCKFWMutex_Lock(fwInstance->mutex);
1029
if( CKR_OK != error ) {
1033
if (!fwInstance->libraryDescription) {
1034
if (fwInstance->mdInstance->GetLibraryDescription) {
1035
fwInstance->libraryDescription = fwInstance->mdInstance->GetLibraryDescription(
1036
fwInstance->mdInstance, fwInstance, &error);
1037
if ((!fwInstance->libraryDescription) && (CKR_OK != error)) {
1041
fwInstance->libraryDescription = (NSSUTF8 *) "";
1045
(void)nssUTF8_CopyIntoFixedBuffer(fwInstance->libraryDescription, (char *)libraryDescription, 32, ' ');
1049
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
1054
* nssCKFWInstance_GetLibraryVersion
1057
NSS_IMPLEMENT CK_VERSION
1058
nssCKFWInstance_GetLibraryVersion
1060
NSSCKFWInstance *fwInstance
1066
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
1067
rv.major = rv.minor = 0;
1070
#endif /* NSSDEBUG */
1072
if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
1073
rv.major = rv.minor = 0;
1077
if( (0 != fwInstance->libraryVersion.major) ||
1078
(0 != fwInstance->libraryVersion.minor) ) {
1079
rv = fwInstance->libraryVersion;
1083
if (fwInstance->mdInstance->GetLibraryVersion) {
1084
fwInstance->libraryVersion = fwInstance->mdInstance->GetLibraryVersion(
1085
fwInstance->mdInstance, fwInstance);
1087
fwInstance->libraryVersion.major = 0;
1088
fwInstance->libraryVersion.minor = 3;
1091
rv = fwInstance->libraryVersion;
1093
(void)nssCKFWMutex_Unlock(fwInstance->mutex);
1098
* nssCKFWInstance_GetModuleHandlesSessionObjects
1101
NSS_IMPLEMENT CK_BBOOL
1102
nssCKFWInstance_GetModuleHandlesSessionObjects
1104
NSSCKFWInstance *fwInstance
1108
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
1111
#endif /* NSSDEBUG */
1113
return fwInstance->moduleHandlesSessionObjects;
1117
* nssCKFWInstance_GetSlots
1120
NSS_IMPLEMENT NSSCKFWSlot **
1121
nssCKFWInstance_GetSlots
1123
NSSCKFWInstance *fwInstance,
1129
return (NSSCKFWSlot **)NULL;
1132
*pError = nssCKFWInstance_verifyPointer(fwInstance);
1133
if( CKR_OK != *pError ) {
1134
return (NSSCKFWSlot **)NULL;
1136
#endif /* NSSDEBUG */
1138
return fwInstance->fwSlotList;
1142
* nssCKFWInstance_WaitForSlotEvent
1145
NSS_IMPLEMENT NSSCKFWSlot *
1146
nssCKFWInstance_WaitForSlotEvent
1148
NSSCKFWInstance *fwInstance,
1153
NSSCKFWSlot *fwSlot = (NSSCKFWSlot *)NULL;
1154
NSSCKMDSlot *mdSlot;
1159
return (NSSCKFWSlot *)NULL;
1162
*pError = nssCKFWInstance_verifyPointer(fwInstance);
1163
if( CKR_OK != *pError ) {
1164
return (NSSCKFWSlot *)NULL;
1172
*pError = CKR_ARGUMENTS_BAD;
1173
return (NSSCKFWSlot *)NULL;
1175
#endif /* NSSDEBUG */
1177
if (!fwInstance->mdInstance->WaitForSlotEvent) {
1178
*pError = CKR_NO_EVENT;
1179
return (NSSCKFWSlot *)NULL;
1182
mdSlot = fwInstance->mdInstance->WaitForSlotEvent(
1183
fwInstance->mdInstance,
1190
return (NSSCKFWSlot *)NULL;
1193
n = nssCKFWInstance_GetNSlots(fwInstance, pError);
1194
if( ((CK_ULONG)0 == n) && (CKR_OK != *pError) ) {
1195
return (NSSCKFWSlot *)NULL;
1198
for( i = 0; i < n; i++ ) {
1199
if( fwInstance->mdSlotList[i] == mdSlot ) {
1200
fwSlot = fwInstance->fwSlotList[i];
1206
/* Internal error */
1207
*pError = CKR_GENERAL_ERROR;
1208
return (NSSCKFWSlot *)NULL;
1215
* NSSCKFWInstance_GetMDInstance
1218
NSS_IMPLEMENT NSSCKMDInstance *
1219
NSSCKFWInstance_GetMDInstance
1221
NSSCKFWInstance *fwInstance
1225
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
1226
return (NSSCKMDInstance *)NULL;
1230
return nssCKFWInstance_GetMDInstance(fwInstance);
1234
* NSSCKFWInstance_GetArena
1237
NSS_IMPLEMENT NSSArena *
1238
NSSCKFWInstance_GetArena
1240
NSSCKFWInstance *fwInstance,
1246
return (NSSArena *)NULL;
1249
*pError = nssCKFWInstance_verifyPointer(fwInstance);
1250
if( CKR_OK != *pError ) {
1251
return (NSSArena *)NULL;
1255
return nssCKFWInstance_GetArena(fwInstance, pError);
1259
* NSSCKFWInstance_MayCreatePthreads
1262
NSS_IMPLEMENT CK_BBOOL
1263
NSSCKFWInstance_MayCreatePthreads
1265
NSSCKFWInstance *fwInstance
1269
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
1274
return nssCKFWInstance_MayCreatePthreads(fwInstance);
1278
* NSSCKFWInstance_CreateMutex
1281
NSS_IMPLEMENT NSSCKFWMutex *
1282
NSSCKFWInstance_CreateMutex
1284
NSSCKFWInstance *fwInstance,
1291
return (NSSCKFWMutex *)NULL;
1294
*pError = nssCKFWInstance_verifyPointer(fwInstance);
1295
if( CKR_OK != *pError ) {
1296
return (NSSCKFWMutex *)NULL;
1300
return nssCKFWInstance_CreateMutex(fwInstance, arena, pError);
1304
* NSSCKFWInstance_GetConfigurationData
1307
NSS_IMPLEMENT NSSUTF8 *
1308
NSSCKFWInstance_GetConfigurationData
1310
NSSCKFWInstance *fwInstance
1314
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
1315
return (NSSUTF8 *)NULL;
1319
return nssCKFWInstance_GetConfigurationData(fwInstance);
1323
* NSSCKFWInstance_GetInitArgs
1326
NSS_IMPLEMENT CK_C_INITIALIZE_ARGS_PTR
1327
NSSCKFWInstance_GetInitArgs
1329
NSSCKFWInstance *fwInstance
1333
if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
1334
return (CK_C_INITIALIZE_ARGS_PTR)NULL;
1338
return nssCKFWInstance_GetInitArgs(fwInstance);