security/nss/lib/certhigh/ocsp.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
-rw-r--r--

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 /*
michael@0 6 * Interface to the OCSP implementation.
michael@0 7 */
michael@0 8
michael@0 9 #ifndef _OCSP_H_
michael@0 10 #define _OCSP_H_
michael@0 11
michael@0 12
michael@0 13 #include "plarena.h"
michael@0 14 #include "seccomon.h"
michael@0 15 #include "secoidt.h"
michael@0 16 #include "keyt.h"
michael@0 17 #include "certt.h"
michael@0 18 #include "ocspt.h"
michael@0 19
michael@0 20
michael@0 21 /************************************************************************/
michael@0 22 SEC_BEGIN_PROTOS
michael@0 23
michael@0 24 /*
michael@0 25 * This function registers the HttpClient with whose functions the
michael@0 26 * HttpClientFcn structure has been populated as the default Http
michael@0 27 * client.
michael@0 28 *
michael@0 29 * The function table must be a global object.
michael@0 30 * The caller must ensure that NSS will be able to call
michael@0 31 * the registered functions for the lifetime of the process.
michael@0 32 */
michael@0 33 extern SECStatus
michael@0 34 SEC_RegisterDefaultHttpClient(const SEC_HttpClientFcn *fcnTable);
michael@0 35
michael@0 36 /*
michael@0 37 * This function obtains the HttpClient which has been registered
michael@0 38 * by an earlier call to SEC_RegisterDefaultHttpClient.
michael@0 39 */
michael@0 40 extern const SEC_HttpClientFcn *
michael@0 41 SEC_GetRegisteredHttpClient(void);
michael@0 42
michael@0 43 /*
michael@0 44 * Sets parameters that control NSS' internal OCSP cache.
michael@0 45 * maxCacheEntries, special varlues are:
michael@0 46 * -1 disable cache
michael@0 47 * 0 unlimited cache entries
michael@0 48 * minimumSecondsToNextFetchAttempt:
michael@0 49 * whenever an OCSP request was attempted or completed over the network,
michael@0 50 * wait at least this number of seconds before trying to fetch again.
michael@0 51 * maximumSecondsToNextFetchAttempt:
michael@0 52 * this is the maximum age of a cached response we allow, until we try
michael@0 53 * to fetch an updated response, even if the OCSP responder expects
michael@0 54 * that newer information update will not be available yet.
michael@0 55 */
michael@0 56 extern SECStatus
michael@0 57 CERT_OCSPCacheSettings(PRInt32 maxCacheEntries,
michael@0 58 PRUint32 minimumSecondsToNextFetchAttempt,
michael@0 59 PRUint32 maximumSecondsToNextFetchAttempt);
michael@0 60
michael@0 61 /*
michael@0 62 * Set the desired behaviour on OCSP failures.
michael@0 63 * See definition of ocspFailureMode for allowed choices.
michael@0 64 */
michael@0 65 extern SECStatus
michael@0 66 CERT_SetOCSPFailureMode(SEC_OcspFailureMode ocspFailureMode);
michael@0 67
michael@0 68 /*
michael@0 69 * Configure the maximum time NSS will wait for an OCSP response.
michael@0 70 */
michael@0 71 extern SECStatus
michael@0 72 CERT_SetOCSPTimeout(PRUint32 seconds);
michael@0 73
michael@0 74 /*
michael@0 75 * Removes all items currently stored in the OCSP cache.
michael@0 76 */
michael@0 77 extern SECStatus
michael@0 78 CERT_ClearOCSPCache(void);
michael@0 79
michael@0 80 /*
michael@0 81 * FUNCTION: CERT_EnableOCSPChecking
michael@0 82 * Turns on OCSP checking for the given certificate database.
michael@0 83 * INPUTS:
michael@0 84 * CERTCertDBHandle *handle
michael@0 85 * Certificate database for which OCSP checking will be enabled.
michael@0 86 * RETURN:
michael@0 87 * Returns SECFailure if an error occurred (likely only problem
michael@0 88 * allocating memory); SECSuccess otherwise.
michael@0 89 */
michael@0 90 extern SECStatus
michael@0 91 CERT_EnableOCSPChecking(CERTCertDBHandle *handle);
michael@0 92
michael@0 93 /*
michael@0 94 * FUNCTION: CERT_DisableOCSPChecking
michael@0 95 * Turns off OCSP checking for the given certificate database.
michael@0 96 * This routine disables OCSP checking. Though it will return
michael@0 97 * SECFailure if OCSP checking is not enabled, it is "safe" to
michael@0 98 * call it that way and just ignore the return value, if it is
michael@0 99 * easier to just call it than to "remember" whether it is enabled.
michael@0 100 * INPUTS:
michael@0 101 * CERTCertDBHandle *handle
michael@0 102 * Certificate database for which OCSP checking will be disabled.
michael@0 103 * RETURN:
michael@0 104 * Returns SECFailure if an error occurred (usually means that OCSP
michael@0 105 * checking was not enabled or status contexts were not initialized --
michael@0 106 * error set will be SEC_ERROR_OCSP_NOT_ENABLED); SECSuccess otherwise.
michael@0 107 */
michael@0 108 extern SECStatus
michael@0 109 CERT_DisableOCSPChecking(CERTCertDBHandle *handle);
michael@0 110
michael@0 111 /*
michael@0 112 * FUNCTION: CERT_SetOCSPDefaultResponder
michael@0 113 * Specify the location and cert of the default responder.
michael@0 114 * If OCSP checking is already enabled *and* use of a default responder
michael@0 115 * is also already enabled, all OCSP checking from now on will go directly
michael@0 116 * to the specified responder. If OCSP checking is not enabled, or if
michael@0 117 * it is but use of a default responder is not enabled, the information
michael@0 118 * will be recorded and take effect whenever both are enabled.
michael@0 119 * INPUTS:
michael@0 120 * CERTCertDBHandle *handle
michael@0 121 * Cert database on which OCSP checking should use the default responder.
michael@0 122 * const char *url
michael@0 123 * The location of the default responder (e.g. "http://foo.com:80/ocsp")
michael@0 124 * Note that the location will not be tested until the first attempt
michael@0 125 * to send a request there.
michael@0 126 * const char *name
michael@0 127 * The nickname of the cert to trust (expected) to sign the OCSP responses.
michael@0 128 * If the corresponding cert cannot be found, SECFailure is returned.
michael@0 129 * RETURN:
michael@0 130 * Returns SECFailure if an error occurred; SECSuccess otherwise.
michael@0 131 * The most likely error is that the cert for "name" could not be found
michael@0 132 * (probably SEC_ERROR_UNKNOWN_CERT). Other errors are low-level (no memory,
michael@0 133 * bad database, etc.).
michael@0 134 */
michael@0 135 extern SECStatus
michael@0 136 CERT_SetOCSPDefaultResponder(CERTCertDBHandle *handle,
michael@0 137 const char *url, const char *name);
michael@0 138
michael@0 139 /*
michael@0 140 * FUNCTION: CERT_EnableOCSPDefaultResponder
michael@0 141 * Turns on use of a default responder when OCSP checking.
michael@0 142 * If OCSP checking is already enabled, this will make subsequent checks
michael@0 143 * go directly to the default responder. (The location of the responder
michael@0 144 * and the nickname of the responder cert must already be specified.)
michael@0 145 * If OCSP checking is not enabled, this will be recorded and take effect
michael@0 146 * whenever it is enabled.
michael@0 147 * INPUTS:
michael@0 148 * CERTCertDBHandle *handle
michael@0 149 * Cert database on which OCSP checking should use the default responder.
michael@0 150 * RETURN:
michael@0 151 * Returns SECFailure if an error occurred; SECSuccess otherwise.
michael@0 152 * No errors are especially likely unless the caller did not previously
michael@0 153 * perform a successful call to SetOCSPDefaultResponder (in which case
michael@0 154 * the error set will be SEC_ERROR_OCSP_NO_DEFAULT_RESPONDER).
michael@0 155 */
michael@0 156 extern SECStatus
michael@0 157 CERT_EnableOCSPDefaultResponder(CERTCertDBHandle *handle);
michael@0 158
michael@0 159 /*
michael@0 160 * FUNCTION: CERT_DisableOCSPDefaultResponder
michael@0 161 * Turns off use of a default responder when OCSP checking.
michael@0 162 * (Does nothing if use of a default responder is not enabled.)
michael@0 163 * INPUTS:
michael@0 164 * CERTCertDBHandle *handle
michael@0 165 * Cert database on which OCSP checking should stop using a default
michael@0 166 * responder.
michael@0 167 * RETURN:
michael@0 168 * Returns SECFailure if an error occurred; SECSuccess otherwise.
michael@0 169 * Errors very unlikely (like random memory corruption...).
michael@0 170 */
michael@0 171 extern SECStatus
michael@0 172 CERT_DisableOCSPDefaultResponder(CERTCertDBHandle *handle);
michael@0 173
michael@0 174 /* If forcePost is set, OCSP requests will only be sent using the HTTP POST
michael@0 175 * method. When forcePost is not set, OCSP requests will be sent using the
michael@0 176 * HTTP GET method, with a fallback to POST when we fail to receive a response
michael@0 177 * and/or when we receive an uncacheable response like "Unknown."
michael@0 178 *
michael@0 179 * The default is to use GET and fallback to POST.
michael@0 180 */
michael@0 181 extern SECStatus CERT_ForcePostMethodForOCSP(PRBool forcePost);
michael@0 182
michael@0 183 /*
michael@0 184 * -------------------------------------------------------
michael@0 185 * The Functions above are those expected to be used by a client
michael@0 186 * providing OCSP status checking along with every cert verification.
michael@0 187 * The functions below are for OCSP testing, debugging, or clients
michael@0 188 * or servers performing more specialized OCSP tasks.
michael@0 189 * -------------------------------------------------------
michael@0 190 */
michael@0 191
michael@0 192 /*
michael@0 193 * FUNCTION: CERT_CreateOCSPRequest
michael@0 194 * Creates a CERTOCSPRequest, requesting the status of the certs in
michael@0 195 * the given list.
michael@0 196 * INPUTS:
michael@0 197 * CERTCertList *certList
michael@0 198 * A list of certs for which status will be requested.
michael@0 199 * Note that all of these certificates should have the same issuer,
michael@0 200 * or it's expected the response will be signed by a trusted responder.
michael@0 201 * If the certs need to be broken up into multiple requests, that
michael@0 202 * must be handled by the caller (and thus by having multiple calls
michael@0 203 * to this routine), who knows about where the request(s) are being
michael@0 204 * sent and whether there are any trusted responders in place.
michael@0 205 * PRTime time
michael@0 206 * Indicates the time for which the certificate status is to be
michael@0 207 * determined -- this may be used in the search for the cert's issuer
michael@0 208 * but has no effect on the request itself.
michael@0 209 * PRBool addServiceLocator
michael@0 210 * If true, the Service Locator extension should be added to the
michael@0 211 * single request(s) for each cert.
michael@0 212 * CERTCertificate *signerCert
michael@0 213 * If non-NULL, means sign the request using this cert. Otherwise,
michael@0 214 * do not sign.
michael@0 215 * XXX note that request signing is not yet supported; see comment in code
michael@0 216 * RETURN:
michael@0 217 * A pointer to a CERTOCSPRequest structure containing an OCSP request
michael@0 218 * for the cert list. On error, null is returned, with an error set
michael@0 219 * indicating the reason. This is likely SEC_ERROR_UNKNOWN_ISSUER.
michael@0 220 * (The issuer is needed to create a request for the certificate.)
michael@0 221 * Other errors are low-level problems (no memory, bad database, etc.).
michael@0 222 */
michael@0 223 extern CERTOCSPRequest *
michael@0 224 CERT_CreateOCSPRequest(CERTCertList *certList, PRTime time,
michael@0 225 PRBool addServiceLocator,
michael@0 226 CERTCertificate *signerCert);
michael@0 227
michael@0 228 /*
michael@0 229 * FUNCTION: CERT_AddOCSPAcceptableResponses
michael@0 230 * Add the AcceptableResponses extension to an OCSP Request.
michael@0 231 * INPUTS:
michael@0 232 * CERTOCSPRequest *request
michael@0 233 * The request to which the extension should be added.
michael@0 234 * SECOidTag responseType0, ...
michael@0 235 * A list (of one or more) of SECOidTag -- each of the response types
michael@0 236 * to be added. The last OID *must* be SEC_OID_PKIX_OCSP_BASIC_RESPONSE.
michael@0 237 * (This marks the end of the list, and it must be specified because a
michael@0 238 * client conforming to the OCSP standard is required to handle the basic
michael@0 239 * response type.) The OIDs are not checked in any way.
michael@0 240 * RETURN:
michael@0 241 * SECSuccess if the extension is added; SECFailure if anything goes wrong.
michael@0 242 * All errors are internal or low-level problems (e.g. no memory).
michael@0 243 */
michael@0 244 extern SECStatus
michael@0 245 CERT_AddOCSPAcceptableResponses(CERTOCSPRequest *request,
michael@0 246 SECOidTag responseType0, ...);
michael@0 247
michael@0 248 /*
michael@0 249 * FUNCTION: CERT_EncodeOCSPRequest
michael@0 250 * DER encodes an OCSP Request, possibly adding a signature as well.
michael@0 251 * XXX Signing is not yet supported, however; see comments in code.
michael@0 252 * INPUTS:
michael@0 253 * PLArenaPool *arena
michael@0 254 * The return value is allocated from here.
michael@0 255 * If a NULL is passed in, allocation is done from the heap instead.
michael@0 256 * CERTOCSPRequest *request
michael@0 257 * The request to be encoded.
michael@0 258 * void *pwArg
michael@0 259 * Pointer to argument for password prompting, if needed. (Definitely
michael@0 260 * not needed if not signing.)
michael@0 261 * RETURN:
michael@0 262 * Returns a NULL on error and a pointer to the SECItem with the
michael@0 263 * encoded value otherwise. Any error is likely to be low-level
michael@0 264 * (e.g. no memory).
michael@0 265 */
michael@0 266 extern SECItem *
michael@0 267 CERT_EncodeOCSPRequest(PLArenaPool *arena, CERTOCSPRequest *request,
michael@0 268 void *pwArg);
michael@0 269
michael@0 270 /*
michael@0 271 * FUNCTION: CERT_DecodeOCSPRequest
michael@0 272 * Decode a DER encoded OCSP Request.
michael@0 273 * INPUTS:
michael@0 274 * SECItem *src
michael@0 275 * Pointer to a SECItem holding DER encoded OCSP Request.
michael@0 276 * RETURN:
michael@0 277 * Returns a pointer to a CERTOCSPRequest containing the decoded request.
michael@0 278 * On error, returns NULL. Most likely error is trouble decoding
michael@0 279 * (SEC_ERROR_OCSP_MALFORMED_REQUEST), or low-level problem (no memory).
michael@0 280 */
michael@0 281 extern CERTOCSPRequest *
michael@0 282 CERT_DecodeOCSPRequest(const SECItem *src);
michael@0 283
michael@0 284 /*
michael@0 285 * FUNCTION: CERT_DestroyOCSPRequest
michael@0 286 * Frees an OCSP Request structure.
michael@0 287 * INPUTS:
michael@0 288 * CERTOCSPRequest *request
michael@0 289 * Pointer to CERTOCSPRequest to be freed.
michael@0 290 * RETURN:
michael@0 291 * No return value; no errors.
michael@0 292 */
michael@0 293 extern void
michael@0 294 CERT_DestroyOCSPRequest(CERTOCSPRequest *request);
michael@0 295
michael@0 296 /*
michael@0 297 * FUNCTION: CERT_DecodeOCSPResponse
michael@0 298 * Decode a DER encoded OCSP Response.
michael@0 299 * INPUTS:
michael@0 300 * SECItem *src
michael@0 301 * Pointer to a SECItem holding DER encoded OCSP Response.
michael@0 302 * RETURN:
michael@0 303 * Returns a pointer to a CERTOCSPResponse (the decoded OCSP Response);
michael@0 304 * the caller is responsible for destroying it. Or NULL if error (either
michael@0 305 * response could not be decoded (SEC_ERROR_OCSP_MALFORMED_RESPONSE),
michael@0 306 * it was of an unexpected type (SEC_ERROR_OCSP_UNKNOWN_RESPONSE_TYPE),
michael@0 307 * or a low-level or internal error occurred).
michael@0 308 */
michael@0 309 extern CERTOCSPResponse *
michael@0 310 CERT_DecodeOCSPResponse(const SECItem *src);
michael@0 311
michael@0 312 /*
michael@0 313 * FUNCTION: CERT_DestroyOCSPResponse
michael@0 314 * Frees an OCSP Response structure.
michael@0 315 * INPUTS:
michael@0 316 * CERTOCSPResponse *request
michael@0 317 * Pointer to CERTOCSPResponse to be freed.
michael@0 318 * RETURN:
michael@0 319 * No return value; no errors.
michael@0 320 */
michael@0 321 extern void
michael@0 322 CERT_DestroyOCSPResponse(CERTOCSPResponse *response);
michael@0 323
michael@0 324 /*
michael@0 325 * FUNCTION: CERT_GetEncodedOCSPResponse
michael@0 326 * Creates and sends a request to an OCSP responder, then reads and
michael@0 327 * returns the (encoded) response.
michael@0 328 * INPUTS:
michael@0 329 * PLArenaPool *arena
michael@0 330 * Pointer to arena from which return value will be allocated.
michael@0 331 * If NULL, result will be allocated from the heap (and thus should
michael@0 332 * be freed via SECITEM_FreeItem).
michael@0 333 * CERTCertList *certList
michael@0 334 * A list of certs for which status will be requested.
michael@0 335 * Note that all of these certificates should have the same issuer,
michael@0 336 * or it's expected the response will be signed by a trusted responder.
michael@0 337 * If the certs need to be broken up into multiple requests, that
michael@0 338 * must be handled by the caller (and thus by having multiple calls
michael@0 339 * to this routine), who knows about where the request(s) are being
michael@0 340 * sent and whether there are any trusted responders in place.
michael@0 341 * const char *location
michael@0 342 * The location of the OCSP responder (a URL).
michael@0 343 * PRTime time
michael@0 344 * Indicates the time for which the certificate status is to be
michael@0 345 * determined -- this may be used in the search for the cert's issuer
michael@0 346 * but has no other bearing on the operation.
michael@0 347 * PRBool addServiceLocator
michael@0 348 * If true, the Service Locator extension should be added to the
michael@0 349 * single request(s) for each cert.
michael@0 350 * CERTCertificate *signerCert
michael@0 351 * If non-NULL, means sign the request using this cert. Otherwise,
michael@0 352 * do not sign.
michael@0 353 * void *pwArg
michael@0 354 * Pointer to argument for password prompting, if needed. (Definitely
michael@0 355 * not needed if not signing.)
michael@0 356 * OUTPUTS:
michael@0 357 * CERTOCSPRequest **pRequest
michael@0 358 * Pointer in which to store the OCSP request created for the given
michael@0 359 * list of certificates. It is only filled in if the entire operation
michael@0 360 * is successful and the pointer is not null -- and in that case the
michael@0 361 * caller is then reponsible for destroying it.
michael@0 362 * RETURN:
michael@0 363 * Returns a pointer to the SECItem holding the response.
michael@0 364 * On error, returns null with error set describing the reason:
michael@0 365 * SEC_ERROR_UNKNOWN_ISSUER
michael@0 366 * SEC_ERROR_CERT_BAD_ACCESS_LOCATION
michael@0 367 * SEC_ERROR_OCSP_BAD_HTTP_RESPONSE
michael@0 368 * Other errors are low-level problems (no memory, bad database, etc.).
michael@0 369 */
michael@0 370 extern SECItem *
michael@0 371 CERT_GetEncodedOCSPResponse(PLArenaPool *arena, CERTCertList *certList,
michael@0 372 const char *location, PRTime time,
michael@0 373 PRBool addServiceLocator,
michael@0 374 CERTCertificate *signerCert, void *pwArg,
michael@0 375 CERTOCSPRequest **pRequest);
michael@0 376
michael@0 377 /*
michael@0 378 * FUNCTION: CERT_VerifyOCSPResponseSignature
michael@0 379 * Check the signature on an OCSP Response. Will also perform a
michael@0 380 * verification of the signer's certificate. Note, however, that a
michael@0 381 * successful verification does not make any statement about the
michael@0 382 * signer's *authority* to provide status for the certificate(s),
michael@0 383 * that must be checked individually for each certificate.
michael@0 384 * INPUTS:
michael@0 385 * CERTOCSPResponse *response
michael@0 386 * Pointer to response structure with signature to be checked.
michael@0 387 * CERTCertDBHandle *handle
michael@0 388 * Pointer to CERTCertDBHandle for certificate DB to use for verification.
michael@0 389 * void *pwArg
michael@0 390 * Pointer to argument for password prompting, if needed.
michael@0 391 * CERTCertificate *issuerCert
michael@0 392 * Issuer of the certificate that generated the OCSP request.
michael@0 393 * OUTPUTS:
michael@0 394 * CERTCertificate **pSignerCert
michael@0 395 * Pointer in which to store signer's certificate; only filled-in if
michael@0 396 * non-null.
michael@0 397 * RETURN:
michael@0 398 * Returns SECSuccess when signature is valid, anything else means invalid.
michael@0 399 * Possible errors set:
michael@0 400 * SEC_ERROR_OCSP_MALFORMED_RESPONSE - unknown type of ResponderID
michael@0 401 * SEC_ERROR_INVALID_TIME - bad format of "ProducedAt" time
michael@0 402 * SEC_ERROR_UNKNOWN_SIGNER - signer's cert could not be found
michael@0 403 * SEC_ERROR_BAD_SIGNATURE - the signature did not verify
michael@0 404 * Other errors are any of the many possible failures in cert verification
michael@0 405 * (e.g. SEC_ERROR_REVOKED_CERTIFICATE, SEC_ERROR_UNTRUSTED_ISSUER) when
michael@0 406 * verifying the signer's cert, or low-level problems (no memory, etc.)
michael@0 407 */
michael@0 408 extern SECStatus
michael@0 409 CERT_VerifyOCSPResponseSignature(CERTOCSPResponse *response,
michael@0 410 CERTCertDBHandle *handle, void *pwArg,
michael@0 411 CERTCertificate **pSignerCert,
michael@0 412 CERTCertificate *issuerCert);
michael@0 413
michael@0 414 /*
michael@0 415 * FUNCTION: CERT_GetOCSPAuthorityInfoAccessLocation
michael@0 416 * Get the value of the URI of the OCSP responder for the given cert.
michael@0 417 * This is found in the (optional) Authority Information Access extension
michael@0 418 * in the cert.
michael@0 419 * INPUTS:
michael@0 420 * CERTCertificate *cert
michael@0 421 * The certificate being examined.
michael@0 422 * RETURN:
michael@0 423 * char *
michael@0 424 * A copy of the URI for the OCSP method, if found. If either the
michael@0 425 * extension is not present or it does not contain an entry for OCSP,
michael@0 426 * SEC_ERROR_EXTENSION_NOT_FOUND will be set and a NULL returned.
michael@0 427 * Any other error will also result in a NULL being returned.
michael@0 428 *
michael@0 429 * This result should be freed (via PORT_Free) when no longer in use.
michael@0 430 */
michael@0 431 extern char *
michael@0 432 CERT_GetOCSPAuthorityInfoAccessLocation(const CERTCertificate *cert);
michael@0 433
michael@0 434 /*
michael@0 435 * FUNCTION: CERT_RegisterAlternateOCSPAIAInfoCallBack
michael@0 436 * This function serves two purposes.
michael@0 437 * 1) It registers the address of a callback function that will be
michael@0 438 * called for certs that have no OCSP AIA extension, to see if the
michael@0 439 * callback wishes to supply an alternative URL for such an OCSP inquiry.
michael@0 440 * 2) It outputs the previously registered function's address to the
michael@0 441 * address supplied by the caller, unless that is NULL.
michael@0 442 * The registered callback function returns NULL, or an allocated string
michael@0 443 * that may be subsequently freed by calling PORT_Free().
michael@0 444 * RETURN:
michael@0 445 * SECSuccess or SECFailure (if the library is not yet intialized)
michael@0 446 */
michael@0 447 extern SECStatus
michael@0 448 CERT_RegisterAlternateOCSPAIAInfoCallBack(
michael@0 449 CERT_StringFromCertFcn newCallback,
michael@0 450 CERT_StringFromCertFcn * oldCallback);
michael@0 451
michael@0 452 /*
michael@0 453 * FUNCTION: CERT_ParseURL
michael@0 454 * Parse a URI into hostname, port, and path. The scheme in the URI must
michael@0 455 * be "http".
michael@0 456 * INPUTS:
michael@0 457 * const char *url
michael@0 458 * The URI to be parsed
michael@0 459 * OUTPUTS:
michael@0 460 * char **pHostname
michael@0 461 * Pointer to store the hostname obtained from the URI.
michael@0 462 * This result should be freed (via PORT_Free) when no longer in use.
michael@0 463 * PRUint16 *pPort
michael@0 464 * Pointer to store the port number obtained from the URI.
michael@0 465 * char **pPath
michael@0 466 * Pointer to store the path obtained from the URI.
michael@0 467 * This result should be freed (via PORT_Free) when no longer in use.
michael@0 468 * RETURN:
michael@0 469 * Returns SECSuccess when parsing was successful. Returns SECFailure when
michael@0 470 * problems were encountered.
michael@0 471 */
michael@0 472 extern SECStatus
michael@0 473 CERT_ParseURL(const char *url, char **pHostname, PRUint16 *pPort, char **pPath);
michael@0 474
michael@0 475 /*
michael@0 476 * FUNCTION: CERT_CheckOCSPStatus
michael@0 477 * Checks the status of a certificate via OCSP. Will only check status for
michael@0 478 * a certificate that has an AIA (Authority Information Access) extension
michael@0 479 * for OCSP *or* when a "default responder" is specified and enabled.
michael@0 480 * (If no AIA extension for OCSP and no default responder in place, the
michael@0 481 * cert is considered to have a good status and SECSuccess is returned.)
michael@0 482 * INPUTS:
michael@0 483 * CERTCertDBHandle *handle
michael@0 484 * certificate DB of the cert that is being checked
michael@0 485 * CERTCertificate *cert
michael@0 486 * the certificate being checked
michael@0 487 * XXX in the long term also need a boolean parameter that specifies
michael@0 488 * whether to check the cert chain, as well; for now we check only
michael@0 489 * the leaf (the specified certificate)
michael@0 490 * PRTime time
michael@0 491 * time for which status is to be determined
michael@0 492 * void *pwArg
michael@0 493 * argument for password prompting, if needed
michael@0 494 * RETURN:
michael@0 495 * Returns SECSuccess if an approved OCSP responder "knows" the cert
michael@0 496 * *and* returns a non-revoked status for it; SECFailure otherwise,
michael@0 497 * with an error set describing the reason:
michael@0 498 *
michael@0 499 * SEC_ERROR_OCSP_BAD_HTTP_RESPONSE
michael@0 500 * SEC_ERROR_OCSP_FUTURE_RESPONSE
michael@0 501 * SEC_ERROR_OCSP_MALFORMED_REQUEST
michael@0 502 * SEC_ERROR_OCSP_MALFORMED_RESPONSE
michael@0 503 * SEC_ERROR_OCSP_OLD_RESPONSE
michael@0 504 * SEC_ERROR_OCSP_REQUEST_NEEDS_SIG
michael@0 505 * SEC_ERROR_OCSP_SERVER_ERROR
michael@0 506 * SEC_ERROR_OCSP_TRY_SERVER_LATER
michael@0 507 * SEC_ERROR_OCSP_UNAUTHORIZED_REQUEST
michael@0 508 * SEC_ERROR_OCSP_UNAUTHORIZED_RESPONSE
michael@0 509 * SEC_ERROR_OCSP_UNKNOWN_CERT
michael@0 510 * SEC_ERROR_OCSP_UNKNOWN_RESPONSE_STATUS
michael@0 511 * SEC_ERROR_OCSP_UNKNOWN_RESPONSE_TYPE
michael@0 512 *
michael@0 513 * SEC_ERROR_BAD_SIGNATURE
michael@0 514 * SEC_ERROR_CERT_BAD_ACCESS_LOCATION
michael@0 515 * SEC_ERROR_INVALID_TIME
michael@0 516 * SEC_ERROR_REVOKED_CERTIFICATE
michael@0 517 * SEC_ERROR_UNKNOWN_ISSUER
michael@0 518 * SEC_ERROR_UNKNOWN_SIGNER
michael@0 519 *
michael@0 520 * Other errors are any of the many possible failures in cert verification
michael@0 521 * (e.g. SEC_ERROR_REVOKED_CERTIFICATE, SEC_ERROR_UNTRUSTED_ISSUER) when
michael@0 522 * verifying the signer's cert, or low-level problems (error allocating
michael@0 523 * memory, error performing ASN.1 decoding, etc.).
michael@0 524 */
michael@0 525 extern SECStatus
michael@0 526 CERT_CheckOCSPStatus(CERTCertDBHandle *handle, CERTCertificate *cert,
michael@0 527 PRTime time, void *pwArg);
michael@0 528
michael@0 529 /*
michael@0 530 * FUNCTION: CERT_CacheOCSPResponseFromSideChannel
michael@0 531 * First, this function checks the OCSP cache to see if a good response
michael@0 532 * for the given certificate already exists. If it does, then the function
michael@0 533 * returns successfully.
michael@0 534 *
michael@0 535 * If not, then it validates that the given OCSP response is a valid,
michael@0 536 * good response for the given certificate and inserts it into the
michael@0 537 * cache.
michael@0 538 *
michael@0 539 * This function is intended for use when OCSP responses are provided via a
michael@0 540 * side-channel, i.e. TLS OCSP stapling (a.k.a. the status_request extension).
michael@0 541 *
michael@0 542 * INPUTS:
michael@0 543 * CERTCertDBHandle *handle
michael@0 544 * certificate DB of the cert that is being checked
michael@0 545 * CERTCertificate *cert
michael@0 546 * the certificate being checked
michael@0 547 * PRTime time
michael@0 548 * time for which status is to be determined
michael@0 549 * SECItem *encodedResponse
michael@0 550 * the DER encoded bytes of the OCSP response
michael@0 551 * void *pwArg
michael@0 552 * argument for password prompting, if needed
michael@0 553 * RETURN:
michael@0 554 * SECSuccess if the cert was found in the cache, or if the OCSP response was
michael@0 555 * found to be valid and inserted into the cache. SECFailure otherwise.
michael@0 556 */
michael@0 557 extern SECStatus
michael@0 558 CERT_CacheOCSPResponseFromSideChannel(CERTCertDBHandle *handle,
michael@0 559 CERTCertificate *cert,
michael@0 560 PRTime time,
michael@0 561 const SECItem *encodedResponse,
michael@0 562 void *pwArg);
michael@0 563
michael@0 564 /*
michael@0 565 * FUNCTION: CERT_GetOCSPStatusForCertID
michael@0 566 * Returns the OCSP status contained in the passed in parameter response
michael@0 567 * that corresponds to the certID passed in.
michael@0 568 * INPUTS:
michael@0 569 * CERTCertDBHandle *handle
michael@0 570 * certificate DB of the cert that is being checked
michael@0 571 * CERTOCSPResponse *response
michael@0 572 * the OCSP response we want to retrieve status from.
michael@0 573 * CERTOCSPCertID *certID
michael@0 574 * the ID we want to look for from the response.
michael@0 575 * CERTCertificate *signerCert
michael@0 576 * the certificate that was used to sign the OCSP response.
michael@0 577 * must be obtained via a call to CERT_VerifyOCSPResponseSignature.
michael@0 578 * PRTime time
michael@0 579 * The time at which we're checking the status for.
michael@0 580 * RETURN:
michael@0 581 * Return values are the same as those for CERT_CheckOCSPStatus
michael@0 582 */
michael@0 583 extern SECStatus
michael@0 584 CERT_GetOCSPStatusForCertID(CERTCertDBHandle *handle,
michael@0 585 CERTOCSPResponse *response,
michael@0 586 CERTOCSPCertID *certID,
michael@0 587 CERTCertificate *signerCert,
michael@0 588 PRTime time);
michael@0 589
michael@0 590 /*
michael@0 591 * FUNCTION CERT_GetOCSPResponseStatus
michael@0 592 * Returns the response status for the response passed.
michael@0 593 * INPUTS:
michael@0 594 * CERTOCSPResponse *response
michael@0 595 * The response to query for status
michael@0 596 * RETURN:
michael@0 597 * Returns SECSuccess if the response has a successful status value.
michael@0 598 * Otherwise it returns SECFailure and sets one of the following error
michael@0 599 * codes via PORT_SetError
michael@0 600 * SEC_ERROR_OCSP_MALFORMED_REQUEST
michael@0 601 * SEC_ERROR_OCSP_SERVER_ERROR
michael@0 602 * SEC_ERROR_OCSP_TRY_SERVER_LATER
michael@0 603 * SEC_ERROR_OCSP_REQUEST_NEEDS_SIG
michael@0 604 * SEC_ERROR_OCSP_UNAUTHORIZED_REQUEST
michael@0 605 * SEC_ERROR_OCSP_UNKNOWN_RESPONSE_STATUS
michael@0 606 */
michael@0 607 extern SECStatus
michael@0 608 CERT_GetOCSPResponseStatus(CERTOCSPResponse *response);
michael@0 609
michael@0 610 /*
michael@0 611 * FUNCTION CERT_CreateOCSPCertID
michael@0 612 * Returns the OCSP certID for the certificate passed in.
michael@0 613 * INPUTS:
michael@0 614 * CERTCertificate *cert
michael@0 615 * The certificate for which to create the certID for.
michael@0 616 * PRTime time
michael@0 617 * The time at which the id is requested for. This is used
michael@0 618 * to determine the appropriate issuer for the cert since
michael@0 619 * the issuing CA may be an older expired certificate.
michael@0 620 * RETURN:
michael@0 621 * A new copy of a CERTOCSPCertID*. The memory for this certID
michael@0 622 * should be freed by calling CERT_DestroyOCSPCertID when the
michael@0 623 * certID is no longer necessary.
michael@0 624 */
michael@0 625 extern CERTOCSPCertID*
michael@0 626 CERT_CreateOCSPCertID(CERTCertificate *cert, PRTime time);
michael@0 627
michael@0 628 /*
michael@0 629 * FUNCTION: CERT_DestroyOCSPCertID
michael@0 630 * Frees the memory associated with the certID passed in.
michael@0 631 * INPUTS:
michael@0 632 * CERTOCSPCertID* certID
michael@0 633 * The certID that the caller no longer needs and wants to
michael@0 634 * free the associated memory.
michael@0 635 * RETURN:
michael@0 636 * SECSuccess if freeing the memory was successful. Returns
michael@0 637 * SECFailure if the memory passed in was not allocated with
michael@0 638 * a call to CERT_CreateOCSPCertID.
michael@0 639 */
michael@0 640 extern SECStatus
michael@0 641 CERT_DestroyOCSPCertID(CERTOCSPCertID* certID);
michael@0 642
michael@0 643
michael@0 644 extern CERTOCSPSingleResponse*
michael@0 645 CERT_CreateOCSPSingleResponseGood(PLArenaPool *arena,
michael@0 646 CERTOCSPCertID *id,
michael@0 647 PRTime thisUpdate,
michael@0 648 const PRTime *nextUpdate);
michael@0 649
michael@0 650 extern CERTOCSPSingleResponse*
michael@0 651 CERT_CreateOCSPSingleResponseUnknown(PLArenaPool *arena,
michael@0 652 CERTOCSPCertID *id,
michael@0 653 PRTime thisUpdate,
michael@0 654 const PRTime *nextUpdate);
michael@0 655
michael@0 656 extern CERTOCSPSingleResponse*
michael@0 657 CERT_CreateOCSPSingleResponseRevoked(
michael@0 658 PLArenaPool *arena,
michael@0 659 CERTOCSPCertID *id,
michael@0 660 PRTime thisUpdate,
michael@0 661 const PRTime *nextUpdate,
michael@0 662 PRTime revocationTime,
michael@0 663 const CERTCRLEntryReasonCode* revocationReason);
michael@0 664
michael@0 665 extern SECItem*
michael@0 666 CERT_CreateEncodedOCSPSuccessResponse(
michael@0 667 PLArenaPool *arena,
michael@0 668 CERTCertificate *responderCert,
michael@0 669 CERTOCSPResponderIDType responderIDType,
michael@0 670 PRTime producedAt,
michael@0 671 CERTOCSPSingleResponse **responses,
michael@0 672 void *wincx);
michael@0 673
michael@0 674 /*
michael@0 675 * FUNCTION: CERT_CreateEncodedOCSPErrorResponse
michael@0 676 * Creates an encoded OCSP response with an error response status.
michael@0 677 * INPUTS:
michael@0 678 * PLArenaPool *arena
michael@0 679 * The return value is allocated from here.
michael@0 680 * If a NULL is passed in, allocation is done from the heap instead.
michael@0 681 * int error
michael@0 682 * An NSS error code indicating an error response status. The error
michael@0 683 * code is mapped to an OCSP response status as follows:
michael@0 684 * SEC_ERROR_OCSP_MALFORMED_REQUEST -> malformedRequest
michael@0 685 * SEC_ERROR_OCSP_SERVER_ERROR -> internalError
michael@0 686 * SEC_ERROR_OCSP_TRY_SERVER_LATER -> tryLater
michael@0 687 * SEC_ERROR_OCSP_REQUEST_NEEDS_SIG -> sigRequired
michael@0 688 * SEC_ERROR_OCSP_UNAUTHORIZED_REQUEST -> unauthorized
michael@0 689 * where the OCSP response status is an enumerated type defined in
michael@0 690 * RFC 2560:
michael@0 691 * OCSPResponseStatus ::= ENUMERATED {
michael@0 692 * successful (0), --Response has valid confirmations
michael@0 693 * malformedRequest (1), --Illegal confirmation request
michael@0 694 * internalError (2), --Internal error in issuer
michael@0 695 * tryLater (3), --Try again later
michael@0 696 * --(4) is not used
michael@0 697 * sigRequired (5), --Must sign the request
michael@0 698 * unauthorized (6) --Request unauthorized
michael@0 699 * }
michael@0 700 * RETURN:
michael@0 701 * Returns a pointer to the SECItem holding the response.
michael@0 702 * On error, returns null with error set describing the reason:
michael@0 703 * SEC_ERROR_INVALID_ARGS
michael@0 704 * Other errors are low-level problems (no memory, bad database, etc.).
michael@0 705 */
michael@0 706 extern SECItem*
michael@0 707 CERT_CreateEncodedOCSPErrorResponse(PLArenaPool *arena, int error);
michael@0 708
michael@0 709 /* Sends an OCSP request using the HTTP POST method to the location addressed
michael@0 710 * by the URL in |location| parameter. The request body will be
michael@0 711 * |encodedRequest|, which must be a valid encoded OCSP request. On success,
michael@0 712 * the server's response is returned and the caller must free it using
michael@0 713 * SECITEM_FreeItem. On failure, NULL is returned. No parsing or validation of
michael@0 714 * the HTTP response is done.
michael@0 715 *
michael@0 716 * If a default HTTP client has been registered with
michael@0 717 * SEC_RegisterDefaultHttpClient then that client is used. Otherwise, an
michael@0 718 * internal HTTP client is used.
michael@0 719 */
michael@0 720 SECItem* CERT_PostOCSPRequest(PLArenaPool *arena, const char *location,
michael@0 721 const SECItem *encodedRequest);
michael@0 722
michael@0 723 /************************************************************************/
michael@0 724 SEC_END_PROTOS
michael@0 725
michael@0 726 #endif /* _OCSP_H_ */

mercurial