diff options
author | beck <> | 2017-01-24 09:59:45 +0000 |
---|---|---|
committer | beck <> | 2017-01-24 09:59:45 +0000 |
commit | 37dc944d40f4b19171f22a8cd86bdea7cc0232ea (patch) | |
tree | 09ff368b71a41c297ba562ca429b3a647298e3fa | |
parent | 03de1298174671da0080d2afb0d4eb14f04c039d (diff) | |
download | openbsd-37dc944d40f4b19171f22a8cd86bdea7cc0232ea.tar.gz openbsd-37dc944d40f4b19171f22a8cd86bdea7cc0232ea.tar.bz2 openbsd-37dc944d40f4b19171f22a8cd86bdea7cc0232ea.zip |
Just don't bother with OpenSSL error strings, they are mostly
irrelevant and look gross here anyway.. we don't need them
-rw-r--r-- | src/usr.sbin/ocspcheck/http.c | 116 | ||||
-rw-r--r-- | src/usr.sbin/ocspcheck/ocspcheck.c | 32 |
2 files changed, 71 insertions, 77 deletions
diff --git a/src/usr.sbin/ocspcheck/http.c b/src/usr.sbin/ocspcheck/http.c index 3c0f404c31..5fab152c14 100644 --- a/src/usr.sbin/ocspcheck/http.c +++ b/src/usr.sbin/ocspcheck/http.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: http.c,v 1.1 2017/01/24 08:50:57 beck Exp $ */ | 1 | /* $Id: http.c,v 1.2 2017/01/24 09:59:45 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> | 3 | * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> |
4 | * | 4 | * |
@@ -95,7 +95,7 @@ dotlsread(char *buf, size_t sz, const struct http *http) | |||
95 | 95 | ||
96 | do { | 96 | do { |
97 | rc = tls_read(http->ctx, buf, sz); | 97 | rc = tls_read(http->ctx, buf, sz); |
98 | } while (TLS_WANT_POLLIN == rc || TLS_WANT_POLLOUT == rc); | 98 | } while (rc == TLS_WANT_POLLIN || rc == TLS_WANT_POLLOUT); |
99 | 99 | ||
100 | if (rc < 0) | 100 | if (rc < 0) |
101 | warnx("%s: tls_read: %s", http->src.ip, | 101 | warnx("%s: tls_read: %s", http->src.ip, |
@@ -110,7 +110,7 @@ dotlswrite(const void *buf, size_t sz, const struct http *http) | |||
110 | 110 | ||
111 | do { | 111 | do { |
112 | rc = tls_write(http->ctx, buf, sz); | 112 | rc = tls_write(http->ctx, buf, sz); |
113 | } while (TLS_WANT_POLLIN == rc || TLS_WANT_POLLOUT == rc); | 113 | } while (rc == TLS_WANT_POLLIN || rc == TLS_WANT_POLLOUT); |
114 | 114 | ||
115 | if (rc < 0) | 115 | if (rc < 0) |
116 | warnx("%s: tls_write: %s", http->src.ip, | 116 | warnx("%s: tls_write: %s", http->src.ip, |
@@ -121,21 +121,21 @@ dotlswrite(const void *buf, size_t sz, const struct http *http) | |||
121 | int | 121 | int |
122 | http_init() | 122 | http_init() |
123 | { | 123 | { |
124 | if (NULL != tlscfg) | 124 | if (tlscfg != NULL) |
125 | return (0); | 125 | return (0); |
126 | 126 | ||
127 | if (-1 == tls_init()) { | 127 | if (tls_init() == -1) { |
128 | warn("tls_init"); | 128 | warn("tls_init"); |
129 | goto err; | 129 | goto err; |
130 | } | 130 | } |
131 | 131 | ||
132 | tlscfg = tls_config_new(); | 132 | tlscfg = tls_config_new(); |
133 | if (NULL == tlscfg) { | 133 | if (tlscfg == NULL) { |
134 | warn("tls_config_new"); | 134 | warn("tls_config_new"); |
135 | goto err; | 135 | goto err; |
136 | } | 136 | } |
137 | 137 | ||
138 | if (-1 == tls_config_set_ca_file(tlscfg, DEFAULT_CA_FILE)) { | 138 | if (tls_config_set_ca_file(tlscfg, DEFAULT_CA_FILE) == -1) { |
139 | warn("tls_config_set_ca_file: %s", tls_config_error(tlscfg)); | 139 | warn("tls_config_set_ca_file: %s", tls_config_error(tlscfg)); |
140 | goto err; | 140 | goto err; |
141 | } | 141 | } |
@@ -158,7 +158,7 @@ http_read(char *buf, size_t sz, const struct http *http) | |||
158 | do { | 158 | do { |
159 | if ((ssz = http->reader(buf, sz, http)) < 0) | 159 | if ((ssz = http->reader(buf, sz, http)) < 0) |
160 | return (-1); | 160 | return (-1); |
161 | if (0 == ssz) | 161 | if (ssz == 0) |
162 | break; | 162 | break; |
163 | xfer += ssz; | 163 | xfer += ssz; |
164 | sz -= ssz; | 164 | sz -= ssz; |
@@ -188,11 +188,11 @@ http_disconnect(struct http *http) | |||
188 | { | 188 | { |
189 | int rc; | 189 | int rc; |
190 | 190 | ||
191 | if (NULL != http->ctx) { | 191 | if (http->ctx != NULL) { |
192 | /* TLS connection. */ | 192 | /* TLS connection. */ |
193 | do { | 193 | do { |
194 | rc = tls_close(http->ctx); | 194 | rc = tls_close(http->ctx); |
195 | } while (TLS_WANT_POLLIN == rc || TLS_WANT_POLLOUT == rc); | 195 | } while (rc == TLS_WANT_POLLIN || rc == TLS_WANT_POLLOUT); |
196 | 196 | ||
197 | if (rc < 0) | 197 | if (rc < 0) |
198 | warnx("%s: tls_close: %s", http->src.ip, | 198 | warnx("%s: tls_close: %s", http->src.ip, |
@@ -200,8 +200,8 @@ http_disconnect(struct http *http) | |||
200 | 200 | ||
201 | tls_free(http->ctx); | 201 | tls_free(http->ctx); |
202 | } | 202 | } |
203 | if (-1 != http->fd) { | 203 | if (http->fd != -1) { |
204 | if (-1 == close(http->fd)) | 204 | if (close(http->fd) == -1) |
205 | warn("%s: close", http->src.ip); | 205 | warn("%s: close", http->src.ip); |
206 | } | 206 | } |
207 | 207 | ||
@@ -213,7 +213,7 @@ void | |||
213 | http_free(struct http *http) | 213 | http_free(struct http *http) |
214 | { | 214 | { |
215 | 215 | ||
216 | if (NULL == http) | 216 | if (http == NULL) |
217 | return; | 217 | return; |
218 | http_disconnect(http); | 218 | http_disconnect(http); |
219 | free(http->host); | 219 | free(http->host); |
@@ -242,14 +242,14 @@ again: | |||
242 | 242 | ||
243 | memset(&ss, 0, sizeof(struct sockaddr_storage)); | 243 | memset(&ss, 0, sizeof(struct sockaddr_storage)); |
244 | 244 | ||
245 | if (4 == addrs[cur].family) { | 245 | if (addrs[cur].family == 4) { |
246 | family = PF_INET; | 246 | family = PF_INET; |
247 | ((struct sockaddr_in *)&ss)->sin_family = AF_INET; | 247 | ((struct sockaddr_in *)&ss)->sin_family = AF_INET; |
248 | ((struct sockaddr_in *)&ss)->sin_port = htons(port); | 248 | ((struct sockaddr_in *)&ss)->sin_port = htons(port); |
249 | c = inet_pton(AF_INET, addrs[cur].ip, | 249 | c = inet_pton(AF_INET, addrs[cur].ip, |
250 | &((struct sockaddr_in *)&ss)->sin_addr); | 250 | &((struct sockaddr_in *)&ss)->sin_addr); |
251 | len = sizeof(struct sockaddr_in); | 251 | len = sizeof(struct sockaddr_in); |
252 | } else if (6 == addrs[cur].family) { | 252 | } else if (addrs[cur].family == 6) { |
253 | family = PF_INET6; | 253 | family = PF_INET6; |
254 | ((struct sockaddr_in6 *)&ss)->sin6_family = AF_INET6; | 254 | ((struct sockaddr_in6 *)&ss)->sin6_family = AF_INET6; |
255 | ((struct sockaddr_in6 *)&ss)->sin6_port = htons(port); | 255 | ((struct sockaddr_in6 *)&ss)->sin6_port = htons(port); |
@@ -264,7 +264,7 @@ again: | |||
264 | if (c < 0) { | 264 | if (c < 0) { |
265 | warn("%s: inet_ntop", addrs[cur].ip); | 265 | warn("%s: inet_ntop", addrs[cur].ip); |
266 | goto again; | 266 | goto again; |
267 | } else if (0 == c) { | 267 | } else if (c == 0) { |
268 | warnx("%s: inet_ntop", addrs[cur].ip); | 268 | warnx("%s: inet_ntop", addrs[cur].ip); |
269 | goto again; | 269 | goto again; |
270 | } | 270 | } |
@@ -272,10 +272,10 @@ again: | |||
272 | /* Create socket and connect. */ | 272 | /* Create socket and connect. */ |
273 | 273 | ||
274 | fd = socket(family, SOCK_STREAM, 0); | 274 | fd = socket(family, SOCK_STREAM, 0); |
275 | if (-1 == fd) { | 275 | if (fd == -1) { |
276 | warn("%s: socket", addrs[cur].ip); | 276 | warn("%s: socket", addrs[cur].ip); |
277 | goto again; | 277 | goto again; |
278 | } else if (-1 == connect(fd, (struct sockaddr *)&ss, len)) { | 278 | } else if (connect(fd, (struct sockaddr *)&ss, len) == -1) { |
279 | warn("%s: connect", addrs[cur].ip); | 279 | warn("%s: connect", addrs[cur].ip); |
280 | close(fd); | 280 | close(fd); |
281 | goto again; | 281 | goto again; |
@@ -284,7 +284,7 @@ again: | |||
284 | /* Allocate the communicator. */ | 284 | /* Allocate the communicator. */ |
285 | 285 | ||
286 | http = calloc(1, sizeof(struct http)); | 286 | http = calloc(1, sizeof(struct http)); |
287 | if (NULL == http) { | 287 | if (http == NULL) { |
288 | warn("calloc"); | 288 | warn("calloc"); |
289 | close(fd); | 289 | close(fd); |
290 | return (NULL); | 290 | return (NULL); |
@@ -295,14 +295,14 @@ again: | |||
295 | http->src.ip = strdup(addrs[cur].ip); | 295 | http->src.ip = strdup(addrs[cur].ip); |
296 | http->host = strdup(host); | 296 | http->host = strdup(host); |
297 | http->path = strdup(path); | 297 | http->path = strdup(path); |
298 | if (NULL == http->src.ip || NULL == http->host || NULL == http->path) { | 298 | if (http->src.ip == NULL || http->host == NULL || http->path == NULL) { |
299 | warn("strdup"); | 299 | warn("strdup"); |
300 | goto err; | 300 | goto err; |
301 | } | 301 | } |
302 | 302 | ||
303 | /* If necessary, do our TLS setup. */ | 303 | /* If necessary, do our TLS setup. */ |
304 | 304 | ||
305 | if (443 != port) { | 305 | if (port != 443) { |
306 | http->writer = dosyswrite; | 306 | http->writer = dosyswrite; |
307 | http->reader = dosysread; | 307 | http->reader = dosysread; |
308 | return (http); | 308 | return (http); |
@@ -311,16 +311,16 @@ again: | |||
311 | http->writer = dotlswrite; | 311 | http->writer = dotlswrite; |
312 | http->reader = dotlsread; | 312 | http->reader = dotlsread; |
313 | 313 | ||
314 | if (NULL == (http->ctx = tls_client())) { | 314 | if ((http->ctx = tls_client()) == NULL) { |
315 | warn("tls_client"); | 315 | warn("tls_client"); |
316 | goto err; | 316 | goto err; |
317 | } else if (-1 == tls_configure(http->ctx, tlscfg)) { | 317 | } else if (tls_configure(http->ctx, tlscfg) == -1) { |
318 | warnx("%s: tls_configure: %s", | 318 | warnx("%s: tls_configure: %s", |
319 | http->src.ip, tls_error(http->ctx)); | 319 | http->src.ip, tls_error(http->ctx)); |
320 | goto err; | 320 | goto err; |
321 | } | 321 | } |
322 | 322 | ||
323 | if (0 != tls_connect_socket(http->ctx, http->fd, http->host)) { | 323 | if (tls_connect_socket(http->ctx, http->fd, http->host) != 0) { |
324 | warnx("%s: tls_connect_socket: %s, %s", http->src.ip, | 324 | warnx("%s: tls_connect_socket: %s, %s", http->src.ip, |
325 | http->host, tls_error(http->ctx)); | 325 | http->host, tls_error(http->ctx)); |
326 | goto err; | 326 | goto err; |
@@ -339,7 +339,7 @@ http_open(const struct http *http, const void *p, size_t psz) | |||
339 | int c; | 339 | int c; |
340 | struct httpxfer *trans; | 340 | struct httpxfer *trans; |
341 | 341 | ||
342 | if (NULL == p) { | 342 | if (p == NULL) { |
343 | c = asprintf(&req, | 343 | c = asprintf(&req, |
344 | "GET %s HTTP/1.0\r\n" | 344 | "GET %s HTTP/1.0\r\n" |
345 | "Host: %s\r\n" | 345 | "Host: %s\r\n" |
@@ -355,13 +355,13 @@ http_open(const struct http *http, const void *p, size_t psz) | |||
355 | "\r\n", | 355 | "\r\n", |
356 | http->path, http->host, psz); | 356 | http->path, http->host, psz); |
357 | } | 357 | } |
358 | if (-1 == c) { | 358 | if (c == -1) { |
359 | warn("asprintf"); | 359 | warn("asprintf"); |
360 | return (NULL); | 360 | return (NULL); |
361 | } else if (!http_write(req, c, http)) { | 361 | } else if (!http_write(req, c, http)) { |
362 | free(req); | 362 | free(req); |
363 | return (NULL); | 363 | return (NULL); |
364 | } else if (NULL != p && ! http_write(p, psz, http)) { | 364 | } else if (p != NULL && !http_write(p, psz, http)) { |
365 | free(req); | 365 | free(req); |
366 | return (NULL); | 366 | return (NULL); |
367 | } | 367 | } |
@@ -369,7 +369,7 @@ http_open(const struct http *http, const void *p, size_t psz) | |||
369 | free(req); | 369 | free(req); |
370 | 370 | ||
371 | trans = calloc(1, sizeof(struct httpxfer)); | 371 | trans = calloc(1, sizeof(struct httpxfer)); |
372 | if (NULL == trans) | 372 | if (trans == NULL) |
373 | warn("calloc"); | 373 | warn("calloc"); |
374 | return (trans); | 374 | return (trans); |
375 | } | 375 | } |
@@ -378,7 +378,7 @@ void | |||
378 | http_close(struct httpxfer *x) | 378 | http_close(struct httpxfer *x) |
379 | { | 379 | { |
380 | 380 | ||
381 | if (NULL == x) | 381 | if (x == NULL) |
382 | return; | 382 | return; |
383 | free(x->hbuf); | 383 | free(x->hbuf); |
384 | free(x->bbuf); | 384 | free(x->bbuf); |
@@ -402,7 +402,7 @@ http_body_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
402 | void *pp; | 402 | void *pp; |
403 | size_t szp; | 403 | size_t szp; |
404 | 404 | ||
405 | if (NULL == sz) | 405 | if (sz == NULL) |
406 | sz = &szp; | 406 | sz = &szp; |
407 | 407 | ||
408 | /* Have we already parsed this? */ | 408 | /* Have we already parsed this? */ |
@@ -420,10 +420,10 @@ http_body_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
420 | /* If less than sizeof(buf), at EOF. */ | 420 | /* If less than sizeof(buf), at EOF. */ |
421 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) | 421 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) |
422 | return (NULL); | 422 | return (NULL); |
423 | else if (0 == ssz) | 423 | else if (ssz == 0) |
424 | break; | 424 | break; |
425 | pp = realloc(trans->bbuf, trans->bbufsz + ssz); | 425 | pp = realloc(trans->bbuf, trans->bbufsz + ssz); |
426 | if (NULL == pp) { | 426 | if (pp == NULL) { |
427 | warn("realloc"); | 427 | warn("realloc"); |
428 | return (NULL); | 428 | return (NULL); |
429 | } | 429 | } |
@@ -461,7 +461,7 @@ http_head_status(const struct http *http, struct httphead *h, size_t sz) | |||
461 | unsigned int code; | 461 | unsigned int code; |
462 | struct httphead *st; | 462 | struct httphead *st; |
463 | 463 | ||
464 | if (NULL == (st = http_head_get("Status", h, sz))) { | 464 | if ((st = http_head_get("Status", h, sz)) == NULL) { |
465 | warnx("%s: no status header", http->src.ip); | 465 | warnx("%s: no status header", http->src.ip); |
466 | return (-1); | 466 | return (-1); |
467 | } | 467 | } |
@@ -470,7 +470,7 @@ http_head_status(const struct http *http, struct httphead *h, size_t sz) | |||
470 | if (rc < 0) { | 470 | if (rc < 0) { |
471 | warn("sscanf"); | 471 | warn("sscanf"); |
472 | return (-1); | 472 | return (-1); |
473 | } else if (1 != rc) { | 473 | } else if (rc != 1) { |
474 | warnx("%s: cannot convert status header", http->src.ip); | 474 | warnx("%s: cannot convert status header", http->src.ip); |
475 | return (-1); | 475 | return (-1); |
476 | } | 476 | } |
@@ -496,7 +496,7 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
496 | struct httphead *h; | 496 | struct httphead *h; |
497 | char *cp, *ep, *ccp, *buf; | 497 | char *cp, *ep, *ccp, *buf; |
498 | 498 | ||
499 | if (NULL == sz) | 499 | if (sz == NULL) |
500 | sz = &szp; | 500 | sz = &szp; |
501 | 501 | ||
502 | /* | 502 | /* |
@@ -505,13 +505,13 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
505 | * If we have errors on the stream, return NULL now. | 505 | * If we have errors on the stream, return NULL now. |
506 | */ | 506 | */ |
507 | 507 | ||
508 | if (NULL != trans->head) { | 508 | if (trans->head != NULL) { |
509 | *sz = trans->headsz; | 509 | *sz = trans->headsz; |
510 | return (trans->head); | 510 | return (trans->head); |
511 | } else if (trans->headok <= 0) | 511 | } else if (trans->headok <= 0) |
512 | return (NULL); | 512 | return (NULL); |
513 | 513 | ||
514 | if (NULL == (buf = strdup(trans->hbuf))) { | 514 | if ((buf = strdup(trans->hbuf)) == NULL) { |
515 | warn("strdup"); | 515 | warn("strdup"); |
516 | return (NULL); | 516 | return (NULL); |
517 | } | 517 | } |
@@ -519,10 +519,10 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
519 | cp = buf; | 519 | cp = buf; |
520 | 520 | ||
521 | do { | 521 | do { |
522 | if (NULL != (cp = strstr(cp, "\r\n"))) | 522 | if ((cp = strstr(cp, "\r\n")) != NULL) |
523 | cp += 2; | 523 | cp += 2; |
524 | hsz++; | 524 | hsz++; |
525 | } while (NULL != cp); | 525 | } while (cp != NULL); |
526 | 526 | ||
527 | /* | 527 | /* |
528 | * Allocate headers, then step through the data buffer, parsing | 528 | * Allocate headers, then step through the data buffer, parsing |
@@ -532,7 +532,7 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
532 | */ | 532 | */ |
533 | 533 | ||
534 | h = calloc(hsz, sizeof(struct httphead)); | 534 | h = calloc(hsz, sizeof(struct httphead)); |
535 | if (NULL == h) { | 535 | if (h == NULL) { |
536 | warn("calloc"); | 536 | warn("calloc"); |
537 | free(buf); | 537 | free(buf); |
538 | return (NULL); | 538 | return (NULL); |
@@ -543,18 +543,18 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
543 | cp = buf; | 543 | cp = buf; |
544 | 544 | ||
545 | do { | 545 | do { |
546 | if (NULL != (ep = strstr(cp, "\r\n"))) { | 546 | if ((ep = strstr(cp, "\r\n")) != NULL) { |
547 | *ep = '\0'; | 547 | *ep = '\0'; |
548 | ep += 2; | 548 | ep += 2; |
549 | } | 549 | } |
550 | if (0 == hsz) { | 550 | if (hsz == 0) { |
551 | h[hsz].key = "Status"; | 551 | h[hsz].key = "Status"; |
552 | h[hsz++].val = cp; | 552 | h[hsz++].val = cp; |
553 | continue; | 553 | continue; |
554 | } | 554 | } |
555 | 555 | ||
556 | /* Skip bad headers. */ | 556 | /* Skip bad headers. */ |
557 | if (NULL == (ccp = strchr(cp, ':'))) { | 557 | if ((ccp = strchr(cp, ':')) == NULL) { |
558 | warnx("%s: header without separator", http->src.ip); | 558 | warnx("%s: header without separator", http->src.ip); |
559 | continue; | 559 | continue; |
560 | } | 560 | } |
@@ -564,7 +564,7 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
564 | ccp++; | 564 | ccp++; |
565 | h[hsz].key = cp; | 565 | h[hsz].key = cp; |
566 | h[hsz++].val = ccp; | 566 | h[hsz++].val = ccp; |
567 | } while (NULL != (cp = ep)); | 567 | } while ((cp = ep) != NULL); |
568 | 568 | ||
569 | trans->headbuf = buf; | 569 | trans->headbuf = buf; |
570 | trans->head = h; | 570 | trans->head = h; |
@@ -588,7 +588,7 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
588 | void *pp; | 588 | void *pp; |
589 | size_t szp; | 589 | size_t szp; |
590 | 590 | ||
591 | if (NULL == sz) | 591 | if (sz == NULL) |
592 | sz = &szp; | 592 | sz = &szp; |
593 | 593 | ||
594 | /* Have we already parsed this? */ | 594 | /* Have we already parsed this? */ |
@@ -614,10 +614,10 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
614 | /* If less than sizeof(buf), at EOF. */ | 614 | /* If less than sizeof(buf), at EOF. */ |
615 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) | 615 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) |
616 | return (NULL); | 616 | return (NULL); |
617 | else if (0 == ssz) | 617 | else if (ssz == 0) |
618 | break; | 618 | break; |
619 | pp = realloc(trans->hbuf, trans->hbufsz + ssz); | 619 | pp = realloc(trans->hbuf, trans->hbufsz + ssz); |
620 | if (NULL == pp) { | 620 | if (pp == NULL) { |
621 | warn("realloc"); | 621 | warn("realloc"); |
622 | return (NULL); | 622 | return (NULL); |
623 | } | 623 | } |
@@ -626,9 +626,9 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
626 | trans->hbufsz += ssz; | 626 | trans->hbufsz += ssz; |
627 | /* Search for end of headers marker. */ | 627 | /* Search for end of headers marker. */ |
628 | ep = memmem(trans->hbuf, trans->hbufsz, "\r\n\r\n", 4); | 628 | ep = memmem(trans->hbuf, trans->hbufsz, "\r\n\r\n", 4); |
629 | } while (NULL == ep && sizeof(buf) == ssz); | 629 | } while (ep == NULL && ssz == sizeof(buf)); |
630 | 630 | ||
631 | if (NULL == ep) { | 631 | if (ep == NULL) { |
632 | warnx("%s: partial transfer", http->src.ip); | 632 | warnx("%s: partial transfer", http->src.ip); |
633 | return (NULL); | 633 | return (NULL); |
634 | } | 634 | } |
@@ -653,7 +653,7 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
653 | ep += 4; | 653 | ep += 4; |
654 | trans->bbufsz = (trans->hbuf + trans->hbufsz) - ep; | 654 | trans->bbufsz = (trans->hbuf + trans->hbufsz) - ep; |
655 | trans->bbuf = malloc(trans->bbufsz); | 655 | trans->bbuf = malloc(trans->bbufsz); |
656 | if (NULL == trans->bbuf) { | 656 | if (trans->bbuf == NULL) { |
657 | warn("malloc"); | 657 | warn("malloc"); |
658 | return (NULL); | 658 | return (NULL); |
659 | } | 659 | } |
@@ -668,7 +668,7 @@ void | |||
668 | http_get_free(struct httpget *g) | 668 | http_get_free(struct httpget *g) |
669 | { | 669 | { |
670 | 670 | ||
671 | if (NULL == g) | 671 | if (g == NULL) |
672 | return; | 672 | return; |
673 | http_close(g->xfer); | 673 | http_close(g->xfer); |
674 | http_free(g->http); | 674 | http_free(g->http); |
@@ -688,17 +688,17 @@ http_get(const struct source *addrs, size_t addrsz, const char *domain, | |||
688 | char *bod, *headr; | 688 | char *bod, *headr; |
689 | 689 | ||
690 | h = http_alloc(addrs, addrsz, domain, port, path); | 690 | h = http_alloc(addrs, addrsz, domain, port, path); |
691 | if (NULL == h) | 691 | if (h == NULL) |
692 | return (NULL); | 692 | return (NULL); |
693 | 693 | ||
694 | if (NULL == (x = http_open(h, post, postsz))) { | 694 | if ((x = http_open(h, post, postsz)) == NULL) { |
695 | http_free(h); | 695 | http_free(h); |
696 | return (NULL); | 696 | return (NULL); |
697 | } else if (NULL == (headr = http_head_read(h, x, &headrsz))) { | 697 | } else if ((headr = http_head_read(h, x, &headrsz)) == NULL) { |
698 | http_close(x); | 698 | http_close(x); |
699 | http_free(h); | 699 | http_free(h); |
700 | return (NULL); | 700 | return (NULL); |
701 | } else if (NULL == (bod = http_body_read(h, x, &bodsz))) { | 701 | } else if ((bod = http_body_read(h, x, &bodsz)) == NULL) { |
702 | http_close(x); | 702 | http_close(x); |
703 | http_free(h); | 703 | http_free(h); |
704 | return (NULL); | 704 | return (NULL); |
@@ -706,7 +706,7 @@ http_get(const struct source *addrs, size_t addrsz, const char *domain, | |||
706 | 706 | ||
707 | http_disconnect(h); | 707 | http_disconnect(h); |
708 | 708 | ||
709 | if (NULL == (head = http_head_parse(h, x, &headsz))) { | 709 | if ((head = http_head_parse(h, x, &headsz)) == NULL) { |
710 | http_close(x); | 710 | http_close(x); |
711 | http_free(h); | 711 | http_free(h); |
712 | return (NULL); | 712 | return (NULL); |
@@ -716,7 +716,7 @@ http_get(const struct source *addrs, size_t addrsz, const char *domain, | |||
716 | return (NULL); | 716 | return (NULL); |
717 | } | 717 | } |
718 | 718 | ||
719 | if (NULL == (g = calloc(1, sizeof(struct httpget)))) { | 719 | if ((g = calloc(1, sizeof(struct httpget))) == NULL) { |
720 | warn("calloc"); | 720 | warn("calloc"); |
721 | http_close(x); | 721 | http_close(x); |
722 | http_free(h); | 722 | http_free(h); |
@@ -767,7 +767,7 @@ main(void) | |||
767 | NULL, 0); | 767 | NULL, 0); |
768 | #endif | 768 | #endif |
769 | 769 | ||
770 | if (NULL == g) | 770 | if (g == NULL) |
771 | errx(EXIT_FAILURE, "http_get"); | 771 | errx(EXIT_FAILURE, "http_get"); |
772 | 772 | ||
773 | httph = http_head_parse(g->http, g->xfer, &httphsz); | 773 | httph = http_head_parse(g->http, g->xfer, &httphsz); |
diff --git a/src/usr.sbin/ocspcheck/ocspcheck.c b/src/usr.sbin/ocspcheck/ocspcheck.c index c19ecf4f05..5f79a999cb 100644 --- a/src/usr.sbin/ocspcheck/ocspcheck.c +++ b/src/usr.sbin/ocspcheck/ocspcheck.c | |||
@@ -86,7 +86,7 @@ host_dns(const char *s, struct addr vec[MAX_SERVERS_DNS]) | |||
86 | } | 86 | } |
87 | 87 | ||
88 | for (vecsz = 0, res = res0; | 88 | for (vecsz = 0, res = res0; |
89 | NULL != res && vecsz < MAX_SERVERS_DNS; | 89 | res != NULL && vecsz < MAX_SERVERS_DNS; |
90 | res = res->ai_next) { | 90 | res = res->ai_next) { |
91 | if (res->ai_family != AF_INET && | 91 | if (res->ai_family != AF_INET && |
92 | res->ai_family != AF_INET6) | 92 | res->ai_family != AF_INET6) |
@@ -94,7 +94,7 @@ host_dns(const char *s, struct addr vec[MAX_SERVERS_DNS]) | |||
94 | 94 | ||
95 | sa = res->ai_addr; | 95 | sa = res->ai_addr; |
96 | 96 | ||
97 | if (AF_INET == res->ai_family) { | 97 | if (res->ai_family == AF_INET) { |
98 | vec[vecsz].family = 4; | 98 | vec[vecsz].family = 4; |
99 | inet_ntop(AF_INET, | 99 | inet_ntop(AF_INET, |
100 | &(((struct sockaddr_in *)sa)->sin_addr), | 100 | &(((struct sockaddr_in *)sa)->sin_addr), |
@@ -127,15 +127,15 @@ url2host(const char *host, short *port, char **path) | |||
127 | 127 | ||
128 | /* We only understand HTTP and HTTPS. */ | 128 | /* We only understand HTTP and HTTPS. */ |
129 | 129 | ||
130 | if (0 == strncmp(host, "https://", 8)) { | 130 | if (strncmp(host, "https://", 8) == 0) { |
131 | *port = 443; | 131 | *port = 443; |
132 | if (NULL == (url = strdup(host + 8))) { | 132 | if ((url = strdup(host + 8)) == NULL) { |
133 | warn("strdup"); | 133 | warn("strdup"); |
134 | return (NULL); | 134 | return (NULL); |
135 | } | 135 | } |
136 | } else if (0 == strncmp(host, "http://", 7)) { | 136 | } else if (strncmp(host, "http://", 7) == 0) { |
137 | *port = 80; | 137 | *port = 80; |
138 | if (NULL == (url = strdup(host + 7))) { | 138 | if ((url = strdup(host + 7)) == NULL) { |
139 | warn("strdup"); | 139 | warn("strdup"); |
140 | return (NULL); | 140 | return (NULL); |
141 | } | 141 | } |
@@ -146,13 +146,13 @@ url2host(const char *host, short *port, char **path) | |||
146 | 146 | ||
147 | /* Terminate path part. */ | 147 | /* Terminate path part. */ |
148 | 148 | ||
149 | if (NULL != (ep = strchr(url, '/'))) { | 149 | if ((ep = strchr(url, '/')) != NULL) { |
150 | *path = strdup(ep); | 150 | *path = strdup(ep); |
151 | *ep = '\0'; | 151 | *ep = '\0'; |
152 | } else | 152 | } else |
153 | *path = strdup(""); | 153 | *path = strdup(""); |
154 | 154 | ||
155 | if (NULL == *path) { | 155 | if (*path == NULL) { |
156 | warn("strdup"); | 156 | warn("strdup"); |
157 | free(url); | 157 | free(url); |
158 | return (NULL); | 158 | return (NULL); |
@@ -227,23 +227,21 @@ read_fullchain(const char *file, int *count) | |||
227 | *count = 0; | 227 | *count = 0; |
228 | 228 | ||
229 | if ((bio = BIO_new_file(file, "r")) == NULL) { | 229 | if ((bio = BIO_new_file(file, "r")) == NULL) { |
230 | warnx("Error opening %s\n", file); | 230 | warnx("Unable to read a certificate from %s", file); |
231 | ERR_print_errors_fp(stderr); | ||
232 | return NULL; | 231 | return NULL; |
233 | } | 232 | } |
234 | if ((xis = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL)) == NULL) { | 233 | if ((xis = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL)) == NULL) { |
235 | warnx("Unable to read PEM format from %s\n", file); | 234 | warnx("Unable to read PEM format from %s", file); |
236 | ERR_print_errors_fp(stderr); | ||
237 | return NULL; | 235 | return NULL; |
238 | } | 236 | } |
239 | BIO_free(bio); | 237 | BIO_free(bio); |
240 | 238 | ||
241 | if (sk_X509_INFO_num(xis) <= 0) { | 239 | if (sk_X509_INFO_num(xis) <= 0) { |
242 | warnx("No certificates in file %s\n", file); | 240 | warnx("No certificates in file %s", file); |
243 | goto end; | 241 | goto end; |
244 | } | 242 | } |
245 | if ((rv = sk_X509_new_null()) == NULL) { | 243 | if ((rv = sk_X509_new_null()) == NULL) { |
246 | ERR_print_errors_fp(stderr); | 244 | warnx("malloc failed"); |
247 | goto end; | 245 | goto end; |
248 | } | 246 | } |
249 | 247 | ||
@@ -252,7 +250,7 @@ read_fullchain(const char *file, int *count) | |||
252 | if (xi->x509 == NULL) | 250 | if (xi->x509 == NULL) |
253 | continue; | 251 | continue; |
254 | if (!sk_X509_push(rv, xi->x509)) { | 252 | if (!sk_X509_push(rv, xi->x509)) { |
255 | ERR_print_errors_fp(stderr); | 253 | warnx("unable to build x509 chain"); |
256 | sk_X509_pop_free(rv, X509_free); | 254 | sk_X509_pop_free(rv, X509_free); |
257 | rv = NULL; | 255 | rv = NULL; |
258 | goto end; | 256 | goto end; |
@@ -337,12 +335,10 @@ ocsp_request_new_from_cert(char *file, int nonce) | |||
337 | cert_id_md = EVP_sha1(); /* XXX. This sucks but OCSP is poopy */ | 335 | cert_id_md = EVP_sha1(); /* XXX. This sucks but OCSP is poopy */ |
338 | if ((id = OCSP_cert_to_id(cert_id_md, cert, issuer)) == NULL) { | 336 | if ((id = OCSP_cert_to_id(cert_id_md, cert, issuer)) == NULL) { |
339 | warnx("Unable to get certificate id from cert in %s", file); | 337 | warnx("Unable to get certificate id from cert in %s", file); |
340 | ERR_print_errors_fp(stderr); | ||
341 | return NULL; | 338 | return NULL; |
342 | } | 339 | } |
343 | if (OCSP_request_add0_id(request->req, id) == NULL) { | 340 | if (OCSP_request_add0_id(request->req, id) == NULL) { |
344 | warnx("Unable to add certificate id to request"); | 341 | warnx("Unable to add certificate id to request"); |
345 | ERR_print_errors_fp(stderr); | ||
346 | return NULL; | 342 | return NULL; |
347 | } | 343 | } |
348 | 344 | ||
@@ -402,7 +398,6 @@ validate_response(char *buf, size_t size, ocsp_request *request, | |||
402 | 398 | ||
403 | if (OCSP_basic_verify(bresp, request->fullchain, store, | 399 | if (OCSP_basic_verify(bresp, request->fullchain, store, |
404 | OCSP_TRUSTOTHER) != 1) { | 400 | OCSP_TRUSTOTHER) != 1) { |
405 | ERR_print_errors_fp(stderr); | ||
406 | warnx("OCSP verify failed from %s", host); | 401 | warnx("OCSP verify failed from %s", host); |
407 | return 0; | 402 | return 0; |
408 | } | 403 | } |
@@ -606,7 +601,6 @@ main (int argc, char **argv) | |||
606 | /* | 601 | /* |
607 | * Validate the OCSP response we got back | 602 | * Validate the OCSP response we got back |
608 | */ | 603 | */ |
609 | ERR_load_crypto_strings(); | ||
610 | OPENSSL_add_all_algorithms_noconf(); | 604 | OPENSSL_add_all_algorithms_noconf(); |
611 | if (!validate_response(hget->bodypart, hget->bodypartsz, | 605 | if (!validate_response(hget->bodypart, hget->bodypartsz, |
612 | request, castore, host, certfile)) | 606 | request, castore, host, certfile)) |