]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ocsp/ocsp_http.c
OCSP HTTP: Restore API of undocumented and recently deprecated functions
[thirdparty/openssl.git] / crypto / ocsp / ocsp_http.c
CommitLineData
29f178bd 1/*
33388b44 2 * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
29f178bd
DDO
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#include "../http/http_local.h"
13
14#ifndef OPENSSL_NO_OCSP
15
83b6dc8d 16OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path,
c9603dfa 17 const OCSP_REQUEST *req, int maxline)
29f178bd 18{
c9603dfa
DDO
19 OSSL_HTTP_REQ_CTX *rctx = NULL;
20
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)
25 return NULL;
26
27 if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, NULL, NULL, path))
28 goto err;
29
30 if (req != NULL && !OSSL_HTTP_REQ_CTX_i2d(rctx, "application/ocsp-request",
31 ASN1_ITEM_rptr(OCSP_REQUEST),
32 (ASN1_VALUE *)req))
33 goto err;
34
35 return rctx;
36
37 err:
38 OSSL_HTTP_REQ_CTX_free(rctx);
39 return NULL;
29f178bd
DDO
40}
41
83b6dc8d 42int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OSSL_HTTP_REQ_CTX *rctx)
29f178bd
DDO
43{
44 *presp = (OCSP_RESPONSE *)
83b6dc8d 45 OSSL_HTTP_REQ_CTX_sendreq_d2i(rctx, ASN1_ITEM_rptr(OCSP_RESPONSE));
29f178bd
DDO
46 return *presp != NULL;
47}
48
49OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
50{
51 OCSP_RESPONSE *resp = NULL;
83b6dc8d 52 OSSL_HTTP_REQ_CTX *ctx;
29f178bd
DDO
53 int rv;
54
55 ctx = OCSP_sendreq_new(b, path, req, -1 /* default max resp line length */);
56 if (ctx == NULL)
57 return NULL;
58
59 rv = OCSP_sendreq_nbio(&resp, ctx);
60
61 /* this indirectly calls ERR_clear_error(): */
83b6dc8d 62 OSSL_HTTP_REQ_CTX_free(ctx);
29f178bd
DDO
63
64 return rv == 1 ? resp : NULL;
65}
29f178bd 66#endif /* !defined(OPENSSL_NO_OCSP) */