Back to index

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

Go to the source code of this file.

Functions

SECOidData * SECOID_FindOID (const SECItem *oid)
SECOidTag SECOID_FindOIDTag (const SECItem *oid)
SECOidData * SECOID_FindOIDByTag (SECOidTag tagnum)
SECOidData * SECOID_FindOIDByMechanism (unsigned long mechanism)
SECStatus SECOID_SetAlgorithmID (PRArenaPool *arena, SECAlgorithmID *aid, SECOidTag tag, SECItem *params)
SECStatus SECOID_CopyAlgorithmID (PRArenaPool *arena, SECAlgorithmID *dest, SECAlgorithmID *src)
SECOidTag SECOID_GetAlgorithmTag (SECAlgorithmID *aid)
void SECOID_DestroyAlgorithmID (SECAlgorithmID *aid, PRBool freeit)
SECComparison SECOID_CompareAlgorithmID (SECAlgorithmID *a, SECAlgorithmID *b)
PRBool SECOID_KnownCertExtenOID (SECItem *extenOid)
const char * SECOID_FindOIDTagDescription (SECOidTag tagnum)
SECOidTag SECOID_AddEntry (const SECOidData *src)
SECStatus SECOID_Shutdown (void)

Variables

SEC_BEGIN_PROTOS const
SEC_ASN1Template 
SECOID_AlgorithmIDTemplate []

Function Documentation

SECOidTag SECOID_AddEntry ( const SECOidData *  src)

Definition at line 1635 of file secoid.c.

{
    SECOidData * dst;
    SECOidData **table;
    SECOidTag    ret         = SEC_OID_UNKNOWN;
    SECStatus    rv;
    int          tableEntries;
    int          used;

    if (!src || !src->oid.data || !src->oid.len || \
        !src->desc || !strlen(src->desc)) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       return ret;
    }
    if (src->supportedExtension != INVALID_CERT_EXTENSION     &&
       src->supportedExtension != UNSUPPORTED_CERT_EXTENSION &&
       src->supportedExtension != SUPPORTED_CERT_EXTENSION     ) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       return ret;
    }

    if (!dynOidPool && secoid_InitDynOidData() != SECSuccess) {
       /* Caller has set error code. */
       return ret;
    }

    NSSRWLock_LockWrite(dynOidLock);

    /* We've just acquired the write lock, and now we call FindOIDTag
    ** which will acquire and release the read lock.  NSSRWLock has been
    ** designed to allow this very case without deadlock.  This approach 
    ** makes the test for the presence of the OID, and the subsequent 
    ** addition of the OID to the table a single atomic write operation.
    */
    ret = SECOID_FindOIDTag(&src->oid);
    if (ret != SEC_OID_UNKNOWN) {
       /* we could return an error here, but I chose not to do that.
       ** This way, if we add an OID to the shared library's built in
       ** list of OIDs in some future release, and that OID is the same
       ** as some OID that a program has been adding, the program will
       ** not suddenly stop working.
       */
       goto done;
    }

    table        = dynOidTable;
    tableEntries = dynOidEntriesAllocated;
    used         = dynOidEntriesUsed;

    if (used + 1 > tableEntries) {
       SECOidData **newTable;
       int          newTableEntries = tableEntries + 16;

       newTable = (SECOidData **)PORT_Realloc(table, 
                                   newTableEntries * sizeof(SECOidData *));
       if (newTable == NULL) {
           goto done;
       }
       dynOidTable            = table        = newTable;
       dynOidEntriesAllocated = tableEntries = newTableEntries;
    }

    /* copy oid structure */
    dst = PORT_ArenaNew(dynOidPool, SECOidData);
    if (!dst) {
       goto done;
    }
    rv  = SECITEM_CopyItem(dynOidPool, &dst->oid, &src->oid);
    if (rv != SECSuccess) {
       goto done;
    }
    dst->desc = PORT_ArenaStrdup(dynOidPool, src->desc);
    if (!dst->desc) {
       goto done;
    }
    dst->offset             = (SECOidTag)(used + SEC_OID_TOTAL);
    dst->mechanism          = src->mechanism;
    dst->supportedExtension = src->supportedExtension;

    rv = secoid_HashDynamicOiddata(dst);
    if ( rv == SECSuccess ) {
       table[used++] = dst;
       dynOidEntriesUsed = used;
       ret = dst->offset;
    }
