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