Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions
pkistore.h File Reference
#include "nsspkit.h"
#include "base.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nssCertificateStoreTraceStr

Typedefs

typedef struct nssCertificateStoreTraceStr

Functions

PR_BEGIN_EXTERN_C NSS_EXTERN
nssCertificateStore * 
nssCertificateStore_Create (NSSArena *arenaOpt)
NSS_EXTERN PRStatus nssCertificateStore_Destroy (nssCertificateStore *store)
NSS_EXTERN NSSCertificate * nssCertificateStore_FindOrAdd (nssCertificateStore *store, NSSCertificate *c)
NSS_EXTERN void nssCertificateStore_RemoveCertLOCKED (nssCertificateStore *store, NSSCertificate *cert)
static void nssCertificateStore_Check (nssCertificateStoreTrace *a, nssCertificateStoreTrace *b)
NSS_EXTERN void nssCertificateStore_Lock (nssCertificateStore *store, nssCertificateStoreTrace *out)
NSS_EXTERN void nssCertificateStore_Unlock (nssCertificateStore *store, nssCertificateStoreTrace *in, nssCertificateStoreTrace *out)
NSS_EXTERN NSSCertificate ** nssCertificateStore_FindCertificatesBySubject (nssCertificateStore *store, NSSDER *subject, NSSCertificate *rvOpt[], PRUint32 maximumOpt, NSSArena *arenaOpt)
NSS_EXTERN NSSCertificate ** nssCertificateStore_FindCertificatesByNickname (nssCertificateStore *store, NSSUTF8 *nickname, NSSCertificate *rvOpt[], PRUint32 maximumOpt, NSSArena *arenaOpt)
NSS_EXTERN NSSCertificate ** nssCertificateStore_FindCertificatesByEmail (nssCertificateStore *store, NSSASCII7 *email, NSSCertificate *rvOpt[], PRUint32 maximumOpt, NSSArena *arenaOpt)
NSS_EXTERN NSSCertificate * nssCertificateStore_FindCertificateByIssuerAndSerialNumber (nssCertificateStore *store, NSSDER *issuer, NSSDER *serial)
NSS_EXTERN NSSCertificate * nssCertificateStore_FindCertificateByEncodedCertificate (nssCertificateStore *store, NSSDER *encoding)
NSS_EXTERN PRStatus nssCertificateStore_AddTrust (nssCertificateStore *store, NSSTrust *trust)
NSS_EXTERN NSSTrust * nssCertificateStore_FindTrustForCertificate (nssCertificateStore *store, NSSCertificate *cert)
NSS_EXTERN PRStatus nssCertificateStore_AddSMIMEProfile (nssCertificateStore *store, nssSMIMEProfile *profile)
NSS_EXTERN nssSMIMEProfile * nssCertificateStore_FindSMIMEProfileForCertificate (nssCertificateStore *store, NSSCertificate *cert)
NSS_EXTERN void nssCertificateStore_DumpStoreInfo (nssCertificateStore *store, void(*cert_dump_iter)(const void *, void *, void *), void *arg)

Class Documentation

struct nssCertificateStoreTraceStr

Definition at line 101 of file pkistore.h.

Class Members
PZLock * lock
PRBool locked
nssCertificateStore * store
PRBool unlocked

Typedef Documentation

Definition at line 108 of file pkistore.h.


Function Documentation

NSS_EXTERN PRStatus nssCertificateStore_AddSMIMEProfile ( nssCertificateStore *  store,
nssSMIMEProfile *  profile 
)

Definition at line 674 of file pkistore.c.

{
    NSSCertificate *cert;
    certificate_hash_entry *entry;
    cert = profile->certificate;
    PZ_Lock(store->lock);
    entry = (certificate_hash_entry *)
                              nssHash_Lookup(store->issuer_and_serial, cert);
    if (entry) {
       entry->profile = nssSMIMEProfile_AddRef(profile);
    }
    PZ_Unlock(store->lock);
    return (entry) ? PR_SUCCESS : PR_FAILURE;
}
NSS_EXTERN PRStatus nssCertificateStore_AddTrust ( nssCertificateStore *  store,
NSSTrust *  trust 
)

