security/nss/lib/libpkix/include/pkix_checker.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 /*
michael@0 5 * This file defines functions associated with the PKIX_CertChainChecker type.
michael@0 6 *
michael@0 7 */
michael@0 8
michael@0 9 #ifndef _PKIX_CHECKER_H
michael@0 10 #define _PKIX_CHECKER_H
michael@0 11
michael@0 12 #include "pkixt.h"
michael@0 13
michael@0 14 #ifdef __cplusplus
michael@0 15 extern "C" {
michael@0 16 #endif
michael@0 17
michael@0 18 /* General
michael@0 19 *
michael@0 20 * Please refer to the libpkix Programmer's Guide for detailed information
michael@0 21 * about how to use the libpkix library. Certain key warnings and notices from
michael@0 22 * that document are repeated here for emphasis.
michael@0 23 *
michael@0 24 * All identifiers in this file (and all public identifiers defined in
michael@0 25 * libpkix) begin with "PKIX_". Private identifiers only intended for use
michael@0 26 * within the library begin with "pkix_".
michael@0 27 *
michael@0 28 * A function returns NULL upon success, and a PKIX_Error pointer upon failure.
michael@0 29 *
michael@0 30 * Unless otherwise noted, for all accessor (gettor) functions that return a
michael@0 31 * PKIX_PL_Object pointer, callers should assume that this pointer refers to a
michael@0 32 * shared object. Therefore, the caller should treat this shared object as
michael@0 33 * read-only and should not modify this shared object. When done using the
michael@0 34 * shared object, the caller should release the reference to the object by
michael@0 35 * using the PKIX_PL_Object_DecRef function.
michael@0 36 *
michael@0 37 * While a function is executing, if its arguments (or anything referred to by
michael@0 38 * its arguments) are modified, free'd, or destroyed, the function's behavior
michael@0 39 * is undefined.
michael@0 40 *
michael@0 41 */
michael@0 42
michael@0 43 /* PKIX_CertChainChecker
michael@0 44 *
michael@0 45 * PKIX_CertChainCheckers provide a standard way for the caller to insert their
michael@0 46 * own custom checks to validate certificates. This may be useful in many
michael@0 47 * scenarios, including when the caller wishes to validate private certificate
michael@0 48 * extensions. The CheckCallback allows custom certificate processing to take
michael@0 49 * place. Additionally, a CertChainChecker can optionally maintain state
michael@0 50 * between successive calls to the CheckCallback. This certChainCheckerState
michael@0 51 * must be an Object (although any object type), allowing it to be
michael@0 52 * reference-counted and allowing it to provide the standard Object functions
michael@0 53 * (Equals, Hashcode, ToString, Compare, Duplicate). If the caller wishes
michael@0 54 * their CertChainChecker to be used during chain building, their
michael@0 55 * certChainCheckerState object must implement an appropriate Duplicate
michael@0 56 * function. The builder uses this Duplicate function when backtracking.
michael@0 57 *
michael@0 58 * Once the caller has created a CertChainChecker object, the caller then
michael@0 59 * specifies a CertChainChecker object in a ProcessingParams object
michael@0 60 * and passes the ProcessingParams object to PKIX_ValidateChain or
michael@0 61 * PKIX_BuildChain, which uses the objects to call the user's callback
michael@0 62 * functions as needed during the validation or building process.
michael@0 63 *
michael@0 64 * A CertChainChecker may be presented certificates in the "reverse" direction
michael@0 65 * (from trust anchor to target) or in the "forward" direction (from target to
michael@0 66 * trust anchor). All CertChainCheckers must support "reverse checking", while
michael@0 67 * support for "forward checking" is optional, but recommended. If "forward
michael@0 68 * checking" is not supported, building chains may be much less efficient. The
michael@0 69 * PKIX_CertChainChecker_IsForwardCheckingSupported function is used to
michael@0 70 * determine whether forward checking is supported, and the
michael@0 71 * PKIX_CertChainChecker_IsForwardDirectionExpected function is used to
michael@0 72 * determine whether the CertChainChecker has been initialized to expect the
michael@0 73 * certificates to be presented in the "forward" direction.
michael@0 74 */
michael@0 75
michael@0 76 /*
michael@0 77 * FUNCTION: PKIX_CertChainChecker_CheckCallback
michael@0 78 * DESCRIPTION:
michael@0 79 *
michael@0 80 * This callback function checks whether the specified Cert pointed to by
michael@0 81 * "cert" is valid using "checker's" internal certChainCheckerState (if any)
michael@0 82 * and removes the critical extensions that it processes (if any) from the
michael@0 83 * List of OIDs (possibly empty) pointed to by "unresolvedCriticalExtensions".
michael@0 84 * If the checker finds that the certificate is not valid, an Error pointer is
michael@0 85 * returned.
michael@0 86 *
michael@0 87 * If the checker uses non-blocking I/O, the address of a platform-dependent
michael@0 88 * non-blocking I/O context ("nbioContext") will be stored at "pNBIOContext",
michael@0 89 * which the caller may use, in a platform-dependent way, to wait, poll, or
michael@0 90 * otherwise determine when to try again. If the checker does not use
michael@0 91 * non-blocking I/O, NULL will always be stored at "pNBIOContext". If a non-NULL
michael@0 92 * value was stored, on a subsequent call the checker will attempt to complete
michael@0 93 * the pending I/O and, if successful, NULL will be stored at "pNBIOContext".
michael@0 94 *
michael@0 95 * PARAMETERS:
michael@0 96 * "checker"
michael@0 97 * Address of CertChainChecker whose certChainCheckerState and
michael@0 98 * CheckCallback logic is to be used. Must be non-NULL.
michael@0 99 * "cert"
michael@0 100 * Address of Cert that is to be validated using "checker".
michael@0 101 * Must be non-NULL.
michael@0 102 * "unresolvedCriticalExtensions"
michael@0 103 * Address of List of OIDs that represents the critical certificate
michael@0 104 * extensions that have yet to be resolved. This parameter may be
michael@0 105 * modified during the function call. Must be non-NULL.
michael@0 106 * "pNBIOContext"
michael@0 107 * Address at which is stored a platform-dependent structure indicating
michael@0 108 * whether checking was suspended for non-blocking I/O. Must be non-NULL.
michael@0 109 * "plContext"
michael@0 110 * Platform-specific context pointer.
michael@0 111 * THREAD SAFETY:
michael@0 112 * Thread Safe
michael@0 113 *
michael@0 114 * Multiple threads must be able to safely call this function without
michael@0 115 * worrying about conflicts, even if they're operating on the same object.
michael@0 116 * RETURNS:
michael@0 117 * Returns NULL if the function succeeds.
michael@0 118 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 119 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 120 */
michael@0 121 typedef PKIX_Error *
michael@0 122 (*PKIX_CertChainChecker_CheckCallback)(
michael@0 123 PKIX_CertChainChecker *checker,
michael@0 124 PKIX_PL_Cert *cert,
michael@0 125 PKIX_List *unresolvedCriticalExtensions, /* list of PKIX_PL_OID */
michael@0 126 void **pNBIOContext,
michael@0 127 void *plContext);
michael@0 128
michael@0 129 /*
michael@0 130 * FUNCTION: PKIX_CertChainChecker_Create
michael@0 131 * DESCRIPTION:
michael@0 132 *
michael@0 133 * Creates a new CertChainChecker and stores it at "pChecker". The new
michael@0 134 * CertChainChecker uses the CheckCallback pointed to by "callback" as its
michael@0 135 * callback function. It uses the Object pointed to by "initialState" (if
michael@0 136 * any) as its initial state. As noted above, the initial state Object must
michael@0 137 * provide a custom implementation of PKIX_PL_Object_Duplicate if the
michael@0 138 * CertChainChecker is to be used during certificate chain building.
michael@0 139 *
michael@0 140 * A CertChainChecker may be presented certificates in the "reverse"
michael@0 141 * direction (from trust anchor to target) or in the "forward" direction
michael@0 142 * (from target to trust anchor). All CertChainCheckers must support
michael@0 143 * "reverse checking", while support for "forward checking" is optional. The
michael@0 144 * CertChainChecker is initialized with two Boolean flags that deal with this
michael@0 145 * distinction: "forwardCheckingSupported" and "forwardDirectionExpected".
michael@0 146 * If the "forwardCheckingSupported" Boolean flag is TRUE, it indicates that
michael@0 147 * this CertChainChecker is capable of checking certificates in the "forward"
michael@0 148 * direction (as well as the "reverse" direction, which all CertChainCheckers
michael@0 149 * MUST support). The "forwardDirectionExpected" Boolean flag indicates in
michael@0 150 * which direction the CertChainChecker should expect the certificates to be
michael@0 151 * presented. This is particularly useful for CertChainCheckers that are
michael@0 152 * capable of checking in either the "forward" direction or the "reverse"
michael@0 153 * direction, but have different processing steps depending on the direction.
michael@0 154 *
michael@0 155 * The CertChainChecker also uses the List of OIDs pointed to by "extensions"
michael@0 156 * as the supported certificate extensions. All certificate extensions that
michael@0 157 * the CertChainChecker might possibly recognize and be able to process
michael@0 158 * should be included in the List of supported extensions. If "checker" does
michael@0 159 * not recognize or process any certificate extensions, "extensions" should
michael@0 160 * be set to NULL.
michael@0 161 *
michael@0 162 * PARAMETERS:
michael@0 163 * "callback"
michael@0 164 * The CheckCallback function to be used. Must be non-NULL.
michael@0 165 * "forwardCheckingSupported"
michael@0 166 * A Boolean value indicating whether or not this CertChainChecker is
michael@0 167 * capable of checking certificates in the "forward" direction.
michael@0 168 * "forwardDirectionExpected"
michael@0 169 * A Boolean value indicating whether or not this CertChainChecker should
michael@0 170 * be used to check in the "forward" direction.
michael@0 171 * "extensions"
michael@0 172 * Address of List of OIDs representing the supported extensions.
michael@0 173 * "initialState"
michael@0 174 * Address of Object representing the CertChainChecker's initial state
michael@0 175 * (if any).
michael@0 176 * "pChecker"
michael@0 177 * Address where object pointer will be stored. Must be non-NULL.
michael@0 178 * "plContext"
michael@0 179 * Platform-specific context pointer.
michael@0 180 * THREAD SAFETY:
michael@0 181 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
michael@0 182 * RETURNS:
michael@0 183 * Returns NULL if the function succeeds.
michael@0 184 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 185 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 186 */
michael@0 187 PKIX_Error *
michael@0 188 PKIX_CertChainChecker_Create(
michael@0 189 PKIX_CertChainChecker_CheckCallback callback,
michael@0 190 PKIX_Boolean forwardCheckingSupported,
michael@0 191 PKIX_Boolean forwardDirectionExpected,
michael@0 192 PKIX_List *extensions, /* list of PKIX_PL_OID */
michael@0 193 PKIX_PL_Object *initialState,
michael@0 194 PKIX_CertChainChecker **pChecker,
michael@0 195 void *plContext);
michael@0 196
michael@0 197 /*
michael@0 198 * FUNCTION: PKIX_CertChainChecker_GetCheckCallback
michael@0 199 * DESCRIPTION:
michael@0 200 *
michael@0 201 * Retrieves a pointer to "checker's" Check callback function and puts it in
michael@0 202 * "pCallback".
michael@0 203 *
michael@0 204 * PARAMETERS:
michael@0 205 * "checker"
michael@0 206 * The CertChainChecker whose Check callback is desired. Must be non-NULL.
michael@0 207 * "pCallback"
michael@0 208 * Address where Check callback function pointer will be stored.
michael@0 209 * Must be non-NULL.
michael@0 210 * "plContext"
michael@0 211 * Platform-specific context pointer.
michael@0 212 * THREAD SAFETY:
michael@0 213 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
michael@0 214 * RETURNS:
michael@0 215 * Returns NULL if the function succeeds.
michael@0 216 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 217 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 218 */
michael@0 219 PKIX_Error *
michael@0 220 PKIX_CertChainChecker_GetCheckCallback(
michael@0 221 PKIX_CertChainChecker *checker,
michael@0 222 PKIX_CertChainChecker_CheckCallback *pCallback,
michael@0 223 void *plContext);
michael@0 224
michael@0 225 /*
michael@0 226 * FUNCTION: PKIX_CertChainChecker_IsForwardCheckingSupported
michael@0 227 * DESCRIPTION:
michael@0 228 *
michael@0 229 * Checks whether forward checking is supported by the CertChainChecker
michael@0 230 * pointed to by "checker" and stores the Boolean result at
michael@0 231 * "pForwardCheckingSupported".
michael@0 232 *
michael@0 233 * A CertChainChecker may be presented certificates in the "reverse"
michael@0 234 * direction (from trust anchor to target) or in the "forward" direction
michael@0 235 * (from target to trust anchor). All CertChainCheckers must support
michael@0 236 * "reverse checking", while support for "forward checking" is optional. This
michael@0 237 * function is used to determine whether forward checking is supported.
michael@0 238 *
michael@0 239 * PARAMETERS:
michael@0 240 * "checker"
michael@0 241 * The CertChainChecker whose ability to validate certificates in the
michael@0 242 * "forward" direction is to be checked. Must be non-NULL.
michael@0 243 * "pForwardCheckingSupported"
michael@0 244 * Destination of the Boolean result. Must be non-NULL.
michael@0 245 * "plContext"
michael@0 246 * Platform-specific context pointer.
michael@0 247 * THREAD SAFETY:
michael@0 248 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
michael@0 249 * RETURNS:
michael@0 250 * Returns NULL if the function succeeds.
michael@0 251 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 252 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 253 */
michael@0 254 PKIX_Error *
michael@0 255 PKIX_CertChainChecker_IsForwardCheckingSupported(
michael@0 256 PKIX_CertChainChecker *checker,
michael@0 257 PKIX_Boolean *pForwardCheckingSupported,
michael@0 258 void *plContext);
michael@0 259
michael@0 260 /*
michael@0 261 * FUNCTION: PKIX_CertChainChecker_IsForwardDirectionExpected
michael@0 262 * DESCRIPTION:
michael@0 263 *
michael@0 264 * Checks whether the CertChainChecker pointed to by "checker" has been
michael@0 265 * initialized to expect the certificates to be presented in the "forward"
michael@0 266 * direction and stores the Boolean result at "pForwardDirectionExpected".
michael@0 267 *
michael@0 268 * A CertChainChecker may be presented certificates in the "reverse"
michael@0 269 * direction (from trust anchor to target) or in the "forward" direction
michael@0 270 * (from target to trust anchor). All CertChainCheckers must support
michael@0 271 * "reverse checking", while support for "forward checking" is optional. This
michael@0 272 * function is used to determine in which direction the CertChainChecker
michael@0 273 * expects the certificates to be presented.
michael@0 274 *
michael@0 275 * PARAMETERS:
michael@0 276 * "checker"
michael@0 277 * The CertChainChecker that has been initialized to expect certificates
michael@0 278 * in either the "forward" or "reverse" directions. Must be non-NULL.
michael@0 279 * "pForwardDirectionExpected"
michael@0 280 * Destination of the Boolean result. Must be non-NULL.
michael@0 281 * "plContext"
michael@0 282 * Platform-specific context pointer.
michael@0 283 * THREAD SAFETY:
michael@0 284 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
michael@0 285 * RETURNS:
michael@0 286 * Returns NULL if the function succeeds.
michael@0 287 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 288 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 289 */
michael@0 290 PKIX_Error *
michael@0 291 PKIX_CertChainChecker_IsForwardDirectionExpected(
michael@0 292 PKIX_CertChainChecker *checker,
michael@0 293 PKIX_Boolean *pForwardDirectionExpected,
michael@0 294 void *plContext);
michael@0 295
michael@0 296 /*
michael@0 297 * FUNCTION: PKIX_CertChainChecker_GetSupportedExtensions
michael@0 298 * DESCRIPTION:
michael@0 299 *
michael@0 300 * Retrieves a pointer to a List of OIDs (each OID corresponding to a
michael@0 301 * certificate extension supported by the CertChainChecker pointed to by
michael@0 302 * "checker") and stores it at "pExtensions". All certificate extensions that
michael@0 303 * the CertChainChecker might possibly recognize and be able to process
michael@0 304 * should be included in the List of supported extensions. If "checker" does
michael@0 305 * not recognize or process any certificate extensions, this function stores
michael@0 306 * NULL at "pExtensions".
michael@0 307 *
michael@0 308 * Note that the List returned by this function is immutable.
michael@0 309 *
michael@0 310 * PARAMETERS:
michael@0 311 * "checker"
michael@0 312 * Address of CertChainChecker whose supported extension OIDs are to be
michael@0 313 * stored. Must be non-NULL.
michael@0 314 * "pExtensions"
michael@0 315 * Address where object pointer will be stored. Must be non-NULL.
michael@0 316 * "plContext"
michael@0 317 * Platform-specific context pointer.
michael@0 318 * THREAD SAFETY:
michael@0 319 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
michael@0 320 * RETURNS:
michael@0 321 * Returns NULL if the function succeeds.
michael@0 322 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 323 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 324 */
michael@0 325 PKIX_Error *
michael@0 326 PKIX_CertChainChecker_GetSupportedExtensions(
michael@0 327 PKIX_CertChainChecker *checker,
michael@0 328 PKIX_List **pExtensions, /* list of PKIX_PL_OID */
michael@0 329 void *plContext);
michael@0 330
michael@0 331 /*
michael@0 332 * FUNCTION: PKIX_CertChainChecker_GetCertChainCheckerState
michael@0 333 * DESCRIPTION:
michael@0 334 *
michael@0 335 * Retrieves a pointer to a PKIX_PL_Object representing the internal state
michael@0 336 * (if any) of the CertChainChecker pointed to by "checker" and stores it at
michael@0 337 * "pCertChainCheckerState".
michael@0 338 *
michael@0 339 * PARAMETERS:
michael@0 340 * "checker"
michael@0 341 * Address of CertChainChecker whose state is to be stored.
michael@0 342 * Must be non-NULL.
michael@0 343 * "pCertChainCheckerState"
michael@0 344 * Address where object pointer will be stored. Must be non-NULL.
michael@0 345 * "plContext"
michael@0 346 * Platform-specific context pointer.
michael@0 347 * THREAD SAFETY:
michael@0 348 * Conditionally Thread Safe
michael@0 349 * (see Thread Safety Definitions in Programmer's Guide)
michael@0 350 * RETURNS:
michael@0 351 * Returns NULL if the function succeeds.
michael@0 352 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 353 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 354 */
michael@0 355 PKIX_Error *
michael@0 356 PKIX_CertChainChecker_GetCertChainCheckerState(
michael@0 357 PKIX_CertChainChecker *checker,
michael@0 358 PKIX_PL_Object **pCertChainCheckerState,
michael@0 359 void *plContext);
michael@0 360
michael@0 361 /*
michael@0 362 * FUNCTION: PKIX_CertChainChecker_SetCertChainCheckerState
michael@0 363 * DESCRIPTION:
michael@0 364 *
michael@0 365 * Sets the internal state of the CertChainChecker pointed to by "checker"
michael@0 366 * using the Object pointed to by "certChainCheckerState". If "checker" needs
michael@0 367 * a NULL internal state, "certChainCheckerState" should be set to NULL.
michael@0 368 *
michael@0 369 * PARAMETERS:
michael@0 370 * "checker"
michael@0 371 * Address of CertChainChecker whose state is to be set. Must be non-NULL.
michael@0 372 * "certChainCheckerState"
michael@0 373 * Address of Object representing internal state.
michael@0 374 * "plContext"
michael@0 375 * Platform-specific context pointer.
michael@0 376 * THREAD SAFETY:
michael@0 377 * Not Thread Safe - assumes exclusive access to "checker"
michael@0 378 * (see Thread Safety Definitions in Programmer's Guide)
michael@0 379 * RETURNS:
michael@0 380 * Returns NULL if the function succeeds.
michael@0 381 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
michael@0 382 * Returns a Fatal Error if the function fails in an unrecoverable way.
michael@0 383 */
michael@0 384 PKIX_Error *
michael@0 385 PKIX_CertChainChecker_SetCertChainCheckerState(
michael@0 386 PKIX_CertChainChecker *checker,
michael@0 387 PKIX_PL_Object *certChainCheckerState,
michael@0 388 void *plContext);
michael@0 389
michael@0 390 #ifdef __cplusplus
michael@0 391 }
michael@0 392 #endif
michael@0 393
michael@0 394 #endif /* _PKIX_CHECKER_H */

mercurial