Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
devm.h File Reference
#include "base.h"
#include "nssckt.h"
#include "dev.h"
#include "devtm.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define CKAPI(epv)   ((CK_FUNCTION_LIST_PTR)(epv))

Functions

NSS_EXTERN void nssDevice_AddRef (struct nssDeviceBaseStr *device)
NSS_EXTERN PRBool nssDevice_Destroy (struct nssDeviceBaseStr *device)
NSS_EXTERN PRBool nssModule_IsThreadSafe (NSSModule *module)
NSS_EXTERN PRBool nssModule_IsInternal (NSSModule *mod)
NSS_EXTERN PRBool nssModule_IsModuleDBOnly (NSSModule *mod)
NSS_EXTERN voidnssModule_GetCryptokiEPV (NSSModule *mod)
NSS_EXTERN NSSSlot * nssSlot_Create (CK_SLOT_ID slotId, NSSModule *parent)
NSS_EXTERN voidnssSlot_GetCryptokiEPV (NSSSlot *slot)
NSS_EXTERN NSSToken * nssToken_Create (CK_SLOT_ID slotID, NSSSlot *peer)
NSS_EXTERN voidnssToken_GetCryptokiEPV (NSSToken *token)
NSS_EXTERN nssSession * nssToken_GetDefaultSession (NSSToken *token)
NSS_EXTERN PRBool nssToken_IsLoginRequired (NSSToken *token)
NSS_EXTERN void nssToken_Remove (NSSToken *token)
NSS_EXTERN nssCryptokiObject * nssCryptokiObject_Create (NSSToken *t, nssSession *session, CK_OBJECT_HANDLE h)
NSS_EXTERN nssTokenObjectCache * nssTokenObjectCache_Create (NSSToken *token, PRBool cacheCerts, PRBool cacheTrust, PRBool cacheCRLs)
NSS_EXTERN void nssTokenObjectCache_Destroy (nssTokenObjectCache *cache)
NSS_EXTERN void nssTokenObjectCache_Clear (nssTokenObjectCache *cache)
NSS_EXTERN PRBool nssTokenObjectCache_HaveObjectClass (nssTokenObjectCache *cache, CK_OBJECT_CLASS objclass)
NSS_EXTERN nssCryptokiObject ** nssTokenObjectCache_FindObjectsByTemplate (nssTokenObjectCache *cache, CK_OBJECT_CLASS objclass, CK_ATTRIBUTE_PTR otemplate, CK_ULONG otlen, PRUint32 maximumOpt, PRStatus *statusOpt)
NSS_EXTERN PRStatus nssTokenObjectCache_GetObjectAttributes (nssTokenObjectCache *cache, NSSArena *arenaOpt, nssCryptokiObject *object, CK_OBJECT_CLASS objclass, CK_ATTRIBUTE_PTR atemplate, CK_ULONG atlen)
NSS_EXTERN PRStatus nssTokenObjectCache_ImportObject (nssTokenObjectCache *cache, nssCryptokiObject *object, CK_OBJECT_CLASS objclass, CK_ATTRIBUTE_PTR ot, CK_ULONG otlen)
NSS_EXTERN void nssTokenObjectCache_RemoveObject (nssTokenObjectCache *cache, nssCryptokiObject *object)
NSS_EXTERN PRStatus nssToken_GetCachedObjectAttributes (NSSToken *token, NSSArena *arenaOpt, nssCryptokiObject *object, CK_OBJECT_CLASS objclass, CK_ATTRIBUTE_PTR atemplate, CK_ULONG atlen)
NSS_EXTERN PRUint32 nssPKCS11String_Length (CK_CHAR *pkcs11str, PRUint32 bufLen)

Define Documentation

#define CKAPI (   epv)    ((CK_FUNCTION_LIST_PTR)(epv))

Definition at line 63 of file devm.h.


Function Documentation

NSS_EXTERN nssCryptokiObject* nssCryptokiObject_Create ( NSSToken *  t,
nssSession *  session,
CK_OBJECT_HANDLE  h 
)

Definition at line 50 of file devutil.c.

{
    PRStatus status;
    NSSSlot *slot;
    nssCryptokiObject *object;
    CK_BBOOL *isTokenObject;
    CK_ATTRIBUTE cert_template[] = {
       { CKA_TOKEN, NULL, 0 },
       { CKA_LABEL, NULL, 0 }
    };
    slot = nssToken_GetSlot(t);
    status = nssCKObject_GetAttributes(h, cert_template, 2,
                                       NULL, session, slot);
    nssSlot_Destroy(slot);
    if (status != PR_SUCCESS) {
       /* a failure here indicates a device error */
       return (nssCryptokiObject *)NULL;
    }
    object = nss_ZNEW(NULL, nssCryptokiObject);
    if (!object) {
       return (nssCryptokiObject *)NULL;
    }
    object->handle = h;
    object->token = nssToken_AddRef(t);
    isTokenObject = (CK_BBOOL *)cert_template[0].pValue;
    object->isTokenObject = *isTokenObject;
    nss_ZFreeIf(isTokenObject);
    NSS_CK_ATTRIBUTE_TO_UTF8(&cert_template[1], object->label);
    return object;
}

