ocspt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. * Public header for exported OCSP types.
  6. */
  7. #ifndef _OCSPT_H_
  8. #define _OCSPT_H_
  9. /*
  10. * The following are all opaque types. If someone needs to get at
  11. * a field within, then we need to fix the API. Try very hard not
  12. * make the type available to them.
  13. */
  14. typedef struct CERTOCSPRequestStr CERTOCSPRequest;
  15. typedef struct CERTOCSPResponseStr CERTOCSPResponse;
  16. /*
  17. * XXX I think only those first two above should need to be exported,
  18. * but until I know for certain I am leaving the rest of these here, too.
  19. */
  20. typedef struct CERTOCSPCertIDStr CERTOCSPCertID;
  21. typedef struct CERTOCSPSingleResponseStr CERTOCSPSingleResponse;
  22. /*
  23. * This interface is described in terms of an HttpClient which
  24. * supports at least a specified set of functions. (An implementer may
  25. * provide HttpClients with additional functionality accessible only to
  26. * users with a particular implementation in mind.) The basic behavior
  27. * is provided by defining a set of functions, listed in an
  28. * SEC_HttpServerFcnStruct. If the implementor of a SpecificHttpClient
  29. * registers his SpecificHttpClient as the default HttpClient, then his
  30. * functions will be called by the user of an HttpClient, such as an
  31. * OCSPChecker.
  32. *
  33. * The implementer of a specific HttpClient (e.g., the NSS-provided
  34. * DefaultHttpClient), populates an SEC_HttpClientFcnStruct, uses it to
  35. * register his client, and waits for his functions to be called.
  36. *
  37. * For future expandability, the SEC_HttpClientFcnStruct is defined as a
  38. * union, with the version field acting as a selector. The proposed
  39. * initial version of the structure is given following the definition
  40. * of the union. The HttpClientState structure is implementation-
  41. * dependent, and should be opaque to the user.
  42. */
  43. typedef void *SEC_HTTP_SERVER_SESSION;
  44. typedef void *SEC_HTTP_REQUEST_SESSION;
  45. /*
  46. * This function creates a SEC_HTTP_SERVER_SESSION object. The implementer of a
  47. * specific HttpClient will allocate the necessary space, when this
  48. * function is called, and will free it when the corresponding FreeFcn
  49. * is called. The SEC_HTTP_SERVER_SESSION object is passed, as an opaque object,
  50. * to subsequent calls.
  51. *
  52. * If the function returns SECSuccess, the returned SEC_HTTP_SERVER_SESSION
  53. * must be cleaned up with a call to SEC_HttpServer_FreeSession,
  54. * after processing is finished.
  55. */
  56. typedef SECStatus (*SEC_HttpServer_CreateSessionFcn)(
  57. const char *host,
  58. PRUint16 portnum,
  59. SEC_HTTP_SERVER_SESSION *pSession);
  60. /*
  61. * This function is called to allow the implementation to attempt to keep
  62. * the connection alive. Depending on the underlying platform, it might
  63. * immediately return SECSuccess without having performed any operations.
  64. * (If a connection has not been kept alive, a subsequent call to
  65. * SEC_HttpRequest_TrySendAndReceiveFcn should reopen the connection
  66. * automatically.)
  67. *
  68. * If the connection uses nonblocking I/O, this function may return
  69. * SECWouldBlock and store a nonzero value at "pPollDesc". In that case
  70. * the caller may wait on the poll descriptor, and should call this function
  71. * again until SECSuccess (and a zero value at "pPollDesc") is obtained.
  72. */
  73. typedef SECStatus (*SEC_HttpServer_KeepAliveSessionFcn)(
  74. SEC_HTTP_SERVER_SESSION session,
  75. PRPollDesc **pPollDesc);
  76. /*
  77. * This function frees the client SEC_HTTP_SERVER_SESSION object, closes all
  78. * SEC_HTTP_REQUEST_SESSIONs created for that server, discards all partial results,
  79. * frees any memory that was allocated by the client, and invalidates any
  80. * response pointers that might have been returned by prior server or request
  81. * functions.
  82. */
  83. typedef SECStatus (*SEC_HttpServer_FreeSessionFcn)(
  84. SEC_HTTP_SERVER_SESSION session);
  85. /*
  86. * This function creates a SEC_HTTP_REQUEST_SESSION object. The implementer of a
  87. * specific HttpClient will allocate the necessary space, when this
  88. * function is called, and will free it when the corresponding FreeFcn
  89. * is called. The SEC_HTTP_REQUEST_SESSION object is passed, as an opaque object,
  90. * to subsequent calls.
  91. *
  92. * An implementation that does not support the requested protocol variant
  93. * (usually "http", but could eventually allow "https") or request method
  94. * should return SECFailure.
  95. *
  96. * Timeout values may include the constants PR_INTERVAL_NO_TIMEOUT (wait
  97. * forever) or PR_INTERVAL_NO_WAIT (nonblocking I/O).
  98. *
  99. * If the function returns SECSuccess, the returned SEC_HTTP_REQUEST_SESSION
  100. * must be cleaned up with a call to SEC_HttpRequest_FreeSession,
  101. * after processing is finished.
  102. */
  103. typedef SECStatus (*SEC_HttpRequest_CreateFcn)(
  104. SEC_HTTP_SERVER_SESSION session,
  105. const char *http_protocol_variant, /* usually "http" */
  106. const char *path_and_query_string,
  107. const char *http_request_method,
  108. const PRIntervalTime timeout,
  109. SEC_HTTP_REQUEST_SESSION *pRequest);
  110. /*
  111. * This function sets data to be sent to the server for an HTTP request
  112. * of http_request_method == POST. If a particular implementation
  113. * supports it, the details for the POST request can be set by calling
  114. * this function, prior to activating the request with TrySendAndReceiveFcn.
  115. *
  116. * An implementation that does not support the POST method should
  117. * implement a SetPostDataFcn function that returns immediately.
  118. *
  119. * Setting http_content_type is optional, the parameter may
  120. * by NULL or the empty string.
  121. */
  122. typedef SECStatus (*SEC_HttpRequest_SetPostDataFcn)(
  123. SEC_HTTP_REQUEST_SESSION request,
  124. const char *http_data,
  125. const PRUint32 http_data_len,
  126. const char *http_content_type);
  127. /*
  128. * This function sets an additional HTTP protocol request header.
  129. * If a particular implementation supports it, one or multiple headers
  130. * can be added to the request by calling this function once or multiple
  131. * times, prior to activating the request with TryFcn.
  132. *
  133. * An implementation that does not support setting additional headers
  134. * should implement an AddRequestHeaderFcn function that returns immediately.
  135. */
  136. typedef SECStatus (*SEC_HttpRequest_AddHeaderFcn)(
  137. SEC_HTTP_REQUEST_SESSION request,
  138. const char *http_header_name,
  139. const char *http_header_value);
  140. /*
  141. * This function initiates or continues an HTTP request. After
  142. * parameters have been set with the Create function and, optionally,
  143. * modified or enhanced with the AddParams function, this call creates
  144. * the socket connection and initiates the communication.
  145. *
  146. * If a timeout value of zero is specified, indicating non-blocking
  147. * I/O, the client creates a non-blocking socket, and returns a status
  148. * of SECWouldBlock and a non-NULL PRPollDesc if the operation is not
  149. * complete. In that case all other return parameters are undefined.
  150. * The caller is expected to repeat the call, possibly after using
  151. * PRPoll to determine that a completion has occurred, until a return
  152. * value of SECSuccess (and a NULL value for pPollDesc) or a return
  153. * value of SECFailure (indicating failure on the network level)
  154. * is obtained.
  155. *
  156. * http_response_data_len is both input and output parameter.
  157. * If a pointer to a PRUint32 is supplied, the http client is
  158. * expected to check the given integer value and always set an out
  159. * value, even on failure.
  160. * An input value of zero means, the caller will accept any response len.
  161. * A different input value indicates the maximum response value acceptable
  162. * to the caller.
  163. * If data is successfully read and the size is acceptable to the caller,
  164. * the function will return SECSuccess and set http_response_data_len to
  165. * the size of the block returned in http_response_data.
  166. * If the data read from the http server is larger than the acceptable
  167. * size, the function will return SECFailure.
  168. * http_response_data_len will be set to a value different from zero to
  169. * indicate the reason of the failure.
  170. * An out value of "0" means, the failure was unrelated to the
  171. * acceptable size.
  172. * An out value of "1" means, the result data is larger than the
  173. * accpeptable size, but the real size is not yet known to the http client
  174. * implementation and it stopped retrieving it,
  175. * Any other out value combined with a return value of SECFailure
  176. * will indicate the actual size of the server data.
  177. *
  178. * The caller is permitted to provide NULL values for any of the
  179. * http_response arguments, indicating the caller is not interested in
  180. * those values. If the caller does provide an address, the HttpClient
  181. * stores at that address a pointer to the corresponding argument, at
  182. * the completion of the operation.
  183. *
  184. * All returned pointers will be owned by the the HttpClient
  185. * implementation and will remain valid until the call to
  186. * SEC_HttpRequest_FreeFcn.
  187. */
  188. typedef SECStatus (*SEC_HttpRequest_TrySendAndReceiveFcn)(
  189. SEC_HTTP_REQUEST_SESSION request,
  190. PRPollDesc **pPollDesc,
  191. PRUint16 *http_response_code,
  192. const char **http_response_content_type,
  193. const char **http_response_headers,
  194. const char **http_response_data,
  195. PRUint32 *http_response_data_len);
  196. /*
  197. * Calling CancelFcn asks for premature termination of the request.
  198. *
  199. * Future calls to SEC_HttpRequest_TrySendAndReceive should
  200. * by avoided, but in this case the HttpClient implementation
  201. * is expected to return immediately with SECFailure.
  202. *
  203. * After calling CancelFcn, a separate call to SEC_HttpRequest_FreeFcn
  204. * is still necessary to free resources.
  205. */
  206. typedef SECStatus (*SEC_HttpRequest_CancelFcn)(
  207. SEC_HTTP_REQUEST_SESSION request);
  208. /*
  209. * Before calling this function, it must be assured the request
  210. * has been completed, i.e. either SEC_HttpRequest_TrySendAndReceiveFcn has
  211. * returned SECSuccess, or the request has been canceled with
  212. * a call to SEC_HttpRequest_CancelFcn.
  213. *
  214. * This function frees the client state object, closes all sockets,
  215. * discards all partial results, frees any memory that was allocated
  216. * by the client, and invalidates all response pointers that might
  217. * have been returned by SEC_HttpRequest_TrySendAndReceiveFcn
  218. */
  219. typedef SECStatus (*SEC_HttpRequest_FreeFcn)(
  220. SEC_HTTP_REQUEST_SESSION request);
  221. typedef struct SEC_HttpClientFcnV1Struct {
  222. SEC_HttpServer_CreateSessionFcn createSessionFcn;
  223. SEC_HttpServer_KeepAliveSessionFcn keepAliveSessionFcn;
  224. SEC_HttpServer_FreeSessionFcn freeSessionFcn;
  225. SEC_HttpRequest_CreateFcn createFcn;
  226. SEC_HttpRequest_SetPostDataFcn setPostDataFcn;
  227. SEC_HttpRequest_AddHeaderFcn addHeaderFcn;
  228. SEC_HttpRequest_TrySendAndReceiveFcn trySendAndReceiveFcn;
  229. SEC_HttpRequest_CancelFcn cancelFcn;
  230. SEC_HttpRequest_FreeFcn freeFcn;
  231. } SEC_HttpClientFcnV1;
  232. typedef struct SEC_HttpClientFcnStruct {
  233. PRInt16 version;
  234. union {
  235. SEC_HttpClientFcnV1 ftable1;
  236. /* SEC_HttpClientFcnV2 ftable2; */
  237. /* ... */
  238. } fcnTable;
  239. } SEC_HttpClientFcn;
  240. /*
  241. * ocspMode_FailureIsVerificationFailure:
  242. * This is the classic behaviour of NSS.
  243. * Any OCSP failure is a verification failure (classic mode, default).
  244. * Without a good response, OCSP networking will be retried each time
  245. * it is required for verifying a cert.
  246. *
  247. * ocspMode_FailureIsNotAVerificationFailure:
  248. * If we fail to obtain a valid OCSP response, consider the
  249. * cert as good.
  250. * Failed OCSP attempts might get cached and not retried until
  251. * minimumSecondsToNextFetchAttempt.
  252. * If we are able to obtain a valid response, the cert
  253. * will be considered good, if either status is "good"
  254. * or the cert was not yet revoked at verification time.
  255. *
  256. * Additional failure modes might be added in the future.
  257. */
  258. typedef enum {
  259. ocspMode_FailureIsVerificationFailure = 0,
  260. ocspMode_FailureIsNotAVerificationFailure = 1
  261. } SEC_OcspFailureMode;
  262. /*
  263. * A ResponderID identifies the responder -- or more correctly, the
  264. * signer of the response. The ASN.1 definition of a ResponderID is:
  265. *
  266. * ResponderID ::= CHOICE {
  267. * byName [1] EXPLICIT Name,
  268. * byKey [2] EXPLICIT KeyHash }
  269. *
  270. * Because it is CHOICE, the type of identification used and the
  271. * identification itself are actually encoded together. To represent
  272. * this same information internally, we explicitly define a type and
  273. * save it, along with the value, into a data structure.
  274. */
  275. typedef enum {
  276. ocspResponderID_other = -1, /* unknown kind of responderID */
  277. ocspResponderID_byName = 1,
  278. ocspResponderID_byKey = 2
  279. } CERTOCSPResponderIDType;
  280. #endif /* _OCSPT_H_ */