MCPcopy Create free account
hub / github.com/apache/httpd / read_response

Function read_response

modules/ssl/ssl_util_ocsp.c:204–304  ·  view source on GitHub ↗

Read the OCSP response from the socket 'sd', using temporary memory * BIO 'bio', and return the decoded OCSP response object, or NULL on * error. */

Source from the content-addressed store, hash-verified

202 * BIO 'bio', and return the decoded OCSP response object, or NULL on
203 * error. */
204static OCSP_RESPONSE *read_response(apr_socket_t *sd, BIO *bio, conn_rec *c,
205 apr_pool_t *p)
206{
207 apr_bucket_brigade *bb, *tmpbb;
208 OCSP_RESPONSE *response;
209 char *line;
210 apr_size_t count;
211 apr_int64_t code;
212
213 /* Using brigades for response parsing is much simpler than using
214 * apr_socket_* directly. */
215 bb = apr_brigade_create(p, c->bucket_alloc);
216 tmpbb = apr_brigade_create(p, c->bucket_alloc);
217 APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_socket_create(sd, c->bucket_alloc));
218
219 line = get_line(tmpbb, bb, c, p);
220 if (!line || strncmp(line, "HTTP/", 5)
221 || (line = ap_strchr(line, ' ')) == NULL
222 || (code = apr_atoi64(++line)) < 200 || code > 299) {
223 ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(01980)
224 "bad response from OCSP server: %s",
225 line ? line : "(none)");
226 return NULL;
227 }
228
229 /* Read till end of headers; don't have to even bother parsing the
230 * Content-Length since the server is obliged to close the
231 * connection after the response anyway for HTTP/1.0. */
232 count = 0;
233 while ((line = get_line(tmpbb, bb, c, p)) != NULL && line[0]
234 && ++count < MAX_HEADERS) {
235 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(01981)
236 "OCSP response header: %s", line);
237 }
238
239 if (count == MAX_HEADERS) {
240 ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(01982)
241 "could not read response headers from OCSP server, "
242 "exceeded maximum count (%u)", MAX_HEADERS);
243 return NULL;
244 }
245 else if (!line) {
246 ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(01983)
247 "could not read response header from OCSP server");
248 return NULL;
249 }
250
251 /* Read the response body into the memory BIO. */
252 count = 0;
253 while (!APR_BRIGADE_EMPTY(bb)) {
254 const char *data;
255 apr_size_t len;
256 apr_status_t rv;
257 apr_bucket *e = APR_BRIGADE_FIRST(bb);
258
259 rv = apr_bucket_read(e, &data, &len, APR_BLOCK_READ);
260 if (rv == APR_EOF) {
261 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(01984)

Callers 1

Calls 3

ap_strchrFunction · 0.85
ssl_log_ssl_errorFunction · 0.85
get_lineFunction · 0.70

Tested by

no test coverage detected