2 * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include <openssl/ocsp.h>
11 #include <openssl/http.h>
12 #include "../http/http_local.h"
14 #ifndef OPENSSL_NO_OCSP
16 OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path,
17 const OCSP_REQUEST *req, int maxline)
19 OSSL_HTTP_REQ_CTX *rctx = NULL;
21 if ((rctx = OSSL_HTTP_REQ_CTX_new(io, io, 1 /* POST */,
22 maxline, 0 /* default max_resp_len */,
23 0 /* no timeout, blocking indefinitely */,
24 NULL, 1 /* expect_asn1 */)) == NULL)
27 if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, NULL, NULL, path))
30 if (req != NULL && !OSSL_HTTP_REQ_CTX_i2d(rctx, "application/ocsp-request",
31 ASN1_ITEM_rptr(OCSP_REQUEST),
38 OSSL_HTTP_REQ_CTX_free(rctx);
42 int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OSSL_HTTP_REQ_CTX *rctx)
44 *presp = (OCSP_RESPONSE *)
45 OSSL_HTTP_REQ_CTX_sendreq_d2i(rctx, ASN1_ITEM_rptr(OCSP_RESPONSE));
46 return *presp != NULL;
49 OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
51 OCSP_RESPONSE *resp = NULL;
52 OSSL_HTTP_REQ_CTX *ctx;
55 ctx = OCSP_sendreq_new(b, path, req, -1 /* default max resp line length */);
59 rv = OCSP_sendreq_nbio(&resp, ctx);
61 /* this indirectly calls ERR_clear_error(): */
62 OSSL_HTTP_REQ_CTX_free(ctx);
64 return rv == 1 ? resp : NULL;
66 #endif /* !defined(OPENSSL_NO_OCSP) */