PageRenderTime 34ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/gecko_api/include/ocspt.h

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