Definition at line 637 of file pkistore.c.

{
    NSSCertificate *cert;
    certificate_hash_entry *entry;
    cert = trust->certificate;
    PZ_Lock(store->lock);
    entry = (certificate_hash_entry *)
                              nssHash_Lookup(store->issuer_and_serial, cert);
    if (entry) {
       entry->trust = nssTrust_AddRef(trust);
    }
    PZ_Unlock(store->lock);
    return (entry) ? PR_SUCCESS : PR_FAILURE;
}
static void nssCertificateStore_Check ( nssCertificateStoreTrace *  a,
nssCertificateStoreTrace *  b 
) [static]

Definition at line 110 of file pkistore.h.

                                                               {
    PORT_Assert(a->locked);
    PORT_Assert(b->unlocked);

    PORT_Assert(!a->unlocked);
    PORT_Assert(!b->locked);

    PORT_Assert(a->lock == b->lock);
    PORT_Assert(a->store == b->store);
};

Here is the caller graph for this function:

PR_BEGIN_EXTERN_C NSS_EXTERN nssCertificateStore* nssCertificateStore_Create ( NSSArena *  arenaOpt)

Definition at line 99 of file pkistore.c.

{
    NSSArena *arena;
    nssCertificateStore *store;
    PRBool i_alloced_arena;
    if (arenaOpt) {
       arena = arenaOpt;
       i_alloced_arena = PR_FALSE;
    } else {
       arena = nssArena_Create();
       if (!arena) {
           return NULL;
       }
       i_alloced_arena = PR_TRUE;
    }
    store = nss_ZNEW(arena, nssCertificateStore);
    if (!store) {
       goto loser;
    }
    store->lock = PZ_NewLock(nssILockOther);
    if (!store->lock) {
       goto loser;
    }
    /* Create the issuer/serial --> {cert, trust, S/MIME profile } hash */
    store->issuer_and_serial = nssHash_CreateCertificate(arena, 0);
    if (!store->issuer_and_serial) {
       goto loser;
    }
    /* Create the subject DER --> subject list hash */
    store->subject = nssHash_CreateItem(arena, 0);
    if (!store->subject) {
       goto loser;
    }
    store->arena = arena;
    store->i_alloced_arena = i_alloced_arena;
    return store;
loser:
    if (store) {
       if (store->lock) {
           PZ_DestroyLock(store->lock);
       }
       if (store->issuer_and_serial) {
           nssHash_Destroy(store->issuer_and_serial);
       }
       if (store->subject) {
           nssHash_Destroy(store->subject);
       }
    }
    if (i_alloced_arena) {
       nssArena_Destroy(arena);
    }
    return NULL;
}
NSS_EXTERN PRStatus nssCertificateStore_Destroy ( nssCertificateStore *  store)

Definition at line 158 of file pkistore.c.

{
    if (nssHash_Count(store->issuer_and_serial) > 0) {
       nss_SetError(NSS_ERROR_BUSY);
       return PR_FAILURE;
    }
    PZ_DestroyLock(store->lock);
    nssHash_Destroy(store->issuer_and_serial);
    nssHash_Destroy(store->subject);
    if (store->i_alloced_arena) {
       nssArena_Destroy(store->arena);
    } else {
       nss_ZFreeIf(store);
    }
    return PR_SUCCESS;
}
NSS_EXTERN void nssCertificateStore_DumpStoreInfo ( nssCertificateStore *  store,
void(*)(const void *, void *, void *)  cert_dump_iter,
void arg 
)

Definition at line 752 of file pkistore.c.

