some attribute and session cleanup

This commit is contained in:
ian.mcgreer%sun.com 2001-11-05 17:18:48 +00:00
Родитель c423baa81d
Коммит cd5938ad76
5 изменённых файлов: 140 добавлений и 38 удалений

Просмотреть файл

@ -32,7 +32,7 @@
*/ */
#ifdef DEBUG #ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: ckhelper.c,v $ $Revision: 1.8 $ $Date: 2001-10-19 18:10:57 $ $Name: $"; static const char CVS_ID[] = "@(#) $RCSfile: ckhelper.c,v $ $Revision: 1.9 $ $Date: 2001-11-05 17:18:47 $ $Name: $";
#endif /* DEBUG */ #endif /* DEBUG */
#ifndef PKIT_H #ifndef PKIT_H
@ -111,13 +111,17 @@ nssCKObject_GetAttributes
/* Get the storage size needed for each attribute */ /* Get the storage size needed for each attribute */
ckrv = CKAPI(slot)->C_GetAttributeValue(hSession, ckrv = CKAPI(slot)->C_GetAttributeValue(hSession,
object, obj_template, count); object, obj_template, count);
if (ckrv != CKR_OK) { if (ckrv != CKR_OK &&
ckrv != CKR_ATTRIBUTE_TYPE_INVALID &&
ckrv != CKR_ATTRIBUTE_SENSITIVE)
{
nssSession_ExitMonitor(session); nssSession_ExitMonitor(session);
/* set an error here */ /* set an error here */
goto loser; goto loser;
} }
/* Allocate memory for each attribute. */ /* Allocate memory for each attribute. */
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
if ((CK_LONG)obj_template[i].ulValueLen <= 0) continue;
obj_template[i].pValue = nss_ZAlloc(arenaOpt, obj_template[i].pValue = nss_ZAlloc(arenaOpt,
obj_template[i].ulValueLen); obj_template[i].ulValueLen);
if (!obj_template[i].pValue) { if (!obj_template[i].pValue) {
@ -131,7 +135,10 @@ nssCKObject_GetAttributes
ckrv = CKAPI(slot)->C_GetAttributeValue(hSession, ckrv = CKAPI(slot)->C_GetAttributeValue(hSession,
object, obj_template, count); object, obj_template, count);
nssSession_ExitMonitor(session); nssSession_ExitMonitor(session);
if (ckrv != CKR_OK) { if (ckrv != CKR_OK &&
ckrv != CKR_ATTRIBUTE_TYPE_INVALID &&
ckrv != CKR_ATTRIBUTE_SENSITIVE)
{
/* set an error here */ /* set an error here */
goto loser; goto loser;
} }
@ -230,3 +237,29 @@ nssCKObject_SetAttributes
} }
} }
/*
NSS_IMPLEMENT PRBool
nssCKObject_IsTokenObject
(
CK_OBJECT_HANDLE object
)
{
}
*/
NSS_IMPLEMENT PRBool
nssCKObject_IsTokenObjectTemplate
(
CK_ATTRIBUTE_PTR objectTemplate,
CK_ULONG otsize
)
{
CK_ULONG ul;
for (ul=0; ul<otsize; ul++) {
if (objectTemplate[ul].type == CKA_TOKEN) {
return (*((CK_BBOOL*)objectTemplate[ul].pValue) == CK_TRUE);
}
}
return PR_FALSE;
}

Просмотреть файл

@ -41,7 +41,7 @@
#define CKHELPER_H #define CKHELPER_H
#ifdef DEBUG #ifdef DEBUG
static const char CKHELPER_CVS_ID[] = "@(#) $RCSfile: ckhelper.h,v $ $Revision: 1.8 $ $Date: 2001-10-19 18:10:58 $ $Name: $"; static const char CKHELPER_CVS_ID[] = "@(#) $RCSfile: ckhelper.h,v $ $Revision: 1.9 $ $Date: 2001-11-05 17:18:47 $ $Name: $";
#endif /* DEBUG */ #endif /* DEBUG */
#ifdef NSS_3_4_CODE #ifdef NSS_3_4_CODE
@ -89,8 +89,10 @@ NSS_EXTERN_DATA const NSSItem g_ck_class_privkey;
* Convert a CK_ATTRIBUTE to an NSSItem. * Convert a CK_ATTRIBUTE to an NSSItem.
*/ */
#define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) \ #define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) \
if ((CK_LONG)(attrib)->ulValueLen > 0) { \
(item)->data = (void *)(attrib)->pValue; \ (item)->data = (void *)(attrib)->pValue; \
(item)->size = (PRUint32)(attrib)->ulValueLen; \ (item)->size = (PRUint32)(attrib)->ulValueLen; \
}
/* NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str) /* NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str)
* *
@ -151,6 +153,13 @@ nssCKObject_SetAttributes
NSSSlot *slot NSSSlot *slot
); );
NSS_EXTERN PRBool
nssCKObject_IsTokenObjectTemplate
(
CK_ATTRIBUTE_PTR objectTemplate,
CK_ULONG otsize
);
PR_END_EXTERN_C PR_END_EXTERN_C
#endif /* CKHELPER_H */ #endif /* CKHELPER_H */

Просмотреть файл