done:
    NSSRWLock_UnlockWrite(dynOidLock);
    return ret;
}
SECComparison SECOID_CompareAlgorithmID ( SECAlgorithmID *  a,
SECAlgorithmID *  b 
)

Definition at line 170 of file secalgid.c.

{
    SECComparison rv;

    rv = SECITEM_CompareItem(&a->algorithm, &b->algorithm);
    if (rv) return rv;
    rv = SECITEM_CompareItem(&a->parameters, &b->parameters);
    return rv;
}
SECStatus SECOID_CopyAlgorithmID ( PRArenaPool arena,
SECAlgorithmID *  dest,
SECAlgorithmID *  src 
)

Definition at line 151 of file secalgid.c.

{
    SECStatus rv;

    rv = SECITEM_CopyItem(arena, &to->algorithm, &from->algorithm);
    if (rv) return rv;
    rv = SECITEM_CopyItem(arena, &to->parameters, &from->parameters);
    return rv;
}
void SECOID_DestroyAlgorithmID ( SECAlgorithmID *  aid,
PRBool  freeit 
)

Definition at line 161 of file secalgid.c.

{
    SECITEM_FreeItem(&algid->parameters, PR_FALSE);
    SECITEM_FreeItem(&algid->algorithm, PR_FALSE);
    if(freeit == PR_TRUE)
        PORT_Free(algid);
}
SECOidData* SECOID_FindOID ( const SECItem *  oid)

Definition at line 1807 of file secoid.c.

{
    SECOidData *ret;

    PR_ASSERT(oidhash != NULL);
    
    ret = PL_HashTableLookupConst ( oidhash, oid );
    if ( ret == NULL ) {
       ret  = secoid_FindDynamic(oid);
       if (ret == NULL) {
           PORT_SetError(SEC_ERROR_UNRECOGNIZED_OID);
       }
    }

    return(ret);
}
SECOidData* SECOID_FindOIDByMechanism ( unsigned long  mechanism)

Definition at line 1792 of file secoid.c.

{
    SECOidData *ret;

    PR_ASSERT(oidhash != NULL);

    ret = PL_HashTableLookupConst ( oidmechhash, (void *)mechanism);
    if ( ret == NULL ) {
        PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
    }

    return (ret);
}
SECOidData* SECOID_FindOIDByTag ( SECOidTag  tagnum)

Definition at line 1838 of file secoid.c.

{

    if (tagnum >= SEC_OID_TOTAL) {
       return secoid_FindDynamicByTag(tagnum);
    }

    PORT_Assert((unsigned int)tagnum < (sizeof(oids) / sizeof(SECOidData)));
    return (SECOidData *)(&oids[tagnum]);
}
SECOidTag SECOID_FindOIDTag ( const SECItem *  oid)

Definition at line 1825 of file secoid.c.

{
    SECOidData *oiddata;

    oiddata = SECOID_FindOID (oid);
    if (oiddata == NULL)
       return SEC_OID_UNKNOWN;

    return oiddata->offset;
}

Definition at line 1862 of file secoid.c.

{
  const SECOidData *oidData = SECOID_FindOIDByTag(tagnum);
  return oidData ? oidData->desc : 0;
}
SECOidTag SECOID_GetAlgorithmTag ( SECAlgorithmID *  aid)

Definition at line 65 of file secalgid.c.

{
    if (id == NULL || id->algorithm.data == NULL)
       return SEC_OID_UNKNOWN;

    return SECOID_FindOIDTag (&(id->algorithm));
}
PRBool SECOID_KnownCertExtenOID ( SECItem *  extenOid)

Definition at line 1849 of file secoid.c.

{
    SECOidData * oidData;

    oidData = SECOID_FindOID (extenOid);
    if (oidData == (SECOidData *)NULL)
       return (PR_FALSE);
    return ((oidData->supportedExtension == SUPPORTED_CERT_EXTENSION) ?
            PR_TRUE : PR_FALSE);
}
SECStatus SECOID_SetAlgorithmID ( PRArenaPool arena,
SECAlgorithmID *  aid,
SECOidTag  tag,
SECItem *  params 
)

Definition at line 74 of file secalgid.c.

{
    SECOidData *oiddata;
    PRBool add_null_param;

    oiddata = SECOID_FindOIDByTag(which);
    if ( !oiddata ) {
       PORT_SetError(SEC_ERROR_INVALID_ALGORITHM);
       return SECFailure;
    }

    if (SECITEM_CopyItem(arena, &id->algorithm, &oiddata->oid))
       return SECFailure;

    switch (which) {
      case SEC_OID_MD2:
      case SEC_OID_MD4:
      case SEC_OID_MD5:
      case SEC_OID_SHA1:
      case SEC_OID_SHA256:
      case SEC_OID_SHA384:
      case SEC_OID_SHA512:
      case SEC_OID_PKCS1_RSA_ENCRYPTION:
      case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION:
      case SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION:
      case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION:
      case SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION:
      case SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION:
      case SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION:
      case SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION:
       add_null_param = PR_TRUE;
       break;
      default:
       add_null_param = PR_FALSE;
       break;
    }

    if (params) {
       /*
        * I am specifically *not* enforcing the following assertion
        * (by following it up with an error and a return of failure)
        * because I do not want to introduce any change in the current
        * behavior.  But I do want for us to notice if the following is
        * ever true, because I do not think it should be so and probably
        * signifies an error/bug somewhere.
        */
       PORT_Assert(!add_null_param || (params->len == 2
                                   && params->data[0] == SEC_ASN1_NULL
                                   && params->data[1] == 0));
       if (SECITEM_CopyItem(arena, &id->parameters, params)) {
           return SECFailure;
       }
    } else {
       /*
        * Again, this is not considered an error.  But if we assume
        * that nobody tries to set the parameters field themselves
        * (but always uses this routine to do that), then we should
        * not hit the following assertion.  Unless they forgot to zero
        * the structure, which could also be a bad (and wrong) thing.
        */
       PORT_Assert(id->parameters.data == NULL);

       if (add_null_param) {
           (void) SECITEM_AllocItem(arena, &id->parameters, 2);
           if (id->parameters.data == NULL) {
              return SECFailure;
           }
           id->parameters.data[0] = SEC_ASN1_NULL;
           id->parameters.data[1] = 0;
       }
    }

    return SECSuccess;
}

Definition at line 1872 of file secoid.c.

{
    if (oidhash) {
       PL_HashTableDestroy(oidhash);
       oidhash = NULL;
    }
    if (oidmechhash) {
       PL_HashTableDestroy(oidmechhash);
       oidmechhash = NULL;
    }
    /* Have to handle the case where the lock was created, but
    ** the pool wasn't. 
    ** I'm not going to attempt to create the lock, just to protect
    ** the destruction of data that probably isn't initialized anyway.
    */
    if (dynOidLock) {
       NSSRWLock_LockWrite(dynOidLock);
       if (dynOidHash) {
           PL_HashTableDestroy(dynOidHash);
           dynOidHash = NULL;
       }
       if (dynOidPool) {
           PORT_FreeArena(dynOidPool, PR_FALSE);
           dynOidPool = NULL;
       }
       if (dynOidTable) {
           PORT_Free(dynOidTable);
           dynOidTable = NULL;
       }
       dynOidEntriesAllocated = 0;
       dynOidEntriesUsed = 0;

       NSSRWLock_UnlockWrite(dynOidLock);
       NSSRWLock_Destroy(dynOidLock);
       dynOidLock = NULL;
    } else {
       /* Since dynOidLock doesn't exist, then all the data it protects
       ** should be uninitialized.  We'll check that (in DEBUG builds),
       ** and then make sure it is so, in case NSS is reinitialized.
       */
       PORT_Assert(!dynOidHash && !dynOidPool && !dynOidTable && \
                   !dynOidEntriesAllocated && !dynOidEntriesUsed);
       dynOidHash = NULL;
       dynOidPool = NULL;
       dynOidTable = NULL;
       dynOidEntriesAllocated = 0;
       dynOidEntriesUsed = 0;
    }
    return SECSuccess;
}

Variable Documentation

Definition at line 54 of file secalgid.c.