Back to index

lightning-sunbird  0.9+nobinonly
crlgen.h
Go to the documentation of this file.
00001 
00002 #ifndef _CRLGEN_H_
00003 #define _CRLGEN_H_
00004 
00005 #include "prio.h"
00006 #include "prprf.h"
00007 #include "plhash.h"
00008 #include "seccomon.h"
00009 #include "certt.h"
00010 #include "secoidt.h"
00011 
00012 
00013 #define CRLGEN_UNKNOWN_CONTEXT                   0
00014 #define CRLGEN_ISSUER_CONTEXT                    1
00015 #define CRLGEN_UPDATE_CONTEXT                    2
00016 #define CRLGEN_NEXT_UPDATE_CONTEXT               3
00017 #define CRLGEN_ADD_EXTENSION_CONTEXT             4
00018 #define CRLGEN_ADD_CERT_CONTEXT                  6
00019 #define CRLGEN_CHANGE_RANGE_CONTEXT              7
00020 #define CRLGEN_RM_CERT_CONTEXT                   8
00021 
00022 #define CRLGEN_TYPE_DATE                         0
00023 #define CRLGEN_TYPE_ZDATE                        1
00024 #define CRLGEN_TYPE_DIGIT                        2
00025 #define CRLGEN_TYPE_DIGIT_RANGE                  3
00026 #define CRLGEN_TYPE_OID                          4
00027 #define CRLGEN_TYPE_STRING                       5
00028 #define CRLGEN_TYPE_ID                           6
00029 
00030 
00031 typedef struct CRLGENGeneratorDataStr          CRLGENGeneratorData;
00032 typedef struct CRLGENEntryDataStr              CRLGENEntryData;
00033 typedef struct CRLGENExtensionEntryStr         CRLGENExtensionEntry;
00034 typedef struct CRLGENCertEntrySrt              CRLGENCertEntry;
00035 typedef struct CRLGENCrlFieldStr               CRLGENCrlField;
00036 typedef struct CRLGENEntriesSortedDataStr      CRLGENEntriesSortedData;
00037 
00038 /* Exported functions */
00039 
00040 /* Used for initialization of extension handles for crl and certs
00041  * extensions from existing CRL data then modifying existing CRL.*/
00042 extern SECStatus CRLGEN_ExtHandleInit(CRLGENGeneratorData *crlGenData);
00043 
00044 /* Commits all added entries and their's extensions into CRL. */
00045 extern SECStatus CRLGEN_CommitExtensionsAndEntries(CRLGENGeneratorData *crlGenData);
00046 
00047 /* Lunches the crl generation script parse */
00048 extern SECStatus CRLGEN_StartCrlGen(CRLGENGeneratorData *crlGenData);
00049 
00050 /* Closes crl generation script file and frees crlGenData */
00051 extern void CRLGEN_FinalizeCrlGeneration(CRLGENGeneratorData *crlGenData);
00052 
00053 /* Parser initialization function. Creates CRLGENGeneratorData structure
00054  *  for the current thread */
00055 extern CRLGENGeneratorData* CRLGEN_InitCrlGeneration(CERTSignedCrl *newCrl,
00056                                                      PRFileDesc *src);
00057 
00058 
00059 /* This lock is defined in crlgen_lex.c(derived from crlgen_lex.l).
00060  * It controls access to invocation of yylex, allows to parse one
00061  * script at a time */
00062 extern void CRLGEN_InitCrlGenParserLock();
00063 extern void CRLGEN_DestroyCrlGenParserLock();
00064 
00065 
00066 /* The following function types are used to define functions for each of
00067  * CRLGENExtensionEntryStr, CRLGENCertEntrySrt, CRLGENCrlFieldStr to
00068  * provide functionality needed for these structures*/
00069 typedef SECStatus updateCrlFn_t(CRLGENGeneratorData *crlGenData, void *str);
00070 typedef SECStatus setNextDataFn_t(CRLGENGeneratorData *crlGenData, void *str,
00071                                   void *data, unsigned short dtype);
00072 typedef SECStatus createNewLangStructFn_t(CRLGENGeneratorData *crlGenData,
00073                                           void *str, unsigned i);
00074 
00075 /* Sets reports failure to parser if anything goes wrong */
00076 extern void      crlgen_setFailure(CRLGENGeneratorData *str, char *);
00077 
00078 /* Collects data in to one of the current data structure that corresponds
00079  * to the correct context type. This function gets called after each token
00080  * is found for a particular line */
00081 extern SECStatus crlgen_setNextData(CRLGENGeneratorData *str, void *data,
00082                              unsigned short dtype);
00083 
00084 /* initiates crl update with collected data. This function is called at the
00085  * end of each line */
00086 extern SECStatus crlgen_updateCrl(CRLGENGeneratorData *str);
00087 
00088 /* Creates new context structure depending on token that was parsed
00089  * at the beginning of a line */
00090 extern SECStatus crlgen_createNewLangStruct(CRLGENGeneratorData *str,
00091                                             unsigned structType);
00092 
00093 
00094 /* CRLGENExtensionEntry is used to store addext request data for either 
00095  * CRL extensions or CRL entry extensions. The differentiation between
00096  * is based on order and type of extension been added.
00097  *    - extData : all data in request staring from name of the extension are
00098  *                in saved here.
00099  *    - nextUpdatedData: counter of elements added to extData
00100  */
00101 struct CRLGENExtensionEntryStr {
00102     char **extData;
00103     int    nextUpdatedData;
00104     updateCrlFn_t    *updateCrlFn;
00105     setNextDataFn_t  *setNextDataFn;
00106 };
00107 
00108 /* CRLGENCeryestEntry is used to store addcert request data
00109  *   - certId : certificate id or range of certificate with dash as a delimiter
00110  *              All certs from range will be inclusively added to crl
00111  *   - revocationTime: revocation time of cert(s)
00112  */
00113 struct CRLGENCertEntrySrt {
00114     char *certId;
00115     char *revocationTime;
00116     updateCrlFn_t   *updateCrlFn;
00117     setNextDataFn_t *setNextDataFn;
00118 };
00119 
00120 
00121 /* CRLGENCrlField is used to store crl fields record like update time, next
00122  * update time, etc.
00123  *  - value: value of the parsed field data*/
00124 struct CRLGENCrlFieldStr {
00125     char *value;
00126     updateCrlFn_t   *updateCrlFn;
00127     setNextDataFn_t *setNextDataFn;
00128 };
00129 
00130 /* Can not create entries extension until completely done with parsing.
00131  * Therefore need to keep joined data
00132  *   - certId : serial number of certificate
00133  *   - extHandle: head pointer to a list of extensions that belong to
00134  *                 entry
00135  *   - entry : CERTCrlEntry structure pointer*/
00136 struct CRLGENEntryDataStr {
00137     SECItem *certId;
00138     void *extHandle;
00139     CERTCrlEntry *entry;
00140 };
00141 
00142 /* Crl generator/parser main structure. Keeps info regarding current state of
00143  * parser(context, status), parser helper functions pointers, parsed data and
00144  * generated data.
00145  *  - contextId : current parsing context. Context in this parser environment
00146  *                defines what type of crl operations parser is going through
00147  *                in the current line of crl generation script.
00148  *                setting or new cert or an extension addition, etc.
00149  *  - createNewLangStructFn: pointer to top level function which creates
00150  *                             data structures according contextId
00151  *  - setNextDataFn : pointer to top level function which sets new parsed data
00152  *                    in temporary structure
00153  *  - updateCrlFn   : pointer to top level function which triggers actual
00154  *                    crl update functions with gathered data
00155  *  - union         : data union create according to contextId
00156  *  - rangeFrom, rangeTo : holds last range in which certs was added
00157  *  - newCrl        : pointer to CERTSignedCrl newly created crl
00158  *  - crlExtHandle : pointer to crl extension handle
00159  *  - entryDataHashTable: hash of CRLGENEntryData.
00160  *                     key: cert serial number
00161  *                     data: CRLGENEntryData pointer
00162  *  - parserStatus  : current status of parser. Triggers parser to abort when
00163  *                    set to SECFailure
00164  *  - src : PRFileDesc structure pointer of crl generator config file
00165  *  - parsedLineNum : currently parsing line. Keeping it to report errors */ 
00166 struct CRLGENGeneratorDataStr {
00167     unsigned short contextId;
00168     CRLGENCrlField       *crlField;
00169     CRLGENCertEntry      *certEntry;
00170     CRLGENExtensionEntry *extensionEntry; 
00171     PRUint64 rangeFrom;
00172     PRUint64 rangeTo;
00173     CERTSignedCrl *signCrl;
00174     void *crlExtHandle;
00175     PLHashTable *entryDataHashTable;
00176     
00177     PRFileDesc *src;
00178     int parsedLineNum;
00179 };
00180 
00181 
00182 #endif /* _CRLGEN_H_ */