{
    PZ_Lock(store->lock);
    nssHash_Iterate(store->issuer_and_serial, cert_dump_iter, arg);
    PZ_Unlock(store->lock);
}
NSS_EXTERN NSSCertificate* nssCertificateStore_FindCertificateByEncodedCertificate ( nssCertificateStore *  store,
NSSDER encoding 
)

Definition at line 616 of file pkistore.c.

{
    PRStatus nssrv = PR_FAILURE;
    NSSDER issuer, serial;
    NSSCertificate *rvCert = NULL;
    nssrv = issuer_and_serial_from_encoding(encoding, &issuer, &serial);
    if (nssrv != PR_SUCCESS) {
       return NULL;
    }
    rvCert = nssCertificateStore_FindCertificateByIssuerAndSerialNumber(store, 
                                                                     &issuer, 
                                                                     &serial);
    PORT_Free(issuer.data);
    PORT_Free(serial.data);
    return rvCert;
}
NSS_EXTERN NSSCertificate* nssCertificateStore_FindCertificateByIssuerAndSerialNumber ( nssCertificateStore *  store,
NSSDER issuer,
NSSDER serial 
)

Definition at line 573 of file pkistore.c.

{
    NSSCertificate *rvCert = NULL;

    PZ_Lock(store->lock);
    rvCert = nssCertStore_FindCertByIssuerAndSerialNumberLocked (
                           store, issuer, serial);
    PZ_Unlock(store->lock);
    return rvCert;
}
NSS_EXTERN NSSCertificate** nssCertificateStore_FindCertificatesByEmail ( nssCertificateStore *  store,
NSSASCII7 email,
NSSCertificate *  rvOpt[],
PRUint32  maximumOpt,
NSSArena *  arenaOpt 
)

Definition at line 520 of file pkistore.c.

{
    NSSCertificate **rvArray = NULL;
    struct email_template_str et;
    et.email = email;
    et.emailList = nssList_Create(NULL, PR_FALSE);
    if (!et.emailList) {
       return NULL;
    }
    PZ_Lock(store->lock);
    nssHash_Iterate(store->subject, match_email, &et);
    if (et.emailList) {
       /* get references before leaving the store's lock protection */
       nssCertificateList_AddReferences(et.emailList);
    }
    PZ_Unlock(store->lock);
    if (et.emailList) {
       rvArray = get_array_from_list(et.emailList, 
                                     rvOpt, maximumOpt, arenaOpt);
       nssList_Destroy(et.emailList);
    }
    return rvArray;
}
NSS_EXTERN NSSCertificate** nssCertificateStore_FindCertificatesByNickname ( nssCertificateStore *  store,
NSSUTF8 nickname,
NSSCertificate *  rvOpt[],
PRUint32  maximumOpt,
NSSArena *  arenaOpt 
)

Definition at line 463 of file pkistore.c.

{
    NSSCertificate **rvArray = NULL;
    struct nickname_template_str nt;
    nt.nickname = nickname;
    nt.subjectList = NULL;
    PZ_Lock(store->lock);
    nssHash_Iterate(store->subject, match_nickname, &nt);
    if (nt.subjectList) {
       nssCertificateList_AddReferences(nt.subjectList);
       rvArray = get_array_from_list(nt.subjectList, 
                                     rvOpt, maximumOpt, arenaOpt);
    }
    PZ_Unlock(store->lock);
    return rvArray;
}
NSS_EXTERN NSSCertificate** nssCertificateStore_FindCertificatesBySubject ( nssCertificateStore *  store,
NSSDER subject,
NSSCertificate *  rvOpt[],
PRUint32  maximumOpt,
NSSArena *  arenaOpt 
)

Definition at line 405 of file pkistore.c.

{
    NSSCertificate **rvArray = NULL;
    nssList *subjectList;
    PZ_Lock(store->lock);
    subjectList = (nssList *)nssHash_Lookup(store->subject, subject);
    if (subjectList) {
       nssCertificateList_AddReferences(subjectList);
       rvArray = get_array_from_list(subjectList, 
                                     rvOpt, maximumOpt, arenaOpt);
    }
    PZ_Unlock(store->lock);
    return rvArray;
}
NSS_EXTERN NSSCertificate* nssCertificateStore_FindOrAdd ( nssCertificateStore *  store,
NSSCertificate *  c 
)

Definition at line 253 of file pkistore.c.

{
    PRStatus nssrv;
    NSSCertificate *rvCert = NULL;

    PZ_Lock(store->lock);
    rvCert = nssCertStore_FindCertByIssuerAndSerialNumberLocked(
                                      store, &c->issuer, &c->serial);
    if (!rvCert) {
       nssrv = nssCertificateStore_AddLocked(store, c);
       if (PR_SUCCESS == nssrv) {
           rvCert = nssCertificate_AddRef(c);
       }
    }
    PZ_Unlock(store->lock);
    return rvCert;
}
NSS_EXTERN nssSMIMEProfile* nssCertificateStore_FindSMIMEProfileForCertificate ( nssCertificateStore *  store,
NSSCertificate *  cert 
)

Definition at line 693 of file pkistore.c.

{
    certificate_hash_entry *entry;
    nssSMIMEProfile *rvProfile = NULL;
    PZ_Lock(store->lock);
    entry = (certificate_hash_entry *)
                              nssHash_Lookup(store->issuer_and_serial, cert);
    if (entry && entry->profile) {
       rvProfile = nssSMIMEProfile_AddRef(entry->profile);
    }
    PZ_Unlock(store->lock);
    return rvProfile;
}
NSS_EXTERN NSSTrust* nssCertificateStore_FindTrustForCertificate ( nssCertificateStore *  store,
NSSCertificate *  cert 
)

Definition at line 656 of file pkistore.c.

{
    certificate_hash_entry *entry;
    NSSTrust *rvTrust = NULL;
    PZ_Lock(store->lock);
    entry = (certificate_hash_entry *)
                              nssHash_Lookup(store->issuer_and_serial, cert);
    if (entry && entry->trust) {
       rvTrust = nssTrust_AddRef(entry->trust);
    }
    PZ_Unlock(store->lock);
    return rvTrust;
}
NSS_EXTERN void nssCertificateStore_Lock ( nssCertificateStore *  store,
nssCertificateStoreTrace *  out 
)

Definition at line 338 of file pkistore.c.

{
#ifdef DEBUG
    PORT_Assert(out);
    out->store = store;
    out->lock = store->lock;
    out->locked = PR_TRUE;
    PZ_Lock(out->lock);
#else
    PZ_Lock(store->lock);
#endif
}
NSS_EXTERN void nssCertificateStore_RemoveCertLOCKED ( nssCertificateStore *  store,
NSSCertificate *  cert 
)

Definition at line 323 of file pkistore.c.

{
    certificate_hash_entry *entry;
    entry = (certificate_hash_entry *)
                              nssHash_Lookup(store->issuer_and_serial, cert);
    if (entry && entry->cert == cert) {
       remove_certificate_entry(store, cert);
       remove_subject_entry(store, cert);
    }
}
NSS_EXTERN void nssCertificateStore_Unlock ( nssCertificateStore *  store,
nssCertificateStoreTrace *  in,
nssCertificateStoreTrace *  out 
)

Definition at line 354 of file pkistore.c.

{
#ifdef DEBUG
    PORT_Assert(in);
    PORT_Assert(out);
    out->store = store;
    out->lock = store->lock;
    out->unlocked = PR_TRUE;

    PORT_Assert(in->store == out->store);
    PORT_Assert(in->lock == out->lock);
    PORT_Assert(in->locked);

    PZ_Unlock(out->lock);
#else
    PZ_Unlock(store->lock);
#endif
}