Back to index

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

Go to the source code of this file.

Defines

#define NSS_CK_TEMPLATE_START(_template, attr, size)
#define NSS_CK_SET_ATTRIBUTE_ITEM(pattr, kind, item)
#define NSS_CK_SET_ATTRIBUTE_UTF8(pattr, kind, utf8)
#define NSS_CK_SET_ATTRIBUTE_VAR(pattr, kind, var)
#define NSS_CK_SET_ATTRIBUTE_NULL(pattr, kind)
#define NSS_CK_TEMPLATE_FINISH(_template, attr, size)
#define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item)
#define NSS_CK_ATTRIBUTE_TO_BOOL(attrib, boolvar)
#define NSS_CK_ATTRIBUTE_TO_ULONG(attrib, ulongvar)
#define NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str)   str = (NSSUTF8 *)((attrib)->pValue);
#define NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib)

Functions

NSS_EXTERN PRStatus nssCKObject_GetAttributes (CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR obj_template, CK_ULONG count, NSSArena *arenaOpt, nssSession *session, NSSSlot *slot)
NSS_EXTERN PRStatus nssCKObject_GetAttributeItem (CK_OBJECT_HANDLE object, CK_ATTRIBUTE_TYPE attribute, NSSArena *arenaOpt, nssSession *session, NSSSlot *slot, NSSItem *rvItem)
NSS_EXTERN PRBool nssCKObject_IsAttributeTrue (CK_OBJECT_HANDLE object, CK_ATTRIBUTE_TYPE attribute, nssSession *session, NSSSlot *slot, PRStatus *rvStatus)
NSS_EXTERN PRStatus nssCKObject_SetAttributes (CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR obj_template, CK_ULONG count, nssSession *session, NSSSlot *slot)
NSS_EXTERN PRBool nssCKObject_IsTokenObjectTemplate (CK_ATTRIBUTE_PTR objectTemplate, CK_ULONG otsize)

Variables

PR_BEGIN_EXTERN_C
NSS_EXTERN_DATA const NSSItem 
g_ck_true
NSS_EXTERN_DATA const NSSItem g_ck_false
NSS_EXTERN_DATA const NSSItem g_ck_class_cert
NSS_EXTERN_DATA const NSSItem g_ck_class_pubkey
NSS_EXTERN_DATA const NSSItem g_ck_class_privkey

Define Documentation

#define NSS_CK_ATTRIBUTE_TO_BOOL (   attrib,
  boolvar 
)
Value:
if ((attrib)->ulValueLen > 0) {                      \
       if (*((CK_BBOOL*)(attrib)->pValue) == CK_TRUE) { \
           boolvar = PR_TRUE;                           \
       } else {                                         \
           boolvar = PR_FALSE;                          \
       }                                                \
    }

Definition at line 115 of file ckhelper.h.

#define NSS_CK_ATTRIBUTE_TO_ITEM (   attrib,
  item 
)
Value:
if ((CK_LONG)(attrib)->ulValueLen > 0) {           \
       (item)->data = (void *)(attrib)->pValue;       \
       (item)->size = (PRUint32)(attrib)->ulValueLen; \
    } else {                                           \
       (item)->data = 0;                              \
       (item)->size = 0;                              \
    }

Definition at line 106 of file ckhelper.h.

#define NSS_CK_ATTRIBUTE_TO_ULONG (   attrib,
  ulongvar 
)
Value:
if ((attrib)->ulValueLen > 0) {                      \
       ulongvar = *((CK_ULONG*)(attrib)->pValue);       \
    }

Definition at line 124 of file ckhelper.h.

#define NSS_CK_ATTRIBUTE_TO_UTF8 (   attrib,
  str 
)    str = (NSSUTF8 *)((attrib)->pValue);

Definition at line 133 of file ckhelper.h.

#define NSS_CK_ITEM_TO_ATTRIBUTE (   item,
  attrib 
)
Value:
(attrib)->pValue = (CK_VOID_PTR)(item)->data;  \
    (attrib)->ulValueLen = (CK_ULONG)(item)->size; \

Definition at line 140 of file ckhelper.h.

#define NSS_CK_SET_ATTRIBUTE_ITEM (   pattr,
  kind,
  item 
)
Value:
(pattr)->type = kind;                             \
    (pattr)->pValue = (CK_VOID_PTR)(item)->data;      \
    (pattr)->ulValueLen = (CK_ULONG)(item)->size;     \
    (pattr)++;

