cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
certfn.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * Certificate Function Header File *
4 * Copyright Peter Gutmann 1996-2008 *
5 * *
6 ****************************************************************************/
7 
8 /* The huge complexity of the certificate management code means that there
9  are a sufficient number of functions required that we confine the
10  prototypes to their own file */
11 
12 #ifndef _CERTFN_DEFINED
13 
14 #define _CERTFN_DEFINED
15 
16 /****************************************************************************
17 * *
18 * DN Manipulation Functions *
19 * *
20 ****************************************************************************/
21 
22 /* DN manipulation routines */
23 
24 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3, 5 ) ) \
25 int insertDNComponent( INOUT_PTR DN_PTR **dnComponentListPtrPtr,
27  IN_BUFFER( valueLength ) const void *value,
30  CRYPT_ERRTYPE_TYPE *errorType );
32 int deleteDNComponent( INOUT_PTR DN_PTR **dnComponentListPtrPtr,
34  IN_BUFFER_OPT( valueLength ) const void *value,
35  IN_LENGTH_SHORT const int valueLength );
36 STDC_NONNULL_ARG( ( 1 ) ) \
37 void deleteDN( INOUT_PTR DN_PTR **dnComponentListPtrPtr );
38 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3 ) ) \
39 int getDNComponentInfo( INOUT const DN_PTR *dnComponentList,
42 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 6 ) ) \
43 int getDNComponentValue( const DN_PTR *dnComponentList,
45  IN_RANGE( 0, 100 ) const int count,
47  *valueLength ) void *value,
49  OUT_LENGTH_SHORT_Z int *valueLength );
50 
51 /* Copy and compare a DN */
52 
54 int copyDN( OUT_OPT_PTR DN_PTR **dnDest, IN_OPT const DN_PTR *dnSrc );
55 CHECK_RETVAL_BOOL \
56 BOOLEAN compareDN( IN_OPT const DN_PTR *dnComponentList1,
57  IN_OPT const DN_PTR *dnComponentList2,
58  const BOOLEAN dn1substring,
59  OUT_OPT_PTR_OPT DN_PTR **mismatchPointPtrPtr );
60 
61 /* Select DN/GeneralName components */
62 
64 int selectGeneralName( INOUT CERT_INFO *certInfoPtr,
68 int selectGeneralNameComponent( INOUT CERT_INFO *certInfoPtr,
69  IN_ATTRIBUTE \
70  const CRYPT_ATTRIBUTE_TYPE certInfoType );
72 int selectDN( INOUT CERT_INFO *certInfoPtr,
73  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType,
75 
76 /* Read/write a DN */
77 
78 CHECK_RETVAL STDC_NONNULL_ARG( ( 3, 4 ) ) \
79 int checkDN( IN_OPT const DN_PTR *dnComponentList,
80  IN_FLAGS( CHECKDN ) const int checkFlags,
81  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
82  CRYPT_ATTRIBUTE_TYPE *errorLocus,
83  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
84  CRYPT_ERRTYPE_TYPE *errorType );
85 CHECK_RETVAL \
86 int sizeofDN( INOUT_OPT DN_PTR *dnComponentList );
87  /* Non-const because it performs a pre-encoding pass */
88 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
89 int readDN( INOUT STREAM *stream,
90  OUT_OPT_PTR DN_PTR **dnComponentListPtrPtr );
92 int writeDN( INOUT STREAM *stream,
93  IN_OPT const DN_PTR *dnComponentList,
94  IN_TAG const int tag );
95 #ifdef USE_CERT_DNSTRING
96 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
97 int readDNstring( INOUT_PTR DN_PTR **dnComponentListPtrPtr,
98  IN_BUFFER( stringLength ) const BYTE *string,
101 int writeDNstring( INOUT STREAM *stream,
102  IN_OPT const DN_PTR *dnComponentList );
103 #endif /* USE_CERT_DNSTRING */
104 
105 /****************************************************************************
106 * *
107 * Attribute Manipulation Functions *
108 * *
109 ****************************************************************************/
110 
111 /* Find an attribute */
112 
114 ATTRIBUTE_PTR *findAttributeByOID( const ATTRIBUTE_PTR *attributePtr,
115  IN_BUFFER( oidLength ) const BYTE *oid,
117 CHECK_RETVAL_PTR \
118 ATTRIBUTE_PTR *findAttribute( IN_OPT const ATTRIBUTE_PTR *attributePtr,
120  const BOOLEAN isFieldID );
121 CHECK_RETVAL_PTR \
122 ATTRIBUTE_PTR *findAttributeField( IN_OPT const ATTRIBUTE_PTR *attributePtr,
126 CHECK_RETVAL_PTR \
127 ATTRIBUTE_PTR *findAttributeFieldEx( IN_OPT const ATTRIBUTE_PTR *attributePtr,
128  IN_ATTRIBUTE \
131 ATTRIBUTE_PTR *findNextFieldInstance( const ATTRIBUTE_PTR *attributePtr );
133 ATTRIBUTE_PTR *findDnInAttribute( IN_OPT const ATTRIBUTE_PTR *attributePtr );
134 
135 /* Get/set information about an attribute:
136 
137  PROPERTY_BLOBATTRIBUTE: The item contains a single blob-type attribute.
138 
139  PROPERTY_COMPLETEATTRIBUTE: This item isn't explicitly present in the
140  attribute list but represents an entire (constructed) attribute of
141  which one field is present, see the long comment for
142  findAttributeFieldEx() in cert/ext.c for a detailed description.
143 
144  PROPERTY_CRITICAL: The item (which should be a complete attribute) has
145  the critical flag set.
146 
147  PROPERTY_DEFAULTVALUE: The item is a dummy placeholder entry containing
148  a default value for an attribute, this field isn't explicitly
149  present in the attribute list but exists only to contain this
150  default value.
151 
152  PROPERTY_DN: The item contains a composite DN rather than an integer/
153  boolean/data value.
154 
155  PROPERTY_IGNORED: This item is a recognised attribute but is ignored at
156  the current compliance level.
157 
158  PROPERTY_VALUE: The integer value for the attribute. This isn't really
159  an attribute property but we need to be able to set it in a few rare
160  cases when we're applying a constraint to an attribute where the
161  constraint modifies the attribute's integer value.
162 
163  PROPERTY_LOCKED: This item is locked against further changes.
164 
165  PROPERTY_OID: The data in this item is an encoded OID that needs to be
166  decoded into the OID text representation before being returned to
167  the caller */
168 
169 typedef enum {
170  ATTRIBUTE_PROPERTY_NONE, /* No attribute property type */
171  ATTRIBUTE_PROPERTY_DEFAULTVALUE,/* Field has default value */
172  ATTRIBUTE_PROPERTY_BLOBATTRIBUTE, /* Item is a single blob attribute */
173  ATTRIBUTE_PROPERTY_COMPLETEATRIBUTE,/* Item is a complete attribute */
174  ATTRIBUTE_PROPERTY_LOCKED, /* Item is locked against changes */
175  ATTRIBUTE_PROPERTY_CRITICAL, /* Attribute is critical */
176  ATTRIBUTE_PROPERTY_DN, /* Attribute contains composite DN */
177  ATTRIBUTE_PROPERTY_OID, /* Attribute data is an OID */
178  ATTRIBUTE_PROPERTY_IGNORED, /* Attribute is ignored */
179  ATTRIBUTE_PROPERTY_VALUE, /* Attribute integer value */
180  ATTRIBUTE_PROPERTY_LAST /* Last possible property type */
182 
184 BOOLEAN checkAttributeProperty( const ATTRIBUTE_PTR *attributePtr,
185  IN_ENUM( ATTRIBUTE_PROPERTY ) \
186  ATTRIBUTE_PROPERTY_TYPE property );
187 STDC_NONNULL_ARG( ( 1 ) ) \
188 void setAttributeProperty( INOUT ATTRIBUTE_PTR *attributePtr,
189  IN_ENUM( ATTRIBUTE_PROPERTY ) \
190  ATTRIBUTE_PROPERTY_TYPE property,
191  IN_INT_Z const int optValue );
193 int getAttributeIdInfo( const ATTRIBUTE_PTR *attributePtr,
197 CHECK_RETVAL \
199 CHECK_RETVAL_BOOL \
200 BOOLEAN checkAttributePresent( IN_OPT const ATTRIBUTE_PTR *attributePtr,
202 CHECK_RETVAL_BOOL \
203 BOOLEAN checkAttributeFieldPresent( IN_OPT const ATTRIBUTE_PTR *attributePtr,
205 
206 /* Get attribute data. See the comment by the SELECTION_INFO definition for
207  why dnPtr uses double indirection for the pointer instead of single
208  indirection */
209 
210 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
211 int getAttributeDataValue( IN const ATTRIBUTE_PTR *attributePtr,
212  OUT_INT_Z int *value );
213 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
214 int getAttributeDataTime( IN const ATTRIBUTE_PTR *attributePtr,
215  OUT time_t *value );
216 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
217 int getAttributeDataDN( IN const ATTRIBUTE_PTR *attributePtr,
219 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3 ) ) \
220 int getAttributeDataPtr( IN const ATTRIBUTE_PTR *attributePtr,
223 
224 /* The pattern { findAttributeField(), getAttributeDataXYZ() } is used
225  frequently enough that we provide a common function for it */
226 
228 int getAttributeFieldValue( IN_OPT const ATTRIBUTE_PTR *attributePtr,
232  OUT_INT_Z int *value );
234 int getAttributeFieldTime( IN_OPT const ATTRIBUTE_PTR *attributePtr,
238  OUT time_t *value );
239 
240 /* Enumerate entries in an attribute list. This is a somewhat oddball
241  function that's required to handle a small number of special-case
242  situations that can't be easily handled directly. The alternative to
243  having the hardwired selections is to provide a general-purpose
244  enumeration capability and then have the caller extract whatever's
245  necessary from the attribute and decide whether they want to continue,
246  however this creates really akward attribute-enumeration loops and,
247  since there are only three cases that we need to handle, really isn't
248  worth the effort */
249 
250 typedef enum {
251  ATTRIBUTE_ENUM_NONE, /* No attribute enumeration type */
252  ATTRIBUTE_ENUM_BLOB, /* Enumerate blob attributes */
253  ATTRIBUTE_ENUM_NONBLOB, /* Enumerate non-blob attributes */
254  ATTRIBUTE_ENUM_LAST /* Last possible attribute enumeration type */
256 
257 typedef struct {
258  const ATTRIBUTE_PTR *attributePtr; /* Currently selected attribute entry */
259  ATTRIBUTE_ENUM_TYPE enumType; /* Type of enumeration being performed */
261 
263 const ATTRIBUTE_PTR *getFirstAttribute( OUT ATTRIBUTE_ENUM_INFO *attrEnumInfo,
264  IN_OPT const ATTRIBUTE_PTR *attributePtr,
265  IN_ENUM( ATTRIBUTE_ENUM ) \
266  const ATTRIBUTE_ENUM_TYPE enumType );
268 const ATTRIBUTE_PTR *getNextAttribute( INOUT ATTRIBUTE_ENUM_INFO *attrEnumInfo );
269 
270 /* Since many of the attributes can be disabled to save space and reduce
271  complexity, we may need to check that an attribute that we want to use is
272  actually available, for example if we're about to create it as part of an
273  internal operation for which we don't want to present an unexpected error
274  status to the caller. The following function checks whether an attribute
275  is enabled for use */
276 
277 CHECK_RETVAL_BOOL \
279 
280 /* Move the current attribute cursor */
281 
282 CHECK_RETVAL_PTR \
283 ATTRIBUTE_PTR *certMoveAttributeCursor( IN_OPT const ATTRIBUTE_PTR *currentCursor,
284  IN_ATTRIBUTE \
285  const CRYPT_ATTRIBUTE_TYPE certInfoType,
288  const int position );
289 
290 /* Add/delete/copy attributes/attribute fields */
291 
292 CHECK_RETVAL STDC_NONNULL_ARG( ( 2, 3, 6 ) ) \
293 int addAttribute( IN_ATTRIBUTE const ATTRIBUTE_TYPE attributeType,
295  IN_BUFFER( oidLength ) const BYTE *oid,
297  const BOOLEAN critical,
298  IN_BUFFER( dataLength ) const void *data,
299  IN_LENGTH_SHORT const int dataLength,
300  IN_FLAGS_Z( ATTR ) const int flags );
301 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 6, 7 ) ) \
302 int addAttributeField( INOUT ATTRIBUTE_PTR **listHeadPtr,
306  IN_INT_Z const int value,
307  IN_FLAGS_Z( ATTR ) const int flags,
308  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
309  CRYPT_ATTRIBUTE_TYPE *errorLocus,
310  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
311  CRYPT_ERRTYPE_TYPE *errorType );
312 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 4, 7, 8 ) ) \
313 int addAttributeFieldString( INOUT ATTRIBUTE_PTR **listHeadPtr,
314  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE fieldID,
316  const CRYPT_ATTRIBUTE_TYPE subFieldID,
317  IN_BUFFER( dataLength ) const void *data,
318  IN_LENGTH_ATTRIBUTE const int dataLength,
319  IN_FLAGS_Z( ATTR ) const int flags,
320  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
321  CRYPT_ATTRIBUTE_TYPE *errorLocus,
322  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
323  CRYPT_ERRTYPE_TYPE *errorType );
324 RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
325 int deleteAttributeField( INOUT ATTRIBUTE_PTR **attributePtr,
328  IN_OPT const DN_PTR *dnCursor );
329 RETVAL STDC_NONNULL_ARG( ( 1, 2, 3 ) ) \
330 int deleteCompositeAttributeField( INOUT ATTRIBUTE_PTR **attributePtr,
333  IN_OPT const DN_PTR *dnCursor );
334 RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
335 int deleteAttribute( INOUT ATTRIBUTE_PTR **attributePtr,
338  IN_OPT const DN_PTR *dnCursor );
339 RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
340 int deleteCompleteAttribute( INOUT ATTRIBUTE_PTR **attributeListPtr,
343  IN_OPT const DN_PTR *dnCursor );
344 STDC_NONNULL_ARG( ( 1 ) ) \
345 void deleteAttributes( INOUT ATTRIBUTE_PTR **attributePtr );
346 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3, 4 ) ) \
347 int copyAttributes( INOUT ATTRIBUTE_PTR **destHeadPtr,
349  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
350  CRYPT_ATTRIBUTE_TYPE *errorLocus,
351  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
352  CRYPT_ERRTYPE_TYPE *errorType );
353 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 4, 5 ) ) \
354 int copyIssuerAttributes( INOUT ATTRIBUTE_PTR **destListHeadPtr,
356  const CRYPT_CERTTYPE_TYPE type,
357  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
358  CRYPT_ATTRIBUTE_TYPE *errorLocus,
359  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
360  CRYPT_ERRTYPE_TYPE *errorType );
361 #ifdef USE_CERTREQ
362 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
363 int copyCRMFRequestAttributes( INOUT ATTRIBUTE_PTR **destListHeadPtr,
364  const ATTRIBUTE_PTR *srcListPtr );
365 #endif /* USE_CERTREQ */
366 #ifdef USE_CERTVAL
367 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
368 int copyRTCSRequestAttributes( INOUT ATTRIBUTE_PTR **destListHeadPtr,
369  const ATTRIBUTE_PTR *srcListPtr );
370 #endif /* USE_CERTVAL */
371 #ifdef USE_CERTREV
372 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
373 int copyOCSPRequestAttributes( INOUT ATTRIBUTE_PTR **destListHeadPtr,
374  const ATTRIBUTE_PTR *srcListPtr );
375 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
376 int copyRevocationAttributes( INOUT ATTRIBUTE_PTR **destListHeadPtr,
377  const ATTRIBUTE_PTR *srcListPtr );
378 #endif /* USE_CERTREV */
379 
380 /* Read/write a collection of attributes */
381 
382 CHECK_RETVAL STDC_NONNULL_ARG( ( 2, 3, 4 ) ) \
383 int checkAttributes( IN_ENUM( ATTRIBUTE ) const ATTRIBUTE_TYPE attributeType,
384  const ATTRIBUTE_PTR *listHeadPtr,
385  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
386  CRYPT_ATTRIBUTE_TYPE *errorLocus,
387  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
388  CRYPT_ERRTYPE_TYPE *errorType );
389 CHECK_RETVAL \
390 int sizeofAttributes( IN_OPT const ATTRIBUTE_PTR *attributePtr );
391 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
392 int writeAttributes( INOUT STREAM *stream,
393  INOUT ATTRIBUTE_PTR *attributePtr,
394  IN_ENUM_OPT( CRYPT_CERTTYPE ) const CRYPT_CERTTYPE_TYPE type,
396 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 5, 6 ) ) \
397 int readAttributes( INOUT STREAM *stream,
399  IN_ENUM_OPT( CRYPT_CERTTYPE ) const CRYPT_CERTTYPE_TYPE type,
401  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
402  CRYPT_ATTRIBUTE_TYPE *errorLocus,
403  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
404  CRYPT_ERRTYPE_TYPE *errorType );
405 
406 /****************************************************************************
407 * *
408 * Validity Information Processing Functions *
409 * *
410 ****************************************************************************/
411 
412 #ifdef USE_CERTVAL
413 
414 /* Read/write validity information */
415 
417 int sizeofRtcsRequestEntry( INOUT VALIDITY_INFO *rtcsEntry );
418 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3 ) ) \
419 int readRtcsRequestEntry( INOUT STREAM *stream,
420  INOUT_PTR VALIDITY_INFO **listHeadPtrPtr,
421  INOUT CERT_INFO *certInfoPtr );
422 STDC_NONNULL_ARG( ( 1, 2 ) ) \
423 int writeRtcsRequestEntry( INOUT STREAM *stream,
424  const VALIDITY_INFO *rtcsEntry );
426 int sizeofRtcsResponseEntry( INOUT VALIDITY_INFO *rtcsEntry,
427  const BOOLEAN isFullResponse );
428 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3 ) ) \
429 int readRtcsResponseEntry( INOUT STREAM *stream,
430  INOUT_PTR VALIDITY_INFO **listHeadPtrPtr,
431  INOUT CERT_INFO *certInfoPtr,
432  const BOOLEAN isFullResponse );
433 STDC_NONNULL_ARG( ( 1, 2 ) ) \
434 int writeRtcsResponseEntry( INOUT STREAM *stream,
435  const VALIDITY_INFO *rtcsEntry,
436  const BOOLEAN isFullResponse );
437 
438 /* Add/delete a validity entry */
439 
440 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
441 int addValidityEntry( INOUT_PTR VALIDITY_INFO **listHeadPtrPtr,
442  OUT_OPT_PTR_OPT VALIDITY_INFO **newEntryPosition,
443  IN_BUFFER( valueLength ) const void *value,
444  IN_LENGTH_FIXED( KEYID_SIZE ) const int valueLength );
445 CHECK_RETVAL STDC_NONNULL_ARG( ( 2, 3, 4 ) ) \
446 int prepareValidityEntries( IN_OPT const VALIDITY_INFO *listPtr,
447  OUT_OPT_PTR VALIDITY_INFO **errorEntry,
448  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
449  CRYPT_ATTRIBUTE_TYPE *errorLocus,
450  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
451  CRYPT_ERRTYPE_TYPE *errorType );
452 STDC_NONNULL_ARG( ( 1 ) ) \
453 void deleteValidityEntries( INOUT_PTR VALIDITY_INFO **listHeadPtrPtr );
454 
455 /* Copy a set of validity entries */
456 
457 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
458 int copyValidityEntries( INOUT_PTR VALIDITY_INFO **destListHeadPtrPtr,
459  const VALIDITY_INFO *srcListPtr );
460 
461 /* Check a certificate's validity status */
462 
464 int checkRTCSResponse( INOUT CERT_INFO *certInfoPtr,
466 
467 #endif /* USE_CERTVAL */
468 
469 /****************************************************************************
470 * *
471 * Revocation Information Processing Functions *
472 * *
473 ****************************************************************************/
474 
475 #ifdef USE_CERTREV
476 
477 /* Read/write revocation information */
478 
480 int sizeofCRLentry( INOUT REVOCATION_INFO *crlEntry );
481 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 4, 5 ) ) \
482 int readCRLentry( INOUT STREAM *stream,
483  INOUT_PTR REVOCATION_INFO **listHeadPtrPtr,
484  IN_LENGTH_Z const int entryNo,
485  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
486  CRYPT_ATTRIBUTE_TYPE *errorLocus,
487  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
488  CRYPT_ERRTYPE_TYPE *errorType );
489 STDC_NONNULL_ARG( ( 1, 2 ) ) \
490 int writeCRLentry( INOUT STREAM *stream,
491  const REVOCATION_INFO *crlEntry );
493 int sizeofOcspRequestEntry( INOUT REVOCATION_INFO *ocspEntry );
494 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3 ) ) \
495 int readOcspRequestEntry( INOUT STREAM *stream,
496  INOUT_PTR REVOCATION_INFO **listHeadPtrPtr,
497  INOUT CERT_INFO *certInfoPtr );
498 STDC_NONNULL_ARG( ( 1, 2 ) ) \
499 int writeOcspRequestEntry( INOUT STREAM *stream,
500  const REVOCATION_INFO *ocspEntry );
502 int sizeofOcspResponseEntry( INOUT REVOCATION_INFO *ocspEntry );
503 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3 ) ) \
504 int readOcspResponseEntry( INOUT STREAM *stream,
505  INOUT_PTR REVOCATION_INFO **listHeadPtrPtr,
506  INOUT CERT_INFO *certInfoPtr );
507 STDC_NONNULL_ARG( ( 1, 2 ) ) \
508 int writeOcspResponseEntry( INOUT STREAM *stream,
509  const REVOCATION_INFO *ocspEntry,
510  const time_t entryTime );
511 
512 /* Add/delete a revocation entry */
513 
514 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 4 ) ) \
515 int addRevocationEntry( INOUT_PTR REVOCATION_INFO **listHeadPtrPtr,
516  OUT_OPT_PTR REVOCATION_INFO **newEntryPosition,
517  IN_KEYID const CRYPT_KEYID_TYPE valueType,
518  IN_BUFFER( valueLength ) const void *value,
519  IN_LENGTH_SHORT const int valueLength,
520  const BOOLEAN noCheck );
521 
522 CHECK_RETVAL STDC_NONNULL_ARG( ( 3, 5, 6 ) ) \
523 int prepareRevocationEntries( INOUT_OPT REVOCATION_INFO *listPtr,
524  const time_t defaultTime,
525  OUT_OPT_PTR REVOCATION_INFO **errorEntry,
526  const BOOLEAN isSingleEntry,
527  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
528  CRYPT_ATTRIBUTE_TYPE *errorLocus,
529  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
530  CRYPT_ERRTYPE_TYPE *errorType );
531 STDC_NONNULL_ARG( ( 1 ) ) \
532 void deleteRevocationEntries( INOUT_PTR REVOCATION_INFO **listHeadPtrPtr );
533 
534 /* Copy a set of revocation entries */
535 
536 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
537 int copyRevocationEntries( INOUT_PTR REVOCATION_INFO **destListHeadPtrPtr,
538  const REVOCATION_INFO *srcListPtr );
539 
540 /* Check a certificate's revocation status */
541 
543 int checkCRL( INOUT CERT_INFO *certInfoPtr,
546 int checkOCSPResponse( INOUT CERT_INFO *certInfoPtr,
548 
549 #endif /* USE_CERTREV */
550 
551 /****************************************************************************
552 * *
553 * Certificate Checking Functions *
554 * *
555 ****************************************************************************/
556 
557 /* Check a certificate object */
558 
560 int checkCertBasic( INOUT CERT_INFO *subjectCertInfoPtr );
561 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 4, 5 ) ) \
562 int checkCert( INOUT CERT_INFO *subjectCertInfoPtr,
565  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
566  CRYPT_ATTRIBUTE_TYPE *errorLocus,
567  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
568  CRYPT_ERRTYPE_TYPE *errorType );
570 int checkCertChain( INOUT CERT_INFO *certInfoPtr );
571 
572 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3, 4 ) ) \
573 int getKeyUsageFromExtKeyUsage( const CERT_INFO *certInfoPtr,
574  OUT_FLAGS_Z( CRYPT_KEYUSAGE ) int *keyUsage,
575  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
576  CRYPT_ATTRIBUTE_TYPE *errorLocus,
577  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
578  CRYPT_ERRTYPE_TYPE *errorType );
579 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 5, 6 ) ) \
580 int checkKeyUsage( const CERT_INFO *certInfoPtr,
581  IN_FLAGS_Z( CHECKKEY ) const int flags,
582  IN_FLAGS_Z( CRYPT_KEYUSAGE ) const int specificUsage,
585  const int complianceLevel,
586  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
587  CRYPT_ATTRIBUTE_TYPE *errorLocus,
588  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
589  CRYPT_ERRTYPE_TYPE *errorType );
590 
591 /* Check certificate constraints */
592 
593 #ifdef USE_CERTLEVEL_PKIX_FULL
594 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 4, 5 ) ) \
595 int checkNameConstraints( const CERT_INFO *subjectCertInfoPtr,
596  const ATTRIBUTE_PTR *issuerAttributes,
597  const BOOLEAN isExcluded,
598  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
599  CRYPT_ATTRIBUTE_TYPE *errorLocus,
600  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
601  CRYPT_ERRTYPE_TYPE *errorType );
603 BOOLEAN isAnyPolicy( const ATTRIBUTE_PTR *attributePtr );
604 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 7, 8 ) ) \
605 int checkPolicyConstraints( const CERT_INFO *subjectCertInfoPtr,
606  const ATTRIBUTE_PTR *issuerAttributes,
607  IN_ENUM_OPT( POLICY ) const POLICY_TYPE policyType,
608  IN_OPT const POLICY_INFO *policyInfo,
609  IN_RANGE( 0, MAX_CHAINLENGTH ) const int policyLevel,
610  const BOOLEAN allowMappedPolicies,
611  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
612  CRYPT_ATTRIBUTE_TYPE *errorLocus,
613  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
614  CRYPT_ERRTYPE_TYPE *errorType );
615 #endif /* USE_CERTLEVEL_PKIX_FULL */
616 #ifdef USE_CERTLEVEL_PKIX_PARTIAL
617 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3, 4 ) ) \
618 int checkPathConstraints( const CERT_INFO *subjectCertInfoPtr,
619  IN_LENGTH_SHORT_Z const int pathLength,
620  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
621  CRYPT_ATTRIBUTE_TYPE *errorLocus,
622  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
623  CRYPT_ERRTYPE_TYPE *errorType );
624 #endif /* USE_CERTLEVEL_PKIX_PARTIAL */
625 
626 /* Sign/sig check a certificate */
627 
629 int signCert( INOUT CERT_INFO *certInfoPtr,
632 int checkCertValidity( INOUT CERT_INFO *certInfoPtr,
634 
635 /****************************************************************************
636 * *
637 * Certificate Chain Functions *
638 * *
639 ****************************************************************************/
640 
641 /* Read/write/copy a certificate chain */
642 
643 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
644 int readCertChain( INOUT STREAM *stream,
647  IN_ENUM( CRYPT_CERTTYPE ) const CRYPT_CERTTYPE_TYPE type,
649  IN_BUFFER_OPT( keyIDlength ) const void *keyID,
651  const BOOLEAN dataOnlyCert );
652 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
653 int writeCertChain( INOUT STREAM *stream,
654  const CERT_INFO *certInfoPtr );
656 int copyCertChain( INOUT CERT_INFO *certInfoPtr,
658  const BOOLEAN isCertCollection );
659 
660 /* Read/write certificate collections in assorted formats */
661 
663 int sizeofCertCollection( const CERT_INFO *certInfoPtr,
664  IN_ENUM( CRYPT_CERTFORMAT ) \
665  const CRYPT_CERTFORMAT_TYPE certFormatType );
666 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
667 int writeCertCollection( INOUT STREAM *stream,
668  const CERT_INFO *certInfoPtr,
669  IN_ENUM( CRYPT_CERTFORMAT ) \
670  const CRYPT_CERTFORMAT_TYPE certFormatType );
671 
672 /* Assemble a certificate chain from certificates read from an object */
673 
674 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 4 ) ) \
675 int assembleCertChain( OUT CRYPT_CERTIFICATE *iCertificate,
677  IN_KEYID const CRYPT_KEYID_TYPE keyIDtype,
678  IN_BUFFER( keyIDlength ) const void *keyID,
679  IN_LENGTH_KEYID const int keyIDlength,
680  IN_FLAGS( KEYMGMT ) const int options );
681 
682 /****************************************************************************
683 * *
684 * Certificate Functions *
685 * *
686 ****************************************************************************/
687 
688 /* Create a certificate object ready for further initialisation */
689 
691 int createCertificateInfo( OUT_OPT_PTR CERT_INFO **certInfoPtrPtr,
692  IN_HANDLE const CRYPT_USER iCryptOwner,
693  IN_ENUM( CRYPT_CERTTYPE ) \
695 
696 /* Add/get/delete a certificate component */
697 
699 int addCertComponent( INOUT CERT_INFO *certInfoPtr,
700  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType,
701  IN_INT_Z const int certInfo );
702 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
703 int addCertComponentString( INOUT CERT_INFO *certInfoPtr,
704  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType,
705  IN_BUFFER( certInfoLength ) const void *certInfo,
707 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
708 int getCertComponent( INOUT CERT_INFO *certInfoPtr,
709  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType,
710  OUT_INT_Z int *certInfo );
711 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 5 ) ) \
712 int getCertComponentString( INOUT CERT_INFO *certInfoPtr,
713  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType,
715  *certInfoLength ) void *certInfo,
719 int deleteCertComponent( INOUT CERT_INFO *certInfoPtr,
720  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType );
721 
722 /* Manage certificate attribute cursors */
723 
725 int setCertificateCursor( INOUT CERT_INFO *certInfoPtr,
727  CRYPT_CURSOR_FIRST ) /* Values are -ve */
728  const int cursorMoveType );
730 int setAttributeCursor( INOUT CERT_INFO *certInfoPtr,
731  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType,
732  IN const int value );
733 
734 /* Import/export a certificate */
735 
736 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
737 int importCert( IN_BUFFER( certObjectLength ) const void *certObject,
740  IN_HANDLE const CRYPT_USER iCryptOwner,
741  IN_KEYID const CRYPT_KEYID_TYPE keyIDtype,
742  IN_BUFFER_OPT( keyIDlength ) const void *keyID,
743  IN_LENGTH_KEYID_Z const int keyIDlength,
744  IN_ENUM_OPT( CRYPT_CERTTYPE ) \
745  const CRYPT_CERTTYPE_TYPE formatHint );
746 CHECK_RETVAL STDC_NONNULL_ARG( ( 3, 5 ) ) \
747 int exportCert( OUT_BUFFER_OPT( certObjectMaxLength, *certObjectLength ) \
748  void *certObject,
749  IN_LENGTH const int certObjectMaxLength,
750  OUT_LENGTH_Z int *certObjectLength,
751  IN_ENUM( CRYPT_CERTFORMAT ) \
752  const CRYPT_CERTFORMAT_TYPE certFormatType,
753  const CERT_INFO *certInfoPtr );
754 
755 /* Oddball routines: work with a certificate's serial number */
756 
758 int setSerialNumber( INOUT CERT_INFO *certInfoPtr,
759  IN_BUFFER_OPT( serialNumberLength ) const void *serialNumber,
761 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3 ) ) \
762 BOOLEAN compareSerialNumber( IN_BUFFER( canonSerialNumberLength ) \
763  const void *canonSerialNumber,
766  const void *serialNumber,
768 
769 /****************************************************************************
770 * *
771 * Miscellaneous Functions *
772 * *
773 ****************************************************************************/
774 
775 /* Convert a text-form OID to its binary form */
776 
777 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 3, 5 ) ) \
778 int textToOID( IN_BUFFER( textOidLength ) const char *textOID,
780  const int textOidLength,
781  OUT_BUFFER( binaryOidMaxLen, *binaryOidLen ) BYTE *binaryOID,
784 
785 /* Check that a text string contains valid characters for its string type.
786  This is used in non-DN strings where we can't avoid the problem by varying
787  the string type based on the characters being used */
788 
790 BOOLEAN checkTextStringData( IN_BUFFER( stringLen ) const char *string,
792  const BOOLEAN isPrintableString );
793 
794 /* Prototypes for functions in certext.c */
795 
796 CHECK_RETVAL_BOOL \
797 BOOLEAN isValidField( IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE fieldID,
798  IN_ENUM( CRYPT_CERTTYPE ) \
800 
801 /* Prototypes for functions in certschk.c */
802 
803 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 7, 8 ) ) \
804 int checkCertDetails( INOUT CERT_INFO *subjectCertInfoPtr,
805  INOUT_OPT CERT_INFO *issuerCertInfoPtr,
809  const BOOLEAN shortCircuitCheck,
810  OUT_ENUM_OPT( CRYPT_ATTRIBUTE ) \
811  CRYPT_ATTRIBUTE_TYPE *errorLocus,
812  OUT_ENUM_OPT( CRYPT_ERRTYPE ) \
813  CRYPT_ERRTYPE_TYPE *errorType );
814 
815 /* Prototypes for functions in comp_cert.c */
816 
818 int copyPublicKeyInfo( INOUT CERT_INFO *certInfoPtr,
822 int copyCertObject( INOUT CERT_INFO *certInfoPtr,
824  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE certInfoType,
825  IN const int certInfo );
826 
827 /* Prototypes for functions in comp_get.c */
828 
830 time_t *getRevocationTimePtr( const CERT_INFO *certInfoPtr );
832 ATTRIBUTE_PTR *findAttributeComponent( const CERT_INFO *certInfoPtr,
833  IN_ATTRIBUTE \
834  const CRYPT_ATTRIBUTE_TYPE certInfoType );
835 
836 /* Prototypes for functions in dn.c */
837 
838 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
839 int convertEmail( INOUT CERT_INFO *certInfoPtr,
840  INOUT DN_PTR **dnComponentListPtrPtr,
842 
843 /* Prototypes for functions in ext.c */
844 
846 BOOLEAN compareAttribute( const ATTRIBUTE_PTR *attributeField1,
849 int fixAttributes( INOUT CERT_INFO *certInfoPtr );
850 
851 /* Prototypes for functions in ext_def.c */
852 
853 CHECK_RETVAL_BOOL \
854 BOOLEAN checkExtensionTables( void );
855 
856 /* Prototypes for functions in imp_chk.c */
857 
858 CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3, 4 ) ) \
859 int getCertObjectInfo( INOUT STREAM *stream,
862  OUT_ENUM_OPT( CRYPT_CERTTYPE ) \
864  IN_ENUM( CRYPT_CERTTYPE ) \
865  const CRYPT_CERTTYPE_TYPE formatHint );
866 
867 /* Prototypes for functions in write_pre.c */
868 
870 int preEncodeCertificate( INOUT CERT_INFO *subjectCertInfoPtr,
871  IN_OPT const CERT_INFO *issuerCertInfoPtr,
872  IN_FLAGS( PRE_SET ) const int actions );
874 int preCheckCertificate( INOUT CERT_INFO *subjectCertInfoPtr,
875  IN_OPT const CERT_INFO *issuerCertInfoPtr,
876  IN_FLAGS( PRE_CHECK ) const int actions,
877  IN_FLAGS( PRE ) const int flags );
878 
879 #endif /* _CERTFN_DEFINED */