@ -32,7 +32,7 @@
*/ */
#ifdef DEBUG #ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: nss3hack.c,v $ $Revision: 1.1 $ $Date: 2001-10-11 16:33:38 $ $Name: $"; static const char CVS_ID[] = "@(#) $RCSfile: nss3hack.c,v $ $Revision: 1.2 $ $Date: 2001-11-05 17:18:48 $ $Name: $";
#endif /* DEBUG */ #endif /* DEBUG */
#ifndef PKIT_H #ifndef PKIT_H
@ -67,6 +67,45 @@ nssSession_ImportNSS3Session(NSSArena *arenaOpt,
return rvSession; return rvSession;
} }
NSS_IMPLEMENT nssSession *
nssSlot_CreateSession
(
NSSSlot *slot,
NSSArena *arenaOpt,
PRBool readWrite
)
{
nssSession *rvSession;
rvSession = nss_ZNEW(arenaOpt, nssSession);
if (!rvSession) {
return (nssSession *)NULL;
}
if (readWrite) {
rvSession->handle = PK11_GetRWSession(slot->pk11slot);
rvSession->isRW = PR_TRUE;
rvSession->slot = slot;
return rvSession;
} else {
return NULL;
}
}
NSS_IMPLEMENT PRStatus
nssSession_Destroy
(
nssSession *s
)
{
CK_RV ckrv = CKR_OK;
if (s) {
if (s->isRW) {
PK11_RestoreROSession(s->slot->pk11slot, s->handle);
}
nss_ZFreeIf(s);
}
return (ckrv == CKR_OK) ? PR_SUCCESS : PR_FAILURE;
}
static NSSSlot * static NSSSlot *
nssSlot_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot) nssSlot_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot)
{ {
@ -117,6 +156,7 @@ nssToken_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot)
} }
rvToken->slot = nssSlot_CreateFromPK11SlotInfo(td, nss3slot); rvToken->slot = nssSlot_CreateFromPK11SlotInfo(td, nss3slot);
rvToken->slot->token = rvToken; rvToken->slot->token = rvToken;
rvToken->defaultSession->slot = rvToken->slot;
return rvToken; return rvToken;
} }

Просмотреть файл

@ -32,7 +32,7 @@
*/ */
#ifdef DEBUG #ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: slot.c,v $ $Revision: 1.9 $ $Date: 2001-10-11 16:33:38 $ $Name: $"; static const char CVS_ID[] = "@(#) $RCSfile: slot.c,v $ $Revision: 1.10 $ $Date: 2001-11-05 17:18:48 $ $Name: $";
#endif /* DEBUG */ #endif /* DEBUG */
#ifndef DEV_H #ifndef DEV_H
@ -438,6 +438,7 @@ nssSlot_SetPassword
return nssrv; return nssrv;
} }
#ifdef PURE_STAN
NSS_IMPLEMENT nssSession * NSS_IMPLEMENT nssSession *
nssSlot_CreateSession nssSlot_CreateSession
( (
@ -504,6 +505,7 @@ nssSession_Destroy
} }
return (ckrv == CKR_OK) ? PR_SUCCESS : PR_FAILURE; return (ckrv == CKR_OK) ? PR_SUCCESS : PR_FAILURE;
} }
#endif
NSS_IMPLEMENT PRStatus NSS_IMPLEMENT PRStatus
nssSession_EnterMonitor nssSession_EnterMonitor

Просмотреть файл

@ -32,7 +32,7 @@
*/ */
#ifdef DEBUG #ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: token.c,v $ $Revision: 1.12 $ $Date: 2001-10-19 18:10:58 $ $Name: $"; static const char CVS_ID[] = "@(#) $RCSfile: token.c,v $ $Revision: 1.13 $ $Date: 2001-11-05 17:18:48 $ $Name: $";
#endif /* DEBUG */ #endif /* DEBUG */
#ifndef DEV_H #ifndef DEV_H
@ -241,16 +241,34 @@ nssToken_ImportObject
) )
{ {
nssSession *session; nssSession *session;
PRBool createdSession = PR_FALSE;
CK_OBJECT_HANDLE object; CK_OBJECT_HANDLE object;
CK_RV ckrv; CK_RV ckrv;
session = (sessionOpt) ? sessionOpt : tok->defaultSession; session = (sessionOpt) ? sessionOpt : tok->defaultSession;
if (nssCKObject_IsTokenObjectTemplate(objectTemplate, otsize)) {
if (sessionOpt) {
if (!nssSession_IsReadWrite(sessionOpt)) {
return CK_INVALID_HANDLE;
} else {
session = sessionOpt;
}
} else if (nssSession_IsReadWrite(tok->defaultSession)) {
session = tok->defaultSession;
} else {
session = nssSlot_CreateSession(tok->slot, NULL, PR_TRUE);
createdSession = PR_TRUE;
}
}
nssSession_EnterMonitor(session); nssSession_EnterMonitor(session);
ckrv = CKAPI(tok->slot)->C_CreateObject(session->handle, ckrv = CKAPI(tok->slot)->C_CreateObject(session->handle,
objectTemplate, otsize, objectTemplate, otsize,
&object); &object);
nssSession_ExitMonitor(session); nssSession_ExitMonitor(session);
if (createdSession) {
nssSession_Destroy(session);
}
if (ckrv != CKR_OK) { if (ckrv != CKR_OK) {
return CK_INVALID_KEY; return CK_INVALID_HANDLE;
} }
return object; return object;
} }