/src/openssl/crypto/ocsp/ocsp_http.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include <openssl/ocsp.h> |
11 | | #include <openssl/http.h> |
12 | | |
13 | | #ifndef OPENSSL_NO_OCSP |
14 | | |
15 | | OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, |
16 | | const OCSP_REQUEST *req, int buf_size) |
17 | 0 | { |
18 | 0 | OSSL_HTTP_REQ_CTX *rctx = OSSL_HTTP_REQ_CTX_new(io, io, buf_size); |
19 | |
|
20 | 0 | if (rctx == NULL) |
21 | 0 | return NULL; |
22 | | /*- |
23 | | * by default: |
24 | | * no bio_update_fn (and consequently no arg) |
25 | | * no ssl |
26 | | * no proxy |
27 | | * no timeout (blocking indefinitely) |
28 | | * no expected content type |
29 | | * max_resp_len = 100 KiB |
30 | | */ |
31 | 0 | if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, 1 /* POST */, |
32 | 0 | NULL, NULL, path)) |
33 | 0 | goto err; |
34 | | /* by default, no extra headers */ |
35 | 0 | if (!OSSL_HTTP_REQ_CTX_set_expected(rctx, |
36 | 0 | NULL /* content_type */, 1 /* asn1 */, |
37 | 0 | 0 /* timeout */, 0 /* keep_alive */)) |
38 | 0 | goto err; |
39 | 0 | if (req != NULL |
40 | 0 | && !OSSL_HTTP_REQ_CTX_set1_req(rctx, "application/ocsp-request", |
41 | 0 | ASN1_ITEM_rptr(OCSP_REQUEST), |
42 | 0 | (const ASN1_VALUE *)req)) |
43 | 0 | goto err; |
44 | 0 | return rctx; |
45 | | |
46 | 0 | err: |
47 | 0 | OSSL_HTTP_REQ_CTX_free(rctx); |
48 | 0 | return NULL; |
49 | 0 | } |
50 | | |
51 | | OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req) |
52 | 0 | { |
53 | 0 | OCSP_RESPONSE *resp = NULL; |
54 | 0 | OSSL_HTTP_REQ_CTX *ctx; |
55 | 0 | BIO *mem; |
56 | |
|
57 | 0 | ctx = OCSP_sendreq_new(b, path, req, 0 /* default buf_size */); |
58 | 0 | if (ctx == NULL) |
59 | 0 | return NULL; |
60 | 0 | mem = OSSL_HTTP_REQ_CTX_exchange(ctx); |
61 | | /* ASN1_item_d2i_bio handles NULL bio gracefully */ |
62 | 0 | resp = (OCSP_RESPONSE *)ASN1_item_d2i_bio(ASN1_ITEM_rptr(OCSP_RESPONSE), |
63 | 0 | mem, NULL); |
64 | |
|
65 | 0 | OSSL_HTTP_REQ_CTX_free(ctx); |
66 | 0 | return resp; |
67 | 0 | } |
68 | | #endif /* !defined(OPENSSL_NO_OCSP) */ |