Back to index

lightning-sunbird  0.9+nobinonly
Functions
dev3hack.c File Reference
#include "pkit.h"
#include "devm.h"
#include "pki3hack.h"
#include "dev3hack.h"
#include "pkim.h"
#include "base.h"
#include "pk11func.h"
#include "secmodti.h"

Go to the source code of this file.

Functions

NSS_IMPLEMENT nssSession * nssSession_ImportNSS3Session (NSSArena *arenaOpt, CK_SESSION_HANDLE session, PZLock *lock, PRBool rw)
NSS_IMPLEMENT nssSession * nssSlot_CreateSession (NSSSlot *slot, NSSArena *arenaOpt, PRBool readWrite)
NSS_IMPLEMENT PRStatus nssSession_Destroy (nssSession *s)
static NSSSlot * nssSlot_CreateFromPK11SlotInfo (NSSTrustDomain *td, PK11SlotInfo *nss3slot)
NSS_IMPLEMENT NSSToken * nssToken_CreateFromPK11SlotInfo (NSSTrustDomain *td, PK11SlotInfo *nss3slot)
NSS_IMPLEMENT void nssToken_UpdateName (NSSToken *token)
NSS_IMPLEMENT PRBool nssSlot_IsPermanent (NSSSlot *slot)
NSS_IMPLEMENT PRBool nssSlot_IsFriendly (NSSSlot *slot)
NSS_IMPLEMENT PRStatus nssToken_Refresh (NSSToken *token)
NSS_IMPLEMENT PRStatus nssSlot_Refresh (NSSSlot *slot)
NSS_IMPLEMENT PRStatus nssToken_GetTrustOrder (NSSToken *tok)
NSS_IMPLEMENT PRBool nssSlot_IsLoggedIn (NSSSlot *slot)
NSSTrustDomain * nssToken_GetTrustDomain (NSSToken *token)
NSS_EXTERN PRStatus nssTrustDomain_RemoveTokenCertsFromCache (NSSTrustDomain *td, NSSToken *token)
NSS_IMPLEMENT PRStatus nssToken_NotifyCertsNotVisible (NSSToken *tok)

Function Documentation

Definition at line 120 of file dev3hack.c.

{
    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;
}
NSS_IMPLEMENT nssSession* nssSession_ImportNSS3Session ( NSSArena *  arenaOpt,
CK_SESSION_HANDLE  session,
PZLock lock,
PRBool  rw 
)

Definition at line 61 of file dev3hack.c.

{
    nssSession *rvSession;
    rvSession = nss_ZNEW(arenaOpt, nssSession);
    rvSession->handle = session;
    rvSession->lock = lock;
    rvSession->ownLock = PR_FALSE;
    rvSession->isRW = rw;
    return rvSession;
}

Here is the caller graph for this function:

static NSSSlot* nssSlot_CreateFromPK11SlotInfo ( NSSTrustDomain *  td,
PK11SlotInfo *  nss3slot 
) [static]

Definition at line 135 of file dev3hack.c.

{
    NSSSlot *rvSlot;
    NSSArena *arena;
    arena = nssArena_Create();
    if (!arena) {
       return NULL;
    }
    rvSlot = nss_ZNEW(arena, NSSSlot);
    if (!rvSlot) {
       nssArena_Destroy(arena);
       return NULL;
    }
    rvSlot->base.refCount = 1;
    rvSlot->base.lock = PZ_NewLock(nssILockOther);
    rvSlot->base.arena = arena;
    rvSlot->pk11slot = nss3slot;
    rvSlot->epv = nss3slot->functionList;
    rvSlot->slotID = nss3slot->slotID;
    /* Grab the slot name from the PKCS#11 fixed-length buffer */
    rvSlot->base.name = nssUTF8_Duplicate(nss3slot->slot_name,td->arena);
    rvSlot->lock = (nss3slot->isThreadSafe) ? NULL : nss3slot->sessionLock;
    return rvSlot;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT nssSession* nssSlot_CreateSession ( NSSSlot *  slot,
NSSArena *  arenaOpt,
PRBool  readWrite 
)

Definition at line 76 of file dev3hack.c.

{
    nssSession *rvSession;
    rvSession = nss_ZNEW(arenaOpt, nssSession);
    if (!rvSession) {
       return (nssSession *)NULL;
    }
    if (readWrite) {
       rvSession->handle = PK11_GetRWSession(slot->pk11slot);
       if (rvSession->handle == CK_INVALID_HANDLE) {
           nss_ZFreeIf(rvSession);
           return NULL;
       }
       rvSession->isRW = PR_TRUE;
       rvSession->slot = slot;
        /*
         * The session doesn't need its own lock.  Here's why.
         * 1. If we are reusing the default RW session of the slot,
         *    the slot lock is already locked to protect the session.
         * 2. If the module is not thread safe, the slot (or rather
         *    module) lock is already locked.
         * 3. If the module is thread safe and we are using a new
         *    session, no higher-level lock has been locked and we
         *    would need a lock for the new session.  However, the
         *    current usage of the session is that it is always
         *    used and destroyed within the same function and never
         *    shared with another thread.
         * So the session is either already protected by another
         * lock or only used by one thread.
         */
        rvSession->lock = NULL;
        rvSession->ownLock = PR_FALSE;
       return rvSession;
    } else {
       return NULL;
    }
}

Definition at line 221 of file dev3hack.c.

{
    return PK11_IsFriendly(slot->pk11slot);
}

Definition at line 280 of file dev3hack.c.

{
    if (!slot->pk11slot->needLogin) {
       return PR_TRUE;
    }
    return PK11_IsLoggedIn(slot->pk11slot, NULL);
}

Definition at line 212 of file dev3hack.c.

{
    return slot->pk11slot->isPerm;
}
NSS_IMPLEMENT PRStatus nssSlot_Refresh ( NSSSlot *  slot)

Definition at line 246 of file dev3hack.c.

{
    PK11SlotInfo *nss3slot = slot->pk11slot;
    PRBool doit = PR_FALSE;
    if (slot->token->base.name[0] == 0) {
       doit = PR_TRUE;
    }
    if (PK11_InitToken(nss3slot, PR_FALSE) != SECSuccess) {
       return PR_FAILURE;
    }
    if (doit) {
       nssTrustDomain_UpdateCachedTokenCerts(slot->token->trustDomain, 
                                             slot->token);
    }
    return nssToken_Refresh(slot->token);
}
NSS_IMPLEMENT NSSToken* nssToken_CreateFromPK11SlotInfo ( NSSTrustDomain *  td,
PK11SlotInfo *  nss3slot 
)

Definition at line 161 of file dev3hack.c.

{
    NSSToken *rvToken;
    NSSArena *arena;
    arena = nssArena_Create();
    if (!arena) {
       return NULL;
    }
    rvToken = nss_ZNEW(arena, NSSToken);
    if (!rvToken) {
       nssArena_Destroy(arena);
       return NULL;
    }
    rvToken->base.refCount = 1;
    rvToken->base.lock = PZ_NewLock(nssILockOther);
    rvToken->base.arena = arena;
    rvToken->pk11slot = nss3slot;
    rvToken->epv = nss3slot->functionList;
    rvToken->defaultSession = nssSession_ImportNSS3Session(td->arena,
                                                       nss3slot->session,
                                                       nss3slot->sessionLock,
                                                       nss3slot->defRWSession);
    /* The above test was used in 3.4, for this cache have it always on */
    if (!PK11_IsInternal(nss3slot) && PK11_IsHW(nss3slot)) {
       rvToken->cache = nssTokenObjectCache_Create(rvToken, 
                                                   PR_TRUE, PR_TRUE, PR_TRUE);
       if (!rvToken->cache) {
           nssArena_Destroy(arena);
           return (NSSToken *)NULL;
       }
    }
    rvToken->trustDomain = td;
    /* Grab the token name from the PKCS#11 fixed-length buffer */
    rvToken->base.name = nssUTF8_Duplicate(nss3slot->token_name,td->arena);
    rvToken->slot = nssSlot_CreateFromPK11SlotInfo(td, nss3slot);
    rvToken->slot->token = rvToken;
    rvToken->defaultSession->slot = rvToken->slot;
    return rvToken;
}

Here is the caller graph for this function:

NSSTrustDomain* nssToken_GetTrustDomain ( NSSToken *  token)

Definition at line 292 of file dev3hack.c.

{
    return token->trustDomain;
}

Definition at line 267 of file dev3hack.c.

{
    PK11SlotInfo *slot;
    SECMODModule *module;
    slot = tok->pk11slot;
    module = PK11_GetModule(slot);
    return module->trustOrder;
}

Here is the call graph for this function:

Definition at line 306 of file dev3hack.c.

{
    return nssTrustDomain_RemoveTokenCertsFromCache(tok->trustDomain, tok);
}

Here is the call graph for this function:

NSS_IMPLEMENT PRStatus nssToken_Refresh ( NSSToken *  token)

Definition at line 229 of file dev3hack.c.

{
    PK11SlotInfo *nss3slot;

    if (!token) {
       return PR_SUCCESS;
    }
    nss3slot = token->pk11slot;
    token->defaultSession = nssSession_ImportNSS3Session(token->slot->base.arena,
                                                       nss3slot->session,
                                                       nss3slot->sessionLock,
                                                       nss3slot->defRWSession);
    return PR_SUCCESS;
}

Here is the caller graph for this function:

NSS_IMPLEMENT void nssToken_UpdateName ( NSSToken *  token)

Definition at line 202 of file dev3hack.c.

{
    if (!token) {
       return;
    }
    token->base.name = nssUTF8_Duplicate(token->pk11slot->token_name,token->base.arena);
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssTrustDomain_RemoveTokenCertsFromCache ( NSSTrustDomain *  td,
NSSToken *  token 
)

Definition at line 456 of file tdcache.c.

{
    NSSCertificate **certs;
    PRUint32 i, arrSize = 10;
    struct token_cert_dtor dtor;
    certs = nss_ZNEWARRAY(NULL, NSSCertificate *, arrSize);
    if (!certs) {
       return PR_FAILURE;
    }
    dtor.cache = td->cache;
    dtor.token = token;
    dtor.certs = certs;
    dtor.numCerts = 0;
    dtor.arrSize = arrSize;
    PZ_Lock(td->cache->lock);
    nssHash_Iterate(td->cache->issuerAndSN, remove_token_certs, (void *)&dtor);
    for (i=0; i<dtor.numCerts; i++) {
       if (dtor.certs[i]->object.numInstances == 0) {
           nssTrustDomain_RemoveCertFromCacheLOCKED(td, dtor.certs[i]);
           dtor.certs[i] = NULL;  /* skip this cert in the second for loop */
       }
    }
    PZ_Unlock(td->cache->lock);
    for (i=0; i<dtor.numCerts; i++) {
       if (dtor.certs[i]) {
           STAN_ForceCERTCertificateUpdate(dtor.certs[i]);
       }
    }
    nss_ZFreeIf(dtor.certs);
    return PR_SUCCESS;
}

Here is the caller graph for this function: