Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
genname.h File Reference
#include "plarena.h"
#include "seccomon.h"
#include "secoidt.h"
#include "secasn1.h"
#include "secder.h"
#include "certt.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SECItem ** cert_EncodeGeneralNames (PRArenaPool *arena, CERTGeneralName *names)
CERTGeneralName * cert_DecodeGeneralNames (PRArenaPool *arena, SECItem **encodedGenName)
SECStatus cert_DestroyGeneralNames (CERTGeneralName *name)
SECStatus cert_EncodeNameConstraints (CERTNameConstraints *constraints, PRArenaPool *arena, SECItem *dest)
CERTNameConstraints * cert_DecodeNameConstraints (PRArenaPool *arena, SECItem *encodedConstraints)
CERTGeneralName * cert_CombineNamesLists (CERTGeneralName *list1, CERTGeneralName *list2)
CERTNameConstraint * cert_CombineConstraintsLists (CERTNameConstraint *list1, CERTNameConstraint *list2)
void CERT_DestroyGeneralName (CERTGeneralName *name)
SECStatus CERT_CompareGeneralName (CERTGeneralName *a, CERTGeneralName *b)
SECStatus CERT_CopyGeneralName (PRArenaPool *arena, CERTGeneralName *dest, CERTGeneralName *src)
void CERT_DestroyGeneralNameList (CERTGeneralNameList *list)
CERTGeneralNameList * CERT_CreateGeneralNameList (CERTGeneralName *name)
SECStatus CERT_CompareGeneralNameLists (CERTGeneralNameList *a, CERTGeneralNameList *b)
voidCERT_GetGeneralNameFromListByType (CERTGeneralNameList *list, CERTGeneralNameType type, PRArenaPool *arena)
void CERT_AddGeneralNameToList (CERTGeneralNameList *list, CERTGeneralNameType type, void *data, SECItem *oid)
CERTGeneralNameList * CERT_DupGeneralNameList (CERTGeneralNameList *list)
int CERT_GetNamesLength (CERTGeneralName *names)
SECStatus CERT_CompareNameSpace (CERTCertificate *cert, CERTGeneralName *namesList, CERTCertificate **certsList, PRArenaPool *arena, CERTCertificate **pBadCert)

Variables

SEC_BEGIN_PROTOS const
SEC_ASN1Template 
CERT_GeneralNamesTemplate []

Function Documentation

void CERT_AddGeneralNameToList ( CERTGeneralNameList *  list,
CERTGeneralNameType  type,
void data,
SECItem *  oid 
)
CERTNameConstraint* cert_CombineConstraintsLists ( CERTNameConstraint *  list1,
CERTNameConstraint *  list2 
)

Definition at line 875 of file genname.c.

{
    PRCList *begin1;
    PRCList *begin2;
    PRCList *end1;
    PRCList *end2;

    if (list1 == NULL){
       return list2;
    } else if (list2 == NULL) {
       return list1;
    } else {
       begin1 = &list1->l;
       begin2 = &list2->l;
       end1 = list1->l.prev;
       end2 = list2->l.prev;
       end1->next = begin2;
       end2->next = begin1;
       begin1->prev = end2;
       begin2->prev = end1;
       return list1;
    }
}
CERTGeneralName* cert_CombineNamesLists ( CERTGeneralName *  list1,
CERTGeneralName *  list2 
)

Definition at line 849 of file genname.c.

{
    PRCList *begin1;
    PRCList *begin2;
    PRCList *end1;
    PRCList *end2;

    if (list1 == NULL){
       return list2;
    } else if (list2 == NULL) {
       return list1;
    } else {
       begin1 = &list1->l;
       begin2 = &list2->l;
       end1 = list1->l.prev;
       end2 = list2->l.prev;
       end1->next = begin2;
       end2->next = begin1;
       begin1->prev = end2;
       begin2->prev = end1;
       return list1;
    }
}
SECStatus CERT_CompareGeneralName ( CERTGeneralName *  a,
CERTGeneralName *  b 
)
SECStatus CERT_CompareGeneralNameLists ( CERTGeneralNameList *  a,
CERTGeneralNameList *  b 
)
SECStatus CERT_CompareNameSpace ( CERTCertificate *  cert,
CERTGeneralName *  namesList,
CERTCertificate **  certsList,
PRArenaPool arena,
CERTCertificate **  pBadCert 
)

Definition at line 1451 of file genname.c.

{
    SECStatus            rv = SECSuccess;
    SECItem              constraintsExtension;
    CERTNameConstraints  *constraints;
    CERTGeneralName      *currentName;
    int                  count = 0;
    CERTNameConstraint  *matchingConstraints;
    CERTCertificate      *badCert = NULL;
    
    /* If no names to check, then no names can be bad. */
    if (!namesList)
       goto done;
    constraintsExtension.data = NULL;
    rv = CERT_FindCertExtension(cert, SEC_OID_X509_NAME_CONSTRAINTS, 
                                &constraintsExtension);
    if (rv != SECSuccess) {
       if (PORT_GetError() == SEC_ERROR_EXTENSION_NOT_FOUND) {
           rv = SECSuccess;
       } else {
           count = -1;
       }
       goto done;
    }
    /* TODO: mark arena */
    constraints = cert_DecodeNameConstraints(arena, &constraintsExtension);
    PORT_Free(constraintsExtension.data);
    currentName = namesList;
    if (constraints == NULL) { /* decode failed */
       rv = SECFailure;
       count = -1;
       goto done;
    } 
    do {
       if (constraints->excluded != NULL) {
           rv = CERT_GetNameConstraintByType(constraints->excluded, 
                                             currentName->type, 
                                         &matchingConstraints, arena);
           if (rv == SECSuccess && matchingConstraints != NULL) {
              rv = cert_CompareNameWithConstraints(currentName, 
                                                   matchingConstraints,
                                               PR_TRUE);
           }
           if (rv != SECSuccess) 
              break;
       }
       if (constraints->permited != NULL) {
           rv = CERT_GetNameConstraintByType(constraints->permited, 
                                             currentName->type, 
                                         &matchingConstraints, arena);
            if (rv == SECSuccess && matchingConstraints != NULL) {
              rv = cert_CompareNameWithConstraints(currentName, 
                                                   matchingConstraints,
                                               PR_FALSE);
           }
           if (rv != SECSuccess) 
              break;
       }
       currentName = CERT_GetNextGeneralName(currentName);
       count ++;
    } while (currentName != namesList);
done:
    if (rv != SECSuccess) {
       badCert = (count >= 0) ? certsList[count] : cert;
    }
    if (pBadCert)
       *pBadCert = badCert;
    /* TODO: release back to mark */
    return rv;
}
SECStatus CERT_CopyGeneralName ( PRArenaPool arena,
CERTGeneralName *  dest,
CERTGeneralName *  src 
)

Definition at line 753 of file genname.c.

{
    SECStatus rv;
    CERTGeneralName *destHead = dest;
    CERTGeneralName *srcHead = src;

    PORT_Assert(dest != NULL);
    if (!dest) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
        return SECFailure;
    }
    /* TODO: mark arena */
    do {
       rv = cert_CopyOneGeneralName(arena, dest, src);
       if (rv != SECSuccess)
           goto loser;
       src = CERT_GetNextGeneralName(src);
       /* if there is only one general name, we shouldn't do this */
       if (src != srcHead) {
           if (dest->l.next == &destHead->l) {
              CERTGeneralName *temp;
              temp = cert_NewGeneralName(arena, (CERTGeneralNameType)0);
              if (!temp) 
                  goto loser;
              temp->l.next = &destHead->l;
              temp->l.prev = &dest->l;
              destHead->l.prev = &temp->l;
              dest->l.next = &temp->l;
              dest = temp;
           } else {
              dest = CERT_GetNextGeneralName(dest);
           }
       }
    } while (src != srcHead && rv == SECSuccess);
    /* TODO: unmark arena */
    return rv;
loser:
    /* TODO: release back to mark */
    return SECFailure;
}
CERTGeneralNameList* CERT_CreateGeneralNameList ( CERTGeneralName *  name)

Definition at line 251 of file genname.c.

                                                  {
    PRArenaPool *arena;
    CERTGeneralNameList *list = NULL;

    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
    if (arena == NULL) {
       goto done;
    }
    list = PORT_ArenaZNew(arena, CERTGeneralNameList);
    if (!list)
       goto loser;
    if (name != NULL) {
       SECStatus rv;
       list->name = cert_NewGeneralName(arena, (CERTGeneralNameType)0);
       if (!list->name)
           goto loser;
       rv = CERT_CopyGeneralName(arena, list->name, name);
       if (rv != SECSuccess)
           goto loser;
    }
    list->lock = PZ_NewLock(nssILockList);
    if (!list->lock)
       goto loser;
    list->arena = arena;
    list->refCount = 1;
done:
    return list;

loser:
    PORT_FreeArena(arena, PR_FALSE);
    return NULL;
}
CERTGeneralName* cert_DecodeGeneralNames ( PRArenaPool arena,
SECItem **  encodedGenName 
)

Definition at line 467 of file genname.c.

{
    PRCList                           *head = NULL;
    PRCList                           *tail = NULL;
    CERTGeneralName                   *currentName = NULL;

    PORT_Assert(arena);
    if (!encodedGenName || !arena) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       return NULL;
    }
    /* TODO: mark arena */
    while (*encodedGenName != NULL) {
       currentName = CERT_DecodeGeneralName(arena, *encodedGenName, NULL);
       if (currentName == NULL)
           break;
       if (head == NULL) {
           head = &(currentName->l);
           tail = head;
       }
       currentName->l.next = head;
       currentName->l.prev = tail;
       tail = head->prev = tail->next = &(currentName->l);
       encodedGenName++;
    }
    if (currentName) {
       /* TODO: unmark arena */
       return CERT_GetNextGeneralName(currentName);
    }
    /* TODO: release arena to mark */
    return NULL;
}
CERTNameConstraints* cert_DecodeNameConstraints ( PRArenaPool arena,
SECItem *  encodedConstraints 
)

Definition at line 696 of file genname.c.

{
    CERTNameConstraints   *constraints;
    SECStatus             rv;

    PORT_Assert(arena);
    PORT_Assert(encodedConstraints);
    /* TODO: mark arena */
    constraints = PORT_ArenaZNew(arena, CERTNameConstraints);
    if (constraints == NULL) {
       goto loser;
    }
    rv = SEC_ASN1DecodeItem(arena, constraints, CERTNameConstraintsTemplate, 
                         encodedConstraints);
    if (rv != SECSuccess) {
       goto loser;
    }
    if (constraints->DERPermited != NULL && 
        constraints->DERPermited[0] != NULL) {
       constraints->permited = 
           cert_DecodeNameConstraintSubTree(arena, constraints->DERPermited,
                                        PR_TRUE);
       if (constraints->permited == NULL) {
           goto loser;
       }
    }
    if (constraints->DERExcluded != NULL && 
        constraints->DERExcluded[0] != NULL) {
       constraints->excluded = 
           cert_DecodeNameConstraintSubTree(arena, constraints->DERExcluded,
                                        PR_FALSE);
       if (constraints->excluded == NULL) {
           goto loser;
       }
    }
    /* TODO: unmark arena */
    return constraints;
loser:
    /* TODO: release arena back to mark */
    return NULL;
}
void CERT_DestroyGeneralName ( CERTGeneralName *  name)

Definition at line 502 of file genname.c.

void CERT_DestroyGeneralNameList ( CERTGeneralNameList *  list)

Definition at line 232 of file genname.c.

{
    PZLock *lock;

    if (list != NULL) {
       lock = list->lock;
       PZ_Lock(lock);
       if (--list->refCount <= 0 && list->arena != NULL) {
           PORT_FreeArena(list->arena, PR_FALSE);
           PZ_Unlock(lock);
           PZ_DestroyLock(lock);
       } else {
           PZ_Unlock(lock);
       }
    }
    return;
}
SECStatus cert_DestroyGeneralNames ( CERTGeneralName *  name)

Definition at line 508 of file genname.c.

{
    CERTGeneralName    *first;
    CERTGeneralName    *next = NULL;


    first = name;
    do {
       next = CERT_GetNextGeneralName(name);
       PORT_Free(name);
       name = next;
    } while (name != first);
    return SECSuccess;
}
CERTGeneralNameList* CERT_DupGeneralNameList ( CERTGeneralNameList *  list)

Definition at line 798 of file genname.c.

{
    if (list != NULL) {
       PZ_Lock(list->lock);
       list->refCount++;
       PZ_Unlock(list->lock);
    }
    return list;
}
SECItem** cert_EncodeGeneralNames ( PRArenaPool arena,
CERTGeneralName *  names 
)

Definition at line 376 of file genname.c.

{
    CERTGeneralName  *current_name;
    SECItem          **items = NULL;
    int              count = 0;
    int              i;
    PRCList          *head;

    PORT_Assert(arena);
    /* TODO: mark arena */
    current_name = names;
    if (names != NULL) {
       count = 1;
    }
    head = &(names->l);
    while (current_name->l.next != head) {
       current_name = CERT_GetNextGeneralName(current_name);
       ++count;
    }
    current_name = CERT_GetNextGeneralName(current_name);
    items = PORT_ArenaNewArray(arena, SECItem *, count + 1);
    if (items == NULL) {
       goto loser;
    }
    for (i = 0; i < count; i++) {
       items[i] = CERT_EncodeGeneralName(current_name, (SECItem *)NULL, arena);
       if (items[i] == NULL) {
           goto loser;
       }
       current_name = CERT_GetNextGeneralName(current_name);
    }
    items[i] = NULL;
    /* TODO: unmark arena */
    return items;
loser:
    /* TODO: release arena to mark */
    return NULL;
}
SECStatus cert_EncodeNameConstraints ( CERTNameConstraints *  constraints,
PRArenaPool arena,
SECItem *  dest 
)

Definition at line 589 of file genname.c.

{
    SECStatus    rv = SECSuccess;

    PORT_Assert(arena);
    /* TODO: mark arena */
    if (constraints->permited != NULL) {
       rv = cert_EncodeNameConstraintSubTree(constraints->permited, arena,
                                         &constraints->DERPermited, 
                                         PR_TRUE);
       if (rv == SECFailure) {
           goto loser;
       }
    }
    if (constraints->excluded != NULL) {
       rv = cert_EncodeNameConstraintSubTree(constraints->excluded, arena,
                                         &constraints->DERExcluded, 
                                         PR_FALSE);
       if (rv == SECFailure) {
           goto loser;
       }
    }
    dest = SEC_ASN1EncodeItem(arena, dest, constraints, 
                           CERTNameConstraintsTemplate);
    if (dest == NULL) {
       goto loser;
    }
    /* TODO: unmark arena */
    return SECSuccess;
loser:
    /* TODO: release arena to mark */
    return SECFailure;
}
void* CERT_GetGeneralNameFromListByType ( CERTGeneralNameList *  list,
CERTGeneralNameType  type,
PRArenaPool arena 
)
int CERT_GetNamesLength ( CERTGeneralName *  names)

Definition at line 981 of file genname.c.

{
    int              length = 0;
    CERTGeneralName  *first;

    first = names;
    if (names != NULL) {
       do {
           length++;
           names = CERT_GetNextGeneralName(names);
       } while (names != first);
    }
    return length;
}

Variable Documentation

Definition at line 165 of file genname.c.