Definition at line 73 of file ckhelper.h.

#define NSS_CK_SET_ATTRIBUTE_NULL (   pattr,
  kind 
)
Value:
(pattr)->type = kind;                             \
    (pattr)->pValue = (CK_VOID_PTR)NULL;              \
    (pattr)->ulValueLen = 0;                          \
    (pattr)++;

Definition at line 92 of file ckhelper.h.

#define NSS_CK_SET_ATTRIBUTE_UTF8 (   pattr,
  kind,
  utf8 
)
Value:
(pattr)->type = kind;                             \
    (pattr)->pValue = (CK_VOID_PTR)utf8;              \
    (pattr)->ulValueLen = (CK_ULONG)nssUTF8_Size(utf8, NULL); \
    if ((pattr)->ulValueLen) ((pattr)->ulValueLen)--; \
    (pattr)++;

Definition at line 79 of file ckhelper.h.

#define NSS_CK_SET_ATTRIBUTE_VAR (   pattr,
  kind,
  var 
)
Value:
(pattr)->type = kind;                             \
    (pattr)->pValue = (CK_VOID_PTR)&var;              \
    (pattr)->ulValueLen = (CK_ULONG)sizeof(var);      \
    (pattr)++;

Definition at line 86 of file ckhelper.h.

#define NSS_CK_TEMPLATE_FINISH (   _template,
  attr,
  size 
)
Value:
size = (attr) - (_template);                      \
    PR_ASSERT(size <= sizeof(_template)/sizeof(_template[0]));

Definition at line 98 of file ckhelper.h.

#define NSS_CK_TEMPLATE_START (   _template,
  attr,
  size 
)
Value:
attr = _template;                                  \
    size = 0;

Definition at line 69 of file ckhelper.h.


Function Documentation

NSS_EXTERN PRStatus nssCKObject_GetAttributeItem ( CK_OBJECT_HANDLE  object,
CK_ATTRIBUTE_TYPE  attribute,
NSSArena *  arenaOpt,
nssSession *  session,
NSSSlot *  slot,
NSSItem *  rvItem 
)

Definition at line 202 of file ckhelper.c.

{
    CK_ATTRIBUTE attr = { 0, NULL, 0 };
    PRStatus nssrv;
    attr.type = attribute;
    nssrv = nssCKObject_GetAttributes(object, &attr, 1, 
                                      arenaOpt, session, slot);
    if (nssrv != PR_SUCCESS) {
       return nssrv;
    }
    rvItem->data = (void *)attr.pValue;
    rvItem->size = (PRUint32)attr.ulValueLen;
    return PR_SUCCESS;
}

Here is the call graph for this function:

NSS_EXTERN PRStatus nssCKObject_GetAttributes ( CK_OBJECT_HANDLE  object,
CK_ATTRIBUTE_PTR  obj_template,
CK_ULONG  count,
NSSArena *  arenaOpt,
nssSession *  session,
NSSSlot *  slot 
)

Definition at line 94 of file ckhelper.c.

{
    nssArenaMark *mark = NULL;
    CK_SESSION_HANDLE hSession;
    CK_ULONG i = 0;
    CK_RV ckrv;
    PRStatus nssrv;
    PRBool alloced = PR_FALSE;
    void *epv = nssSlot_GetCryptokiEPV(slot);
    hSession = session->handle; 
    if (arenaOpt) {
       mark = nssArena_Mark(arenaOpt);
       if (!mark) {
           goto loser;
       }
    }
    nssSession_EnterMonitor(session);
    /* XXX kinda hacky, if the storage size is already in the first template
     * item, then skip the alloc portion
     */
    if (obj_template[0].ulValueLen == 0) {
       /* Get the storage size needed for each attribute */
       ckrv = CKAPI(epv)->C_GetAttributeValue(hSession,
                                              object, obj_template, count);
       if (ckrv != CKR_OK && 
           ckrv != CKR_ATTRIBUTE_TYPE_INVALID &&
           ckrv != CKR_ATTRIBUTE_SENSITIVE) 
       {
           nssSession_ExitMonitor(session);
           nss_SetError(NSS_ERROR_DEVICE_ERROR);
           goto loser;
       }
       /* Allocate memory for each attribute. */
       for (i=0; i<count; i++) {
           CK_ULONG ulValueLen = obj_template[i].ulValueLen;
           if (ulValueLen == 0) continue;
           if (ulValueLen == (CK_ULONG) -1) {
              obj_template[i].ulValueLen = 0;
              continue;
           }
           if (is_string_attribute(obj_template[i].type)) {
              ulValueLen++;
           }
           obj_template[i].pValue = nss_ZAlloc(arenaOpt, ulValueLen);
           if (!obj_template[i].pValue) {
              nssSession_ExitMonitor(session);
              goto loser;
           }
       }
       alloced = PR_TRUE;
    }
    /* Obtain the actual attribute values. */
    ckrv = CKAPI(epv)->C_GetAttributeValue(hSession,
                                           object, obj_template, count);
    nssSession_ExitMonitor(session);
    if (ckrv != CKR_OK && 
        ckrv != CKR_ATTRIBUTE_TYPE_INVALID &&
        ckrv != CKR_ATTRIBUTE_SENSITIVE) 
    {
       nss_SetError(NSS_ERROR_DEVICE_ERROR);
       goto loser;
    }
    if (alloced && arenaOpt) {
       nssrv = nssArena_Unmark(arenaOpt, mark);
       if (nssrv != PR_SUCCESS) {
           goto loser;
       }
    }

    if (count > 1 && ((ckrv == CKR_ATTRIBUTE_TYPE_INVALID) || 
                                   (ckrv == CKR_ATTRIBUTE_SENSITIVE))) {
       /* old tokens would keep the length of '0' and not deal with any
        * of the attributes we passed. For those tokens read them one at
        * a time */
       for (i=0; i < count; i++) {
           if ((obj_template[i].ulValueLen == 0) 
                            || (obj_template[i].ulValueLen == -1)) {
              obj_template[i].ulValueLen=0;
              (void) nssCKObject_GetAttributes(object,&obj_template[i], 1,
                     arenaOpt, session, slot);
           }
       }
    }
    return PR_SUCCESS;
loser:
    if (alloced) {
       if (arenaOpt) {
           /* release all arena memory allocated before the failure. */
           (void)nssArena_Release(arenaOpt, mark);
       } else {
           CK_ULONG j;
           /* free each heap object that was allocated before the failure. */
           for (j=0; j<i; j++) {
              nss_ZFreeIf(obj_template[j].pValue);
           }
       }
    }
    return PR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_EXTERN PRBool nssCKObject_IsAttributeTrue ( CK_OBJECT_HANDLE  object,
CK_ATTRIBUTE_TYPE  attribute,
nssSession *  session,
NSSSlot *  slot,
PRStatus rvStatus 
)

Definition at line 225 of file ckhelper.c.

{
    CK_BBOOL bool;
    CK_ATTRIBUTE_PTR attr;
    CK_ATTRIBUTE atemplate = { 0, NULL, 0 };
    CK_RV ckrv;
    void *epv = nssSlot_GetCryptokiEPV(slot);
    attr = &atemplate;
    NSS_CK_SET_ATTRIBUTE_VAR(attr, attribute, bool);
    nssSession_EnterMonitor(session);
    ckrv = CKAPI(epv)->C_GetAttributeValue(session->handle, object, 
                                           &atemplate, 1);
    nssSession_ExitMonitor(session);
    if (ckrv != CKR_OK) {
       *rvStatus = PR_FAILURE;
       return PR_FALSE;
    }
    *rvStatus = PR_SUCCESS;
    return (PRBool)(bool == CK_TRUE);
}

Here is the call graph for this function:

Definition at line 275 of file ckhelper.c.

{
    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;
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssCKObject_SetAttributes ( CK_OBJECT_HANDLE  object,
CK_ATTRIBUTE_PTR  obj_template,
CK_ULONG  count,
nssSession *  session,
NSSSlot *  slot 
)

Definition at line 253 of file ckhelper.c.

{
    CK_RV ckrv;
    void *epv = nssSlot_GetCryptokiEPV(slot);
    nssSession_EnterMonitor(session);
    ckrv = CKAPI(epv)->C_SetAttributeValue(session->handle, object, 
                                           obj_template, count);
    nssSession_ExitMonitor(session);
    if (ckrv == CKR_OK) {
       return PR_SUCCESS;
    } else {
       return PR_FAILURE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 65 of file ckhelper.h.

Definition at line 67 of file ckhelper.h.

Definition at line 66 of file ckhelper.h.

Definition at line 62 of file ckhelper.h.

Definition at line 61 of file ckhelper.h.