Here is the caller graph for this function:

NSS_EXTERN void* nssModule_GetCryptokiEPV ( NSSModule *  mod)

Here is the caller graph for this function:

NSS_EXTERN PRBool nssModule_IsInternal ( NSSModule *  mod)
NSS_EXTERN PRBool nssModule_IsThreadSafe ( NSSModule *  module)

Definition at line 125 of file devutil.c.

{
    PRInt32 i;
    for (i = bufLen - 1; i>=0; ) {
       if (pkcs11Str[i] != ' ' && pkcs11Str[i] != '\0') break;
       --i;
    }
    return (PRUint32)(i + 1);
}
NSS_EXTERN NSSSlot* nssSlot_Create ( CK_SLOT_ID  slotId,
NSSModule *  parent 
)
NSS_EXTERN void* nssSlot_GetCryptokiEPV ( NSSSlot *  slot)

Definition at line 250 of file devslot.c.

{
    return slot->epv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSToken* nssToken_Create ( CK_SLOT_ID  slotID,
NSSSlot *  peer 
)

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssToken_GetCachedObjectAttributes ( NSSToken *  token,
NSSArena *  arenaOpt,
nssCryptokiObject *  object,
CK_OBJECT_CLASS  objclass,
CK_ATTRIBUTE_PTR  atemplate,
CK_ULONG  atlen 
)

Definition at line 1298 of file devtoken.c.

{
    if (!token->cache) {
       return PR_FAILURE;
    }
    return nssTokenObjectCache_GetObjectAttributes(token->cache, arenaOpt,
                                                   object, objclass,
                                                   atemplate, atlen);
}

Here is the caller graph for this function:

NSS_EXTERN void* nssToken_GetCryptokiEPV ( NSSToken *  token)

Definition at line 111 of file devtoken.c.

{
    return nssSlot_GetCryptokiEPV(token->slot);
}

Here is the caller graph for this function:

NSS_EXTERN nssSession* nssToken_GetDefaultSession ( NSSToken *  token)

Definition at line 119 of file devtoken.c.

{
    return token->defaultSession;
}

Definition at line 149 of file devtoken.c.

{
    return (token->ckFlags & CKF_LOGIN_REQUIRED);
}
NSS_EXTERN void nssToken_Remove ( NSSToken *  token)

Definition at line 78 of file devtoken.c.

{
    nssTokenObjectCache_Clear(tok->cache);
}

Here is the caller graph for this function:

NSS_EXTERN void nssTokenObjectCache_Clear ( nssTokenObjectCache *  cache)

Definition at line 296 of file devutil.c.

{
    if (cache) {
       PZ_Lock(cache->lock);
       clear_cache(cache);
       PZ_Unlock(cache->lock);
    }
}

Here is the caller graph for this function:

NSS_EXTERN nssTokenObjectCache* nssTokenObjectCache_Create ( NSSToken *  token,
PRBool  cacheCerts,
PRBool  cacheTrust,
PRBool  cacheCRLs 
)

Definition at line 247 of file devutil.c.

{
    nssTokenObjectCache *rvCache;
    rvCache = nss_ZNEW(NULL, nssTokenObjectCache);
    if (!rvCache) {
       goto loser;
    }
    rvCache->lock = PZ_NewLock(nssILockOther); /* XXX */
    if (!rvCache->lock) {
       goto loser;
    }
    rvCache->doObjectType[cachedCerts] = cacheCerts;
    rvCache->doObjectType[cachedTrust] = cacheTrust;
    rvCache->doObjectType[cachedCRLs] = cacheCRLs;
    rvCache->token = token; /* cache goes away with token */
    return rvCache;
loser:
    return (nssTokenObjectCache *)NULL;
}

Here is the caller graph for this function:

NSS_EXTERN void nssTokenObjectCache_Destroy ( nssTokenObjectCache *  cache)

Definition at line 308 of file devutil.c.

Here is the caller graph for this function:

NSS_EXTERN nssCryptokiObject** nssTokenObjectCache_FindObjectsByTemplate ( nssTokenObjectCache *  cache,
CK_OBJECT_CLASS  objclass,
CK_ATTRIBUTE_PTR  otemplate,
CK_ULONG  otlen,
PRUint32  maximumOpt,
PRStatus statusOpt 
)

Definition at line 827 of file devutil.c.

{
    PRStatus status = PR_FAILURE;
    nssCryptokiObject **rvObjects = NULL;
    if (!token_is_present(cache)) {
       status = PR_SUCCESS;
       goto finish;
    }
    PZ_Lock(cache->lock);
    switch (objclass) {
    case CKO_CERTIFICATE:
       if (cache->doObjectType[cachedCerts]) {
           status = get_token_certs_for_cache(cache);
           if (status != PR_SUCCESS) {
              goto unlock;
           }
           rvObjects = find_objects_in_array(cache->objects[cachedCerts], 
                                             otemplate, otlen, maximumOpt);
       }
       break;
    case CKO_NETSCAPE_TRUST:
       if (cache->doObjectType[cachedTrust]) {
           status = get_token_trust_for_cache(cache);
           if (status != PR_SUCCESS) {
              goto unlock;
           }
           rvObjects = find_objects_in_array(cache->objects[cachedTrust], 
                                             otemplate, otlen, maximumOpt);
       }
       break;
    case CKO_NETSCAPE_CRL:
       if (cache->doObjectType[cachedCRLs]) {
           status = get_token_crls_for_cache(cache);
           if (status != PR_SUCCESS) {
              goto unlock;
           }
           rvObjects = find_objects_in_array(cache->objects[cachedCRLs], 
                                             otemplate, otlen, maximumOpt);
       }
       break;
    default: break;
    }
unlock:
    PZ_Unlock(cache->lock);
finish:
    if (statusOpt) {
       *statusOpt = status;
    }
    return rvObjects;
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssTokenObjectCache_GetObjectAttributes ( nssTokenObjectCache *  cache,
NSSArena *  arenaOpt,
nssCryptokiObject *  object,
CK_OBJECT_CLASS  objclass,
CK_ATTRIBUTE_PTR  atemplate,
CK_ULONG  atlen 
)

Definition at line 907 of file devutil.c.

{
    PRUint32 i, j;
    NSSArena *arena = NULL;
    nssArenaMark *mark = NULL;
    nssCryptokiObjectAndAttributes *cachedOA = NULL;
    nssCryptokiObjectAndAttributes **oa = NULL;
    PRUint32 objectType;
    if (!token_is_present(cache)) {
       return PR_FAILURE;
    }
    PZ_Lock(cache->lock);
    switch (objclass) {
    case CKO_CERTIFICATE:    objectType = cachedCerts; break;
    case CKO_NETSCAPE_TRUST: objectType = cachedTrust; break;
    case CKO_NETSCAPE_CRL:   objectType = cachedCRLs;  break;
    default: goto loser;
    }
    if (!cache_available_for_object_type(cache, objectType)) {
       goto loser;
    }
    oa = cache->objects[objectType];
    if (!oa) {
       goto loser;
    }
    for (; *oa; oa++) {
       if (nssCryptokiObject_Equal((*oa)->object, object)) {
           cachedOA = *oa;
           break;
       }
    }
    if (!cachedOA) {
       goto loser; /* don't have this object */
    }
    if (arenaOpt) {
       arena = arenaOpt;
       mark = nssArena_Mark(arena);
    }
    for (i=0; i<atlen; i++) {
       for (j=0; j<cachedOA->numAttributes; j++) {
           if (atemplate[i].type == cachedOA->attributes[j].type) {
              CK_ATTRIBUTE_PTR attr = &cachedOA->attributes[j];
              if (cachedOA->attributes[j].ulValueLen == 0 ||
                  cachedOA->attributes[j].ulValueLen == (CK_ULONG)-1) 
              {
                  break; /* invalid attribute */
              }
              if (atemplate[i].ulValueLen > 0) {
                  if (atemplate[i].pValue == NULL ||
                      atemplate[i].ulValueLen < attr->ulValueLen) 
                  {
                     goto loser;
                  }
              } else {
                  atemplate[i].pValue = nss_ZAlloc(arena, attr->ulValueLen);
                  if (!atemplate[i].pValue) {
                     goto loser;
                  }
              }
              nsslibc_memcpy(atemplate[i].pValue,
                             attr->pValue, attr->ulValueLen);
              atemplate[i].ulValueLen = attr->ulValueLen;
              break;
           }
       }
       if (j == cachedOA->numAttributes) {
           atemplate[i].ulValueLen = (CK_ULONG)-1;
       }
    }
    PZ_Unlock(cache->lock);
    if (mark) {
       nssArena_Unmark(arena, mark);
    }
    return PR_SUCCESS;
loser:
    PZ_Unlock(cache->lock);
    if (mark) {
       nssArena_Release(arena, mark);
    }
    return PR_FAILURE;
}

Here is the caller graph for this function:

NSS_EXTERN PRBool nssTokenObjectCache_HaveObjectClass ( nssTokenObjectCache *  cache,
CK_OBJECT_CLASS  objclass 
)

Definition at line 320 of file devutil.c.

{
    PRBool haveIt;
    PZ_Lock(cache->lock);
    switch (objclass) {
    case CKO_CERTIFICATE:    haveIt = cache->doObjectType[cachedCerts]; break;
    case CKO_NETSCAPE_TRUST: haveIt = cache->doObjectType[cachedTrust]; break;
    case CKO_NETSCAPE_CRL:   haveIt = cache->doObjectType[cachedCRLs];  break;
    default:                 haveIt = PR_FALSE;
    }
    PZ_Unlock(cache->lock);
    return haveIt;
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssTokenObjectCache_ImportObject ( nssTokenObjectCache *  cache,
nssCryptokiObject *  object,
CK_OBJECT_CLASS  objclass,
CK_ATTRIBUTE_PTR  ot,
CK_ULONG  otlen 
)

Definition at line 997 of file devutil.c.

{
    PRStatus status = PR_SUCCESS;
    PRUint32 count;
    nssCryptokiObjectAndAttributes **oa, ***otype;
    PRUint32 objectType;
    PRBool haveIt = PR_FALSE;

    if (!token_is_present(cache)) {
       return PR_SUCCESS; /* cache not active, ignored */
    }
    PZ_Lock(cache->lock);
    switch (objclass) {
    case CKO_CERTIFICATE:    objectType = cachedCerts; break;
    case CKO_NETSCAPE_TRUST: objectType = cachedTrust; break;
    case CKO_NETSCAPE_CRL:   objectType = cachedCRLs;  break;
    default:
       PZ_Unlock(cache->lock);
       return PR_SUCCESS; /* don't need to import it here */
    }
    if (!cache_available_for_object_type(cache, objectType)) {
       PZ_Unlock(cache->lock);
       return PR_SUCCESS; /* cache not active, ignored */
    }
    count = 0;
    otype = &cache->objects[objectType]; /* index into array of types */
    oa = *otype; /* the array of objects for this type */
    while (oa && *oa) {
       if (nssCryptokiObject_Equal((*oa)->object, object)) {
           haveIt = PR_TRUE;
           break;
       }
       count++;
       oa++;
    }
    if (haveIt) {
       /* Destroy the old entry */
       (*oa)->object->token = NULL;
       nssCryptokiObject_Destroy((*oa)->object);
       nssArena_Destroy((*oa)->arena);
    } else {
       /* Create space for a new entry */
       if (count > 0) {
           *otype = nss_ZREALLOCARRAY(*otype,
                                      nssCryptokiObjectAndAttributes *, 
                                      count + 2);
       } else {
           *otype = nss_ZNEWARRAY(NULL, nssCryptokiObjectAndAttributes *, 2);
       }
    }
    if (*otype) {
       nssCryptokiObject *copyObject = nssCryptokiObject_Clone(object);
       if (objectType == cachedCerts) {
           (*otype)[count] = create_cert(copyObject, &status);
       } else if (objectType == cachedTrust) {
           (*otype)[count] = create_trust(copyObject, &status);
       } else if (objectType == cachedCRLs) {
           (*otype)[count] = create_crl(copyObject, &status);
       }
    } else {
       status = PR_FAILURE;
    }
    PZ_Unlock(cache->lock);
    return status;
}

Here is the caller graph for this function:

NSS_EXTERN void nssTokenObjectCache_RemoveObject ( nssTokenObjectCache *  cache,
nssCryptokiObject *  object 
)

Definition at line 1070 of file devutil.c.

{
    PRUint32 oType;
    nssCryptokiObjectAndAttributes **oa, **swp = NULL;
    if (!token_is_present(cache)) {
       return;
    }
    PZ_Lock(cache->lock);
    for (oType=0; oType<3; oType++) {
       if (!cache_available_for_object_type(cache, oType) ||
           !cache->objects[oType])
       {
           continue;
       }
       for (oa = cache->objects[oType]; *oa; oa++) {
           if (nssCryptokiObject_Equal((*oa)->object, object)) {
              swp = oa; /* the entry to remove */
              while (oa[1]) oa++; /* go to the tail */
              (*swp)->object->token = NULL;
              nssCryptokiObject_Destroy((*swp)->object);
              nssArena_Destroy((*swp)->arena); /* destroy it */
              *swp = *oa; /* swap the last with the removed */
              *oa = NULL; /* null-terminate the array */
              break;
           }
       }
       if (swp) {
           break;
       }
    }
    if ((oType <3) &&
              cache->objects[oType] && cache->objects[oType][0] == NULL) {
       nss_ZFreeIf(cache->objects[oType]); /* no entries remaining */
       cache->objects[oType] = NULL;
    }
    PZ_Unlock(cache->lock);
}

Here is the caller graph for this function: