michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: /* michael@0: * This file defines functions associated with the PKIX_CertChainChecker type. michael@0: * michael@0: */ michael@0: michael@0: #ifndef _PKIX_CHECKER_H michael@0: #define _PKIX_CHECKER_H michael@0: michael@0: #include "pkixt.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: /* General michael@0: * michael@0: * Please refer to the libpkix Programmer's Guide for detailed information michael@0: * about how to use the libpkix library. Certain key warnings and notices from michael@0: * that document are repeated here for emphasis. michael@0: * michael@0: * All identifiers in this file (and all public identifiers defined in michael@0: * libpkix) begin with "PKIX_". Private identifiers only intended for use michael@0: * within the library begin with "pkix_". michael@0: * michael@0: * A function returns NULL upon success, and a PKIX_Error pointer upon failure. michael@0: * michael@0: * Unless otherwise noted, for all accessor (gettor) functions that return a michael@0: * PKIX_PL_Object pointer, callers should assume that this pointer refers to a michael@0: * shared object. Therefore, the caller should treat this shared object as michael@0: * read-only and should not modify this shared object. When done using the michael@0: * shared object, the caller should release the reference to the object by michael@0: * using the PKIX_PL_Object_DecRef function. michael@0: * michael@0: * While a function is executing, if its arguments (or anything referred to by michael@0: * its arguments) are modified, free'd, or destroyed, the function's behavior michael@0: * is undefined. michael@0: * michael@0: */ michael@0: michael@0: /* PKIX_CertChainChecker michael@0: * michael@0: * PKIX_CertChainCheckers provide a standard way for the caller to insert their michael@0: * own custom checks to validate certificates. This may be useful in many michael@0: * scenarios, including when the caller wishes to validate private certificate michael@0: * extensions. The CheckCallback allows custom certificate processing to take michael@0: * place. Additionally, a CertChainChecker can optionally maintain state michael@0: * between successive calls to the CheckCallback. This certChainCheckerState michael@0: * must be an Object (although any object type), allowing it to be michael@0: * reference-counted and allowing it to provide the standard Object functions michael@0: * (Equals, Hashcode, ToString, Compare, Duplicate). If the caller wishes michael@0: * their CertChainChecker to be used during chain building, their michael@0: * certChainCheckerState object must implement an appropriate Duplicate michael@0: * function. The builder uses this Duplicate function when backtracking. michael@0: * michael@0: * Once the caller has created a CertChainChecker object, the caller then michael@0: * specifies a CertChainChecker object in a ProcessingParams object michael@0: * and passes the ProcessingParams object to PKIX_ValidateChain or michael@0: * PKIX_BuildChain, which uses the objects to call the user's callback michael@0: * functions as needed during the validation or building process. michael@0: * michael@0: * A CertChainChecker may be presented certificates in the "reverse" direction michael@0: * (from trust anchor to target) or in the "forward" direction (from target to michael@0: * trust anchor). All CertChainCheckers must support "reverse checking", while michael@0: * support for "forward checking" is optional, but recommended. If "forward michael@0: * checking" is not supported, building chains may be much less efficient. The michael@0: * PKIX_CertChainChecker_IsForwardCheckingSupported function is used to michael@0: * determine whether forward checking is supported, and the michael@0: * PKIX_CertChainChecker_IsForwardDirectionExpected function is used to michael@0: * determine whether the CertChainChecker has been initialized to expect the michael@0: * certificates to be presented in the "forward" direction. michael@0: */ michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_CheckCallback michael@0: * DESCRIPTION: michael@0: * michael@0: * This callback function checks whether the specified Cert pointed to by michael@0: * "cert" is valid using "checker's" internal certChainCheckerState (if any) michael@0: * and removes the critical extensions that it processes (if any) from the michael@0: * List of OIDs (possibly empty) pointed to by "unresolvedCriticalExtensions". michael@0: * If the checker finds that the certificate is not valid, an Error pointer is michael@0: * returned. michael@0: * michael@0: * If the checker uses non-blocking I/O, the address of a platform-dependent michael@0: * non-blocking I/O context ("nbioContext") will be stored at "pNBIOContext", michael@0: * which the caller may use, in a platform-dependent way, to wait, poll, or michael@0: * otherwise determine when to try again. If the checker does not use michael@0: * non-blocking I/O, NULL will always be stored at "pNBIOContext". If a non-NULL michael@0: * value was stored, on a subsequent call the checker will attempt to complete michael@0: * the pending I/O and, if successful, NULL will be stored at "pNBIOContext". michael@0: * michael@0: * PARAMETERS: michael@0: * "checker" michael@0: * Address of CertChainChecker whose certChainCheckerState and michael@0: * CheckCallback logic is to be used. Must be non-NULL. michael@0: * "cert" michael@0: * Address of Cert that is to be validated using "checker". michael@0: * Must be non-NULL. michael@0: * "unresolvedCriticalExtensions" michael@0: * Address of List of OIDs that represents the critical certificate michael@0: * extensions that have yet to be resolved. This parameter may be michael@0: * modified during the function call. Must be non-NULL. michael@0: * "pNBIOContext" michael@0: * Address at which is stored a platform-dependent structure indicating michael@0: * whether checking was suspended for non-blocking I/O. Must be non-NULL. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Thread Safe michael@0: * michael@0: * Multiple threads must be able to safely call this function without michael@0: * worrying about conflicts, even if they're operating on the same object. michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: typedef PKIX_Error * michael@0: (*PKIX_CertChainChecker_CheckCallback)( michael@0: PKIX_CertChainChecker *checker, michael@0: PKIX_PL_Cert *cert, michael@0: PKIX_List *unresolvedCriticalExtensions, /* list of PKIX_PL_OID */ michael@0: void **pNBIOContext, michael@0: void *plContext); michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_Create michael@0: * DESCRIPTION: michael@0: * michael@0: * Creates a new CertChainChecker and stores it at "pChecker". The new michael@0: * CertChainChecker uses the CheckCallback pointed to by "callback" as its michael@0: * callback function. It uses the Object pointed to by "initialState" (if michael@0: * any) as its initial state. As noted above, the initial state Object must michael@0: * provide a custom implementation of PKIX_PL_Object_Duplicate if the michael@0: * CertChainChecker is to be used during certificate chain building. michael@0: * michael@0: * A CertChainChecker may be presented certificates in the "reverse" michael@0: * direction (from trust anchor to target) or in the "forward" direction michael@0: * (from target to trust anchor). All CertChainCheckers must support michael@0: * "reverse checking", while support for "forward checking" is optional. The michael@0: * CertChainChecker is initialized with two Boolean flags that deal with this michael@0: * distinction: "forwardCheckingSupported" and "forwardDirectionExpected". michael@0: * If the "forwardCheckingSupported" Boolean flag is TRUE, it indicates that michael@0: * this CertChainChecker is capable of checking certificates in the "forward" michael@0: * direction (as well as the "reverse" direction, which all CertChainCheckers michael@0: * MUST support). The "forwardDirectionExpected" Boolean flag indicates in michael@0: * which direction the CertChainChecker should expect the certificates to be michael@0: * presented. This is particularly useful for CertChainCheckers that are michael@0: * capable of checking in either the "forward" direction or the "reverse" michael@0: * direction, but have different processing steps depending on the direction. michael@0: * michael@0: * The CertChainChecker also uses the List of OIDs pointed to by "extensions" michael@0: * as the supported certificate extensions. All certificate extensions that michael@0: * the CertChainChecker might possibly recognize and be able to process michael@0: * should be included in the List of supported extensions. If "checker" does michael@0: * not recognize or process any certificate extensions, "extensions" should michael@0: * be set to NULL. michael@0: * michael@0: * PARAMETERS: michael@0: * "callback" michael@0: * The CheckCallback function to be used. Must be non-NULL. michael@0: * "forwardCheckingSupported" michael@0: * A Boolean value indicating whether or not this CertChainChecker is michael@0: * capable of checking certificates in the "forward" direction. michael@0: * "forwardDirectionExpected" michael@0: * A Boolean value indicating whether or not this CertChainChecker should michael@0: * be used to check in the "forward" direction. michael@0: * "extensions" michael@0: * Address of List of OIDs representing the supported extensions. michael@0: * "initialState" michael@0: * Address of Object representing the CertChainChecker's initial state michael@0: * (if any). michael@0: * "pChecker" michael@0: * Address where object pointer will be stored. Must be non-NULL. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertChainChecker_Create( michael@0: PKIX_CertChainChecker_CheckCallback callback, michael@0: PKIX_Boolean forwardCheckingSupported, michael@0: PKIX_Boolean forwardDirectionExpected, michael@0: PKIX_List *extensions, /* list of PKIX_PL_OID */ michael@0: PKIX_PL_Object *initialState, michael@0: PKIX_CertChainChecker **pChecker, michael@0: void *plContext); michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_GetCheckCallback michael@0: * DESCRIPTION: michael@0: * michael@0: * Retrieves a pointer to "checker's" Check callback function and puts it in michael@0: * "pCallback". michael@0: * michael@0: * PARAMETERS: michael@0: * "checker" michael@0: * The CertChainChecker whose Check callback is desired. Must be non-NULL. michael@0: * "pCallback" michael@0: * Address where Check callback function pointer will be stored. michael@0: * Must be non-NULL. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertChainChecker_GetCheckCallback( michael@0: PKIX_CertChainChecker *checker, michael@0: PKIX_CertChainChecker_CheckCallback *pCallback, michael@0: void *plContext); michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_IsForwardCheckingSupported michael@0: * DESCRIPTION: michael@0: * michael@0: * Checks whether forward checking is supported by the CertChainChecker michael@0: * pointed to by "checker" and stores the Boolean result at michael@0: * "pForwardCheckingSupported". michael@0: * michael@0: * A CertChainChecker may be presented certificates in the "reverse" michael@0: * direction (from trust anchor to target) or in the "forward" direction michael@0: * (from target to trust anchor). All CertChainCheckers must support michael@0: * "reverse checking", while support for "forward checking" is optional. This michael@0: * function is used to determine whether forward checking is supported. michael@0: * michael@0: * PARAMETERS: michael@0: * "checker" michael@0: * The CertChainChecker whose ability to validate certificates in the michael@0: * "forward" direction is to be checked. Must be non-NULL. michael@0: * "pForwardCheckingSupported" michael@0: * Destination of the Boolean result. Must be non-NULL. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertChainChecker_IsForwardCheckingSupported( michael@0: PKIX_CertChainChecker *checker, michael@0: PKIX_Boolean *pForwardCheckingSupported, michael@0: void *plContext); michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_IsForwardDirectionExpected michael@0: * DESCRIPTION: michael@0: * michael@0: * Checks whether the CertChainChecker pointed to by "checker" has been michael@0: * initialized to expect the certificates to be presented in the "forward" michael@0: * direction and stores the Boolean result at "pForwardDirectionExpected". michael@0: * michael@0: * A CertChainChecker may be presented certificates in the "reverse" michael@0: * direction (from trust anchor to target) or in the "forward" direction michael@0: * (from target to trust anchor). All CertChainCheckers must support michael@0: * "reverse checking", while support for "forward checking" is optional. This michael@0: * function is used to determine in which direction the CertChainChecker michael@0: * expects the certificates to be presented. michael@0: * michael@0: * PARAMETERS: michael@0: * "checker" michael@0: * The CertChainChecker that has been initialized to expect certificates michael@0: * in either the "forward" or "reverse" directions. Must be non-NULL. michael@0: * "pForwardDirectionExpected" michael@0: * Destination of the Boolean result. Must be non-NULL. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertChainChecker_IsForwardDirectionExpected( michael@0: PKIX_CertChainChecker *checker, michael@0: PKIX_Boolean *pForwardDirectionExpected, michael@0: void *plContext); michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_GetSupportedExtensions michael@0: * DESCRIPTION: michael@0: * michael@0: * Retrieves a pointer to a List of OIDs (each OID corresponding to a michael@0: * certificate extension supported by the CertChainChecker pointed to by michael@0: * "checker") and stores it at "pExtensions". All certificate extensions that michael@0: * the CertChainChecker might possibly recognize and be able to process michael@0: * should be included in the List of supported extensions. If "checker" does michael@0: * not recognize or process any certificate extensions, this function stores michael@0: * NULL at "pExtensions". michael@0: * michael@0: * Note that the List returned by this function is immutable. michael@0: * michael@0: * PARAMETERS: michael@0: * "checker" michael@0: * Address of CertChainChecker whose supported extension OIDs are to be michael@0: * stored. Must be non-NULL. michael@0: * "pExtensions" michael@0: * Address where object pointer will be stored. Must be non-NULL. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertChainChecker_GetSupportedExtensions( michael@0: PKIX_CertChainChecker *checker, michael@0: PKIX_List **pExtensions, /* list of PKIX_PL_OID */ michael@0: void *plContext); michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_GetCertChainCheckerState michael@0: * DESCRIPTION: michael@0: * michael@0: * Retrieves a pointer to a PKIX_PL_Object representing the internal state michael@0: * (if any) of the CertChainChecker pointed to by "checker" and stores it at michael@0: * "pCertChainCheckerState". michael@0: * michael@0: * PARAMETERS: michael@0: * "checker" michael@0: * Address of CertChainChecker whose state is to be stored. michael@0: * Must be non-NULL. michael@0: * "pCertChainCheckerState" michael@0: * Address where object pointer will be stored. Must be non-NULL. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Conditionally Thread Safe michael@0: * (see Thread Safety Definitions in Programmer's Guide) michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertChainChecker_GetCertChainCheckerState( michael@0: PKIX_CertChainChecker *checker, michael@0: PKIX_PL_Object **pCertChainCheckerState, michael@0: void *plContext); michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertChainChecker_SetCertChainCheckerState michael@0: * DESCRIPTION: michael@0: * michael@0: * Sets the internal state of the CertChainChecker pointed to by "checker" michael@0: * using the Object pointed to by "certChainCheckerState". If "checker" needs michael@0: * a NULL internal state, "certChainCheckerState" should be set to NULL. michael@0: * michael@0: * PARAMETERS: michael@0: * "checker" michael@0: * Address of CertChainChecker whose state is to be set. Must be non-NULL. michael@0: * "certChainCheckerState" michael@0: * Address of Object representing internal state. michael@0: * "plContext" michael@0: * Platform-specific context pointer. michael@0: * THREAD SAFETY: michael@0: * Not Thread Safe - assumes exclusive access to "checker" michael@0: * (see Thread Safety Definitions in Programmer's Guide) michael@0: * RETURNS: michael@0: * Returns NULL if the function succeeds. michael@0: * Returns a CertChainChecker Error if the function fails in a non-fatal way. michael@0: * Returns a Fatal Error if the function fails in an unrecoverable way. michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertChainChecker_SetCertChainCheckerState( michael@0: PKIX_CertChainChecker *checker, michael@0: PKIX_PL_Object *certChainCheckerState, michael@0: void *plContext); michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif /* _PKIX_CHECKER_H */