ocsp.h 28